;--------------------------------------------------------
; File Created by SDCC : FreeWare ANSI-C Compiler
; Version 2.5.1 #1058 (Jul 15 2005)
; This file generated Fri Jul 15 02:53:56 2005
;--------------------------------------------------------
	.module realloc
	.optsdcc -mz80
	
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
	.globl _realloc
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
;--------------------------------------------------------
;  ram data
;--------------------------------------------------------
	.area _DATA
;--------------------------------------------------------
; overlayable items in  ram 
;--------------------------------------------------------
	.area _OVERLAY
;--------------------------------------------------------
; external initialized ram data
;--------------------------------------------------------
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
	.area _CODE
	.area _GSINIT
	.area _GSFINAL
	.area _GSINIT
;--------------------------------------------------------
; Home
;--------------------------------------------------------
	.area _HOME
	.area _CODE
;--------------------------------------------------------
; code
;--------------------------------------------------------
	.area _CODE
;realloc.c:67: void xdata * realloc (void * p, size_t size)
;	genLabel
;	genFunction
;	---------------------------------
; Function realloc
; ---------------------------------
_realloc_start::
_realloc:
	push	ix
	ld	ix,#0
	add	ix,sp
	ld	hl,#-8
	add	hl,sp
	ld	sp,hl
;realloc.c:120: }
;realloc.c:75: pthis = _sdcc_find_memheader(p);
;	genIpush
; _saveRegsForCall: sendSetSize: 0 deInUse: 0 bcInUse: 0 deSending: 0
;	AOP_STK for 
	ld	l,4(ix)
	ld	h,5(ix)
	push	hl
;	genCall
	call	__sdcc_find_memheader
	ld	b,h
	ld	c,l
	pop	af
;	genAssign
	ld	e,c
	ld	d,b
;realloc.c:76: if (pthis)
;	genIfx
	ld	a,e
	or	a,d
	jp	z,00114$
;realloc.c:78: if (size > (0xFFFF-HEADER_SIZE))
;	genCmpGt
;	AOP_STK for 
	ld	a,#0xF9
	sub	a,6(ix)
	ld	a,#0xFF
	sbc	a,7(ix)
	jp	nc,00111$
;realloc.c:80: ret = (void xdata *) NULL; //To prevent overflow in next line
;	genAssign
;	AOP_STK for _realloc_ret_1_1
	ld	-4(ix),#0x00
	ld	-3(ix),#0x00
;	genGoto
	jp	00115$
;	genLabel
00111$:
;realloc.c:84: size += HEADER_SIZE; //We need a memory for header too
;	genPlus
;	AOP_STK for 
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,6(ix)
	add	a,#0x06
	ld	6(ix),a
	ld	a,7(ix)
	adc	a,#0x00
	ld	7(ix),a
;realloc.c:86: if ((((unsigned int)pthis->next) - ((unsigned int)pthis)) >= size)
;	genPointerGet
;	AOP_STK for _realloc__1_0
	ld	l,e
	ld	h,d
	ld	a,(hl)
	ld	-6(ix),a
	inc	hl
	ld	a,(hl)
	ld	-5(ix),a
;	genCast
;	AOP_STK for _realloc__1_0
;	AOP_STK for _realloc__1_0
	ld	a,-6(ix)
	ld	-8(ix),a
	ld	a,-5(ix)
	ld	-7(ix),a
;	genCast
	ld	c,e
	ld	b,d
;	genMinus
;	AOP_STK for _realloc__1_0
	ld	a,-8(ix)
	sub	a,c
	ld	c,a
	ld	a,-7(ix)
	sbc	a,b
	ld	b,a
;	genCmpLt
;	AOP_STK for 
	ld	a,c
	sub	a,6(ix)
	ld	a,b
	sbc	a,7(ix)
	jp	c,00108$
;realloc.c:88: pthis->len = size;
;	genPlus
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,e
	add	a,#0x04
	ld	c,a
	ld	a,d
	adc	a,#0x00
	ld	b,a
;	genAssign (pointer)
;	AOP_STK for 
;	isBitvar = 0
	ld	l,c
	ld	h,b
	ld	a,6(ix)
	ld	(hl),a
	inc	hl
	ld	a,7(ix)
	ld	(hl),a
;realloc.c:89: ret = p;
;	genAssign
;	AOP_STK for 
;	AOP_STK for _realloc_ret_1_1
	ld	a,4(ix)
	ld	-4(ix),a
	ld	a,5(ix)
	ld	-3(ix),a
;	genGoto
	jp	00115$
;	genLabel
00108$:
;realloc.c:93: if ((_sdcc_prev_memheader) &&
;	genIfx
	ld	iy,#__sdcc_prev_memheader
	ld	a,0(iy)
	or	a,1(iy)
	jp	z,00104$
;realloc.c:94: ((((unsigned int)pthis->next) -
;	genAssign
;	AOP_STK for _realloc__1_0
	ld	c,-6(ix)
	ld	b,-5(ix)
;	genCast
;	AOP_STK for _realloc__1_0
	ld	-8(ix),c
	ld	-7(ix),b
;realloc.c:95: ((unsigned int)_sdcc_prev_memheader) -
;	genCast
	ld	c,0(iy)
	ld	b,1(iy)
;	genMinus
;	AOP_STK for _realloc__1_0
	ld	a,-8(ix)
	sub	a,c
	ld	-8(ix),a
	ld	a,-7(ix)
	sbc	a,b
	ld	-7(ix),a
;realloc.c:96: _sdcc_prev_memheader->len) >= size))
;	genAssign
	ld	bc,(__sdcc_prev_memheader)
;	genPlus
;	genPlusIncr
	inc	bc
	inc	bc
	inc	bc
	inc	bc
;	genPointerGet
	ld	l,c
	ld	h,b
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
;	genMinus
;	AOP_STK for _realloc__1_0
	ld	a,-8(ix)
	sub	a,c
	ld	c,a
	ld	a,-7(ix)
	sbc	a,b
	ld	b,a
;	genCmpLt
;	AOP_STK for 
	ld	a,c
	sub	a,6(ix)
	ld	a,b
	sbc	a,7(ix)
	jp	c,00104$
;realloc.c:98: pnew = (MEMHEADER xdata * )((char xdata *)_sdcc_prev_memheader + _sdcc_prev_memheader->len);
;	genAssign
;	(operands are equal 3)
;	genAssign
	ld	bc,(__sdcc_prev_memheader)
;	genPlus
;	genPlusIncr
	inc	bc
	inc	bc
	inc	bc
	inc	bc
;	genPointerGet
	ld	l,c
	ld	h,b
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
;	genPlus
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,0(iy)
	add	a,c
	ld	c,a
	ld	a,1(iy)
	adc	a,b
	ld	b,a
;	genAssign
;	AOP_STK for _realloc_pnew_1_1
	ld	-2(ix),c
	ld	-1(ix),b
;realloc.c:99: _sdcc_prev_memheader->next = pnew;
;	genAssign
	ld	bc,(__sdcc_prev_memheader)
;	genAssign (pointer)
;	AOP_STK for _realloc_pnew_1_1
;	isBitvar = 0
	ld	l,c
	ld	h,b
	ld	a,-2(ix)
	ld	(hl),a
	inc	hl
	ld	a,-1(ix)
	ld	(hl),a
;realloc.c:100: memmove(pnew, pthis, pthis->len);
;	genPlus
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,e
	add	a,#0x04
	ld	c,a
	ld	a,d
	adc	a,#0x00
	ld	b,a
;	genPointerGet
	ld	l,c
	ld	h,b
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
;	genIpush
; _saveRegsForCall: sendSetSize: 0 deInUse: 0 bcInUse: 0 deSending: 0
	push	bc
;	genIpush
	push	de
;	genIpush
;	AOP_STK for _realloc_pnew_1_1
	ld	l,-2(ix)
	ld	h,-1(ix)
	push	hl
;	genCall
	call	_memmove
	pop	af
	pop	af
	pop	af
;realloc.c:101: pnew->len = size;
;	genPlus
;	AOP_STK for _realloc_pnew_1_1
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,-2(ix)
	add	a,#0x04
	ld	c,a
	ld	a,-1(ix)
	adc	a,#0x00
	ld	b,a
;	genAssign (pointer)
;	AOP_STK for 
;	isBitvar = 0
	ld	l,c
	ld	h,b
	ld	a,6(ix)
	ld	(hl),a
	inc	hl
	ld	a,7(ix)
	ld	(hl),a
;realloc.c:102: ret = MEM(pnew);
;	genPlus
;	AOP_STK for _realloc_pnew_1_1
;	AOP_STK for _realloc_ret_1_1
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,-2(ix)
	add	a,#0x06
	ld	-4(ix),a
	ld	a,-1(ix)
	adc	a,#0x00
	ld	-3(ix),a
;	genGoto
	jp	00115$
;	genLabel
00104$:
;realloc.c:106: ret = malloc(size - HEADER_SIZE);
;	genMinus
;	AOP_STK for 
	ld	a,6(ix)
	add	a,#0xFA
	ld	c,a
	ld	a,7(ix)
	adc	a,#0xFF
	ld	b,a
;	genIpush
; _saveRegsForCall: sendSetSize: 0 deInUse: 1 bcInUse: 0 deSending: 0
	push	de
	push	bc
;	genCall
	call	_malloc
	ld	b,h
	ld	c,l
	pop	af
	pop	de
;	genAssign
;	AOP_STK for _realloc_ret_1_1
	ld	-4(ix),c
	ld	-3(ix),b
;realloc.c:107: if (ret)
;	genIfx
;	AOP_STK for _realloc_ret_1_1
	ld	a,-4(ix)
	or	a,-3(ix)
	jp	z,00115$
;realloc.c:109: memcpy(ret, MEM(pthis), pthis->len - HEADER_SIZE);
;	genPlus
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,e
	add	a,#0x04
	ld	c,a
	ld	a,d
	adc	a,#0x00
	ld	b,a
;	genPointerGet
	ld	l,c
	ld	h,b
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
;	genMinus
	ld	a,c
	add	a,#0xFA
	ld	c,a
	ld	a,b
	adc	a,#0xFF
	ld	b,a
;	genPlus
;	genPlusIncr
;	Can't optimise plus by inc, falling back to the normal way
	ld	a,e
	add	a,#0x06
	ld	e,a
	ld	a,d
	adc	a,#0x00
	ld	d,a
;	genIpush
; _saveRegsForCall: sendSetSize: 0 deInUse: 0 bcInUse: 0 deSending: 0
	push	bc
;	genIpush
	push	de
;	genIpush
;	AOP_STK for _realloc_ret_1_1
	ld	l,-4(ix)
	ld	h,-3(ix)
	push	hl
;	genCall
	call	_memcpy
	pop	af
	pop	af
	pop	af
;realloc.c:110: free(p);
;	genIpush
; _saveRegsForCall: sendSetSize: 0 deInUse: 0 bcInUse: 0 deSending: 0
;	AOP_STK for 
	ld	l,4(ix)
	ld	h,5(ix)
	push	hl
;	genCall
	call	_free
	pop	af
;	genGoto
	jp	00115$
;	genLabel
00114$:
;realloc.c:118: ret = malloc(size);
;	genIpush
; _saveRegsForCall: sendSetSize: 0 deInUse: 0 bcInUse: 0 deSending: 0
;	AOP_STK for 
	ld	l,6(ix)
	ld	h,7(ix)
	push	hl
;	genCall
	call	_malloc
	ld	b,h
	ld	c,l
	pop	af
;	genAssign
;	AOP_STK for _realloc_ret_1_1
	ld	-4(ix),c
	ld	-3(ix),b
;	genLabel
00115$:
;realloc.c:121: return ret;
;	genRet
;	AOP_STK for _realloc_ret_1_1
; Dump of IC_LEFT: type AOP_STK size 2
;	 aop_stk -4
	ld	l,-4(ix)
	ld	h,-3(ix)
;	genLabel
00116$:
;	genEndFunction
	ld	sp,ix
	pop	ix
	ret
_realloc_end::
	.area _CODE
