// File: /workspace/github_c_makefile_star2_O0/hughbarney[P]zepl/zepl.c
// Function: growgap
int growgap(buffer_t *bp, point_t n)
{
	char_t *new;
	point_t buflen, newlen, xgap, xegap;
		
	assert(bp->b_buf <= bp->b_gap);
	assert(bp->b_gap <= bp->b_egap);
	assert(bp->b_egap <= bp->b_ebuf);

	xgap = bp->b_gap - bp->b_buf;
	xegap = bp->b_egap - bp->b_buf;
	buflen = bp->b_ebuf - bp->b_buf;
    
	/* reduce number of reallocs by growing by a minimum amount */
	n = (n < MIN_GAP_EXPAND ? MIN_GAP_EXPAND : n);
	newlen = buflen + n * sizeof (char_t);

	if (buflen == 0) {
		if (newlen < 0 || MAX_SIZE_T < newlen) fatal("Failed to allocate required memory.\n");
		new = (char_t*) malloc((size_t) newlen);
		if (new == NULL) fatal("Failed to allocate required memory.\n");
	} else {
		if (newlen < 0 || MAX_SIZE_T < newlen) return msg("Failed to allocate required memory");
		new = (char_t*) realloc(bp->b_buf, (size_t) newlen);
		if (new == NULL) return msg("Failed to allocate required memory");
	}

	/* Relocate pointers in new buffer and append the new
	 * extension to the end of the gap.
	 */
	bp->b_buf = new;
	bp->b_gap = bp->b_buf + xgap;      
	bp->b_ebuf = bp->b_buf + buflen;
	bp->b_egap = bp->b_buf + newlen;
	while (xegap < buflen--)
		*--bp->b_egap = *--bp->b_ebuf;
	bp->b_ebuf = bp->b_buf + newlen;

	assert(bp->b_buf < bp->b_ebuf);          /* Buffer must exist. */
	assert(bp->b_buf <= bp->b_gap);
	assert(bp->b_gap < bp->b_egap);          /* Gap must grow only. */
	assert(bp->b_egap <= bp->b_ebuf);
	return (TRUE);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x28(%rbp)
cmpq $0x200, -0x18(%rbp)     # imm = 0x200
jge 0x275a
movl $0x200, %eax            # imm = 0x200
movq %rax, -0x48(%rbp)
jmp 0x2762
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x0, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x27c6
cmpq $0x0, -0x30(%rbp)
jl 0x2798
movq $-0x1, %rax
cmpq -0x30(%rbp), %rax
jae 0x27a4
leaq 0x887b(%rip), %rdi      # 0xb01a
callq 0x2520
movq -0x30(%rbp), %rdi
callq 0x2220
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x27c4
leaq 0x885b(%rip), %rdi      # 0xb01a
callq 0x2520
jmp 0x2824
cmpq $0x0, -0x30(%rbp)
jl 0x27da
movq $-0x1, %rax
cmpq -0x30(%rbp), %rax
jae 0x27f0
leaq 0x885e(%rip), %rdi      # 0xb03f
movb $0x0, %al
callq 0x2560
movl %eax, -0x4(%rbp)
jmp 0x28cd
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x2240
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x2822
leaq 0x882c(%rip), %rdi      # 0xb03f
movb $0x0, %al
callq 0x2560
movl %eax, -0x4(%rbp)
jmp 0x28cd
jmp 0x2824
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
addq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
addq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
addq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $-0x1, %rdx
movq %rdx, -0x28(%rbp)
cmpq %rcx, %rax
jge 0x28b2
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rax
movq %rax, %rdx
addq $-0x1, %rdx
movq %rdx, 0x28(%rcx)
movb -0x1(%rax), %cl
movq -0x10(%rbp), %rdx
movq 0x38(%rdx), %rax
movq %rax, %rsi
addq $-0x1, %rsi
movq %rsi, 0x38(%rdx)
movb %cl, -0x1(%rax)
jmp 0x286c
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
addq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)