// File: /workspace/github_c_makefile_star2_O1/LemonBoy[P]autobahn/xdiff/xprepare.c
// Function: xdl_prepare_ctx
static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_t const *xpp,
			   xdlclassifier_t *cf, xdfile_t *xdf) {
	unsigned int hbits;
	long nrec, hsize, bsize;
	unsigned long hav;
	char const *blk, *cur, *top, *prev;
	xrecord_t *crec;
	xrecord_t **recs, **rrecs;
	xrecord_t **rhash;
	unsigned long *ha;
	char *rchg;
	long *rindex;

	ha = NULL;
	rindex = NULL;
	rchg = NULL;
	rhash = NULL;
	recs = NULL;

	if (xdl_cha_init(&xdf->rcha, sizeof(xrecord_t), narec / 4 + 1) < 0)
		goto abort;
	if (!(recs = (xrecord_t **) xdl_malloc(narec * sizeof(xrecord_t *))))
		goto abort;

	if (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF)
		hbits = hsize = 0;
	else {
		hbits = xdl_hashbits((unsigned int) narec);
		hsize = 1 << hbits;
		if (!(rhash = (xrecord_t **) xdl_malloc(hsize * sizeof(xrecord_t *))))
			goto abort;
		memset(rhash, 0, hsize * sizeof(xrecord_t *));
	}

	nrec = 0;
	if ((cur = blk = xdl_mmfile_first(mf, &bsize)) != NULL) {
		for (top = blk + bsize; cur < top; ) {
			prev = cur;
			hav = xdl_hash_record(&cur, top, xpp->flags);
			if (nrec >= narec) {
				narec *= 2;
				if (!(rrecs = (xrecord_t **) xdl_realloc(recs, narec * sizeof(xrecord_t *))))
					goto abort;
				recs = rrecs;
			}
			if (!(crec = xdl_cha_alloc(&xdf->rcha)))
				goto abort;
			crec->ptr = prev;
			crec->size = (long) (cur - prev);
			crec->ha = hav;
			recs[nrec++] = crec;

			if ((XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF) &&
			    xdl_classify_record(pass, cf, rhash, hbits, crec) < 0)
				goto abort;
		}
	}

	if (!(rchg = (char *) xdl_malloc((nrec + 2) * sizeof(char))))
		goto abort;
	memset(rchg, 0, (nrec + 2) * sizeof(char));

	if (!(rindex = (long *) xdl_malloc((nrec + 1) * sizeof(long))))
		goto abort;
	if (!(ha = (unsigned long *) xdl_malloc((nrec + 1) * sizeof(unsigned long))))
		goto abort;

	xdf->nrec = nrec;
	xdf->recs = recs;
	xdf->hbits = hbits;
	xdf->rhash = rhash;
	xdf->rchg = rchg + 1;
	xdf->rindex = rindex;
	xdf->nreff = 0;
	xdf->ha = ha;
	xdf->dstart = 0;
	xdf->dend = nrec - 1;

	return 0;

abort:
	xdl_free(ha);
	xdl_free(rindex);
	xdl_free(rchg);
	xdl_free(rhash);
	xdl_free(recs);
	xdl_cha_free(&xdf->rcha);
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %r14
movq %r8, %r13
movq %rcx, 0x30(%rsp)
movq %rdx, %r12
movq %rsi, %r15
movl %edi, %ebx
addq $0x3, %rdx
testq %r12, %r12
cmovnsq %r12, %rdx
sarq $0x2, %rdx
incq %rdx
movl $0x20, %esi
movq %r9, %rdi
callq 0x431e
testl %eax, %eax
js 0x3d92
leaq (,%r12,8), %rdi
callq 0x10e0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x3d92
movq 0x30(%rsp), %rax
movl (%rax), %eax
andl $0x60, %eax
cmpl $0x40, %eax
movq %r12, 0x40(%rsp)
jne 0x3da2
movq $0x0, 0x28(%rsp)
xorl %r12d, %r12d
jmp 0x3de0
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebx, %ebx
jmp 0x4117
movl %r12d, %edi
callq 0x4939
movl %eax, %ecx
movl $0x1, %eax
movq %rcx, 0x28(%rsp)
shll %cl, %eax
movslq %eax, %rbp
shlq $0x3, %rbp
movq %rbp, %rdi
callq 0x10e0
testq %rax, %rax
je 0x40e2
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x1090
movq %r12, 0x18(%rsp)
leaq 0x70(%rsp), %rsi
movq %r15, %rdi
callq 0x430e
movq %rax, 0x20(%rsp)
testq %rax, %rax
movq %r14, 0x10(%rsp)
je 0x403b
movq %rax, %r15
addq 0x70(%rsp), %r15
movq 0x20(%rsp), %r12
cmpq %r15, %r12
jae 0x403b
xorl %eax, %eax
cmpl $0x1, %ebx
setne %al
movq $-0x1, %rdx
movq 0x28(%rsp), %rcx
shlq %cl, %rdx
leaq 0x18(%r13), %rsi
movq %rsi, 0x48(%rsp)
movl %ecx, %ecx
movq %rcx, 0x58(%rsp)
notq %rdx
movq %rdx, 0x60(%rsp)
leaq 0x28(,%rax,8), %rax
movq %rax, 0x50(%rsp)
xorl %r14d, %r14d
movq %r15, 0x38(%rsp)
movq 0x30(%rsp), %rax
movq (%rax), %rdx
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x47bd
movq %rax, %rbp
movq 0x40(%rsp), %rbx
cmpq %rbx, %r14
jl 0x3eb0
movq %rbx, %rsi
shlq $0x4, %rsi
movq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x1100
testq %rax, %rax
je 0x4108
addq %rbx, %rbx
movq %rbx, 0x40(%rsp)
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %r15
movq 0x10(%rsp), %rdi
callq 0x435a
testq %rax, %rax
je 0x40fa
movq %rax, %rbx
movq %r12, 0x8(%rax)
movq 0x20(%rsp), %rax
subq %r12, %rax
movq %rax, 0x10(%rbx)
movq %rbp, 0x18(%rbx)
movq 0x8(%rsp), %rax
movq %rbx, (%rax,%r14,8)
movq 0x30(%rsp), %rax
movl (%rax), %eax
andl $0x60, %eax
cmpl $0x40, %eax
je 0x4028
movb (%r13), %cl
movq %rbp, %rax
shrq %cl, %rax
movq 0x8(%rbx), %r12
addq %rbp, %rax
movq $-0x1, %r15
shlq %cl, %r15
notq %r15
andq %rax, %r15
movq 0x10(%r13), %rax
movq (%rax,%r15,8), %rbp
testq %rbp, %rbp
je 0x3f55
movq 0x8(%rbp), %rax
cmpq 0x18(%rbx), %rax
jne 0x3f4f
movq 0x10(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq 0x8(%rbx), %rdx
movq 0x10(%rbx), %rcx
movq 0x68(%r13), %r8
callq 0x44b5
testl %eax, %eax
jne 0x3fee
movq (%rbp), %rbp
jmp 0x3f1f
movq 0x48(%rsp), %rdi
callq 0x435a
testq %rax, %rax
je 0x40fa
movq %rax, %rbp
movq %r12, 0x68(%rsp)
movq 0x60(%r13), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x60(%r13)
movq %rax, 0x20(%rbp)
movq 0x58(%r13), %rsi
cmpq %rsi, %rax
movq 0x18(%rsp), %r12
jl 0x3fb0
leaq (%rsi,%rsi), %rax
movq %rax, 0x58(%r13)
movq 0x50(%r13), %rdi
shlq $0x4, %rsi
callq 0x1100
testq %rax, %rax
je 0x4155
movq %rax, 0x50(%r13)
movq 0x50(%r13), %rax
movq 0x20(%rbp), %rcx
movq %rbp, (%rax,%rcx,8)
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rbp)
movq 0x10(%rbx), %rax
movq %rax, 0x18(%rbp)
movq 0x18(%rbx), %rax
movq %rax, 0x8(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rbp)
movq 0x10(%r13), %rax
movq (%rax,%r15,8), %rcx
movq %rcx, (%rbp)
movq %rbp, (%rax,%r15,8)
jmp 0x3ff3
movq 0x18(%rsp), %r12
movq 0x50(%rsp), %rax
incq (%rbp,%rax)
movq 0x20(%rbp), %rax
movq %rax, 0x18(%rbx)
movq %rax, %rdx
movq 0x58(%rsp), %rcx
shrq %cl, %rdx
addq %rax, %rdx
andq 0x60(%rsp), %rdx
movq (%r12,%rdx,8), %rax
movq %rax, (%rbx)
movq %rbx, (%r12,%rdx,8)
movq 0x38(%rsp), %r15
incq %r14
movq 0x20(%rsp), %r12
cmpq %r15, %r12
jb 0x3e5f
jmp 0x403e
xorl %r14d, %r14d
leaq 0x2(%r14), %rbx
movq %rbx, %rdi
callq 0x10e0
testq %rax, %rax
je 0x40cc
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1090
leaq 0x8(,%r14,8), %r15
movq %r15, %rdi
callq 0x10e0
testq %rax, %rax
movq 0x18(%rsp), %r12
je 0x40ec
movq %rax, %rbx
movq %r15, %rdi
callq 0x10e0
testq %rax, %rax
je 0x40ee
movq 0x10(%rsp), %rdx
movq %r14, 0x38(%rdx)
movq 0x8(%rsp), %rcx
movq %rcx, 0x60(%rdx)
movq 0x28(%rsp), %rcx
movl %ecx, 0x40(%rdx)
movq %r12, 0x48(%rdx)
incq %r13
movq %r13, 0x68(%rdx)
movq %rbx, 0x70(%rdx)
xorl %ecx, %ecx
movq %rcx, 0x78(%rdx)
movq %rax, 0x80(%rdx)
movq %rcx, 0x50(%rdx)
decq %r14
movq %r14, 0x58(%rdx)
jmp 0x4144
xorl %r13d, %r13d
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r15
movq 0x18(%rsp), %r12
jmp 0x4117
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebx, %ebx
jmp 0x40f3
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r15
jmp 0x4117
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r15
jmp 0x410f
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r12
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
movq %r12, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x433f
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r15
jmp 0x4114