// File: /workspace/github_c_makefile_star2_O3/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 0x41c6
testl %eax, %eax
js 0x3c55
movl %ebx, 0x28(%rsp)
movq %r12, %rbx
leaq (,%r12,8), %rdi
callq 0x10f0
testq %rax, %rax
je 0x3c55
movq %rax, %rbp
movq 0x30(%rsp), %rax
movl (%rax), %eax
andl $0x60, %eax
cmpl $0x40, %eax
jne 0x3c9d
movq $0x0, 0x20(%rsp)
movq %rbp, 0x18(%rsp)
movq $0x0, 0x8(%rsp)
jmp 0x3cd6
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rbx, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
movq %r12, %rdi
callq 0x1030
movq %rbp, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x41e7
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %edi
callq 0x4715
movl %eax, %r12d
movl $0x1, %eax
movl %r12d, %ecx
shll %cl, %eax
movslq %eax, %rsi
shlq $0x3, %rsi
movl $0x1, %edi
callq 0x10b0
testq %rax, %rax
je 0x3c57
movq %r12, 0x20(%rsp)
movq %rax, 0x8(%rsp)
movq %rbp, 0x18(%rsp)
leaq 0x70(%rsp), %rsi
movq %r15, %rdi
callq 0x41b6
movq %rax, 0x38(%rsp)
testq %rax, %rax
movq %r14, 0x10(%rsp)
je 0x3f34
movq 0x70(%rsp), %rsi
testq %rsi, %rsi
jle 0x3f34
movq %rax, %r12
movq %rbx, %rbp
addq %rax, %rsi
leaq 0x18(%r13), %rax
movq %rax, 0x40(%rsp)
xorl %eax, %eax
cmpl $0x1, 0x28(%rsp)
setne %al
leaq 0x28(,%rax,8), %rax
movq %rax, 0x58(%rsp)
movq 0x20(%rsp), %rcx
movl %ecx, %eax
movq %rax, 0x50(%rsp)
movq $-0x1, %rax
shlq %cl, %rax
notq %rax
movq %rax, 0x48(%rsp)
xorl %r15d, %r15d
movq %rsi, 0x68(%rsp)
movq 0x30(%rsp), %rax
movq (%rax), %rdx
leaq 0x38(%rsp), %rdi
callq 0x4592
movq %rax, %r14
cmpq %rbp, %r15
jl 0x3d98
movq %rbp, %rsi
shlq $0x4, %rsi
movq %rbp, %rbx
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
callq 0x1110
testq %rax, %rax
je 0x3ff0
addq %rbx, %rbx
movq %rax, 0x18(%rsp)
movq %rbx, %rbp
movq 0x10(%rsp), %rdi
callq 0x4202
testq %rax, %rax
je 0x3fd6
movq %rax, %rbx
movq %r12, 0x8(%rax)
movq 0x38(%rsp), %rax
subq %r12, %rax
movq %rax, 0x10(%rbx)
movq %r14, 0x18(%rbx)
movq 0x18(%rsp), %rax
movq %rbx, (%rax,%r15,8)
movq 0x30(%rsp), %rax
movl (%rax), %eax
andl $0x60, %eax
cmpl $0x40, %eax
je 0x3f1c
movq %rbp, 0x28(%rsp)
movb (%r13), %cl
movq %r14, %rax
shrq %cl, %rax
movq 0x8(%rbx), %r12
addq %r14, %rax
movq $-0x1, %r14
shlq %cl, %r14
notq %r14
andq %rax, %r14
movq 0x10(%r13), %rax
movq (%rax,%r14,8), %rbp
testq %rbp, %rbp
je 0x3e42
movq 0x8(%rbp), %rax
cmpq 0x18(%rbx), %rax
jne 0x3e3c
movq 0x10(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq 0x8(%rbx), %rdx
movq 0x10(%rbx), %rcx
movq 0x68(%r13), %r8
callq 0x4349
testl %eax, %eax
jne 0x3ee2
movq (%rbp), %rbp
jmp 0x3e0c
movq 0x40(%rsp), %rdi
callq 0x4202
testq %rax, %rax
je 0x3fd6
movq %rax, %rbp
movq %r12, 0x60(%rsp)
movq 0x60(%r13), %rdx
leaq 0x1(%rdx), %rax
movq %rax, 0x60(%r13)
movq %rdx, 0x20(%rbp)
movq 0x58(%r13), %rsi
cmpq %rsi, %rdx
jge 0x3e81
movq 0x50(%r13), %rax
movq 0x8(%rsp), %r12
jmp 0x3eac
leaq (%rsi,%rsi), %rax
movq %rax, 0x58(%r13)
movq 0x50(%r13), %rdi
shlq $0x4, %rsi
callq 0x1110
testq %rax, %rax
movq 0x8(%rsp), %r12
je 0x4004
movq %rax, 0x50(%r13)
movq 0x20(%rbp), %rdx
movq %rbp, (%rax,%rdx,8)
movq 0x60(%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,%r14,8), %rcx
movq %rcx, (%rbp)
movq %rbp, (%rax,%r14,8)
jmp 0x3eeb
movq 0x20(%rbp), %rdx
movq 0x8(%rsp), %r12
movq 0x58(%rsp), %rax
incq (%rbp,%rax)
movq %rdx, 0x18(%rbx)
movq %rdx, %rax
movq 0x50(%rsp), %rcx
shrq %cl, %rax
addq %rdx, %rax
andq 0x48(%rsp), %rax
movq (%r12,%rax,8), %rcx
movq %rcx, (%rbx)
movq %rbx, (%r12,%rax,8)
movq 0x28(%rsp), %rbp
incq %r15
movq 0x38(%rsp), %r12
movq 0x68(%rsp), %rsi
cmpq %rsi, %r12
jb 0x3d53
jmp 0x3f37
xorl %r15d, %r15d
leaq 0x2(%r15), %rsi
movl $0x1, %edi
callq 0x10b0
testq %rax, %rax
je 0x3fbd
movq %rax, %r13
leaq 0x8(,%r15,8), %r14
movq %r14, %rdi
callq 0x10f0
testq %rax, %rax
movq 0x18(%rsp), %rbp
movq 0x8(%rsp), %r12
je 0x3fe4
movq %rax, %rbx
movq %r14, %rdi
callq 0x10f0
testq %rax, %rax
je 0x3fe6
movq 0x10(%rsp), %rdx
movq %r15, 0x38(%rdx)
movq %rbp, 0x60(%rdx)
movq 0x20(%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 %r15
movq %r15, 0x58(%rdx)
jmp 0x3c8c
xorl %r13d, %r13d
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbp
movq 0x8(%rsp), %r12
jmp 0x3c5f
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbp
jmp 0x3ff7
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
jmp 0x3c5f
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r12
xorl %r13d, %r13d
jmp 0x3c5f
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbp
jmp 0x3ffc