// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movq %r8, %r13
movq %rcx, 0x18(%rsp)
movq %rdx, %r15
movq %rsi, %r14
movl %edi, %ebx
pushq $0x4
popq %rcx
movq %rdx, %rax
cqto
idivq %rcx
leaq 0x1(%rax), %rdx
pushq $0x20
popq %rsi
movq %r9, 0x10(%rsp)
movq %r9, %rdi
callq 0x3b7a
testl %eax, %eax
js 0x36b1
movq %r15, 0x8(%rsp)
leaq (,%r15,8), %rdi
callq 0x10f0
xorl %r12d, %r12d
testq %rax, %rax
je 0x36b1
movq %rax, %r15
movq 0x18(%rsp), %rax
movl (%rax), %eax
andl $0x60, %eax
cmpl $0x40, %eax
jne 0x36f7
xorl %ebp, %ebp
jmp 0x3723
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rbx, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
movq %rbp, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x3b98
pushq $-0x1
popq %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
callq 0x40c7
movl %eax, %r12d
pushq $0x1
popq %rax
movl %r12d, %ecx
shll %cl, %eax
movslq %eax, %rsi
shlq $0x3, %rsi
pushq $0x1
popq %rdi
callq 0x10b0
testq %rax, %rax
je 0x36b4
movq %rax, %rbp
leaq 0x60(%rsp), %rsi
movq %r14, %rdi
callq 0x3b6a
movq %rax, 0x20(%rsp)
testq %rax, %rax
movq %r12, 0x28(%rsp)
je 0x395d
movq %rax, %r14
movq %rbp, (%rsp)
movq 0x60(%rsp), %rsi
addq %rax, %rsi
leaq 0x18(%r13), %rax
movq %rax, 0x30(%rsp)
xorl %eax, %eax
cmpl $0x1, %ebx
setne %al
leaq 0x28(,%rax,8), %rax
movq %rax, 0x48(%rsp)
movl %r12d, %eax
movq %rax, 0x40(%rsp)
pushq $-0x1
popq %rax
movl %r12d, %ecx
shlq %cl, %rax
notq %rax
movq %rax, 0x38(%rsp)
xorl %r12d, %r12d
movq %rsi, 0x58(%rsp)
cmpq %rsi, %r14
movq 0x8(%rsp), %rbx
jae 0x3962
movq 0x18(%rsp), %rax
movq (%rax), %rdx
leaq 0x20(%rsp), %rdi
callq 0x3f8d
movq %rax, %rbp
cmpq %rbx, %r12
jl 0x37dc
movq %rbx, %rsi
shlq $0x4, %rsi
movq %r15, %rdi
callq 0x1110
testq %rax, %rax
je 0x394f
addq %rbx, %rbx
movq %rbx, 0x8(%rsp)
movq %rax, %r15
movq 0x10(%rsp), %rdi
callq 0x3bb0
testq %rax, %rax
je 0x394f
movq %rax, %rbx
movq %r14, 0x8(%rax)
movq 0x20(%rsp), %rax
subq %r14, %rax
movq %rax, 0x10(%rbx)
movq %rbp, 0x18(%rbx)
movq %rbx, (%r15,%r12,8)
movq 0x18(%rsp), %rax
movl (%rax), %eax
andl $0x60, %eax
cmpl $0x40, %eax
je 0x393d
movb (%r13), %cl
movq %rbp, %rax
shrq %cl, %rax
movq 0x8(%rbx), %rdx
movq %rdx, 0x50(%rsp)
addq %rbp, %rax
pushq $-0x1
popq %rbp
shlq %cl, %rbp
notq %rbp
andq %rax, %rbp
leaq (,%rbp,8), %r14
addq 0x10(%r13), %r14
movq (%r14), %r14
testq %r14, %r14
je 0x3883
movq 0x8(%r14), %rax
cmpq 0x18(%rbx), %rax
jne 0x384b
movq 0x10(%r14), %rdi
movq 0x18(%r14), %rsi
movq 0x8(%rbx), %rdx
movq 0x10(%rbx), %rcx
movq 0x68(%r13), %r8
callq 0x3d01
testl %eax, %eax
je 0x384b
movq 0x20(%r14), %rdx
jmp 0x390e
movq 0x30(%rsp), %rdi
callq 0x3bb0
testq %rax, %rax
je 0x394f
movq %rax, %r14
movq 0x60(%r13), %rdx
leaq 0x1(%rdx), %rax
movq %rax, 0x60(%r13)
movq %rdx, 0x20(%r14)
movq 0x58(%r13), %rsi
cmpq %rsi, %rdx
jge 0x38b8
movq 0x50(%r13), %rax
jmp 0x38da
leaq (%rsi,%rsi), %rax
movq %rax, 0x58(%r13)
movq 0x50(%r13), %rdi
shlq $0x4, %rsi
callq 0x1110
testq %rax, %rax
je 0x394f
movq %rax, 0x50(%r13)
movq 0x20(%r14), %rdx
movq %r14, (%rax,%rdx,8)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%r14)
movq 0x10(%rbx), %rax
movq %rax, 0x18(%r14)
movq 0x18(%rbx), %rax
movq %rax, 0x8(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%r14)
movq 0x10(%r13), %rax
movq (%rax,%rbp,8), %rcx
movq %rcx, (%r14)
movq %r14, (%rax,%rbp,8)
movq 0x48(%rsp), %rax
incq (%r14,%rax)
movq %rdx, 0x18(%rbx)
movq %rdx, %rax
movq 0x40(%rsp), %rcx
shrq %cl, %rax
addq %rdx, %rax
andq 0x38(%rsp), %rax
movq (%rsp), %rdx
movq (%rdx,%rax,8), %rcx
movq %rcx, (%rbx)
movq %rbx, (%rdx,%rax,8)
incq %r12
movq 0x20(%rsp), %r14
movq 0x58(%rsp), %rsi
jmp 0x3791
xorl %ebx, %ebx
movq (%rsp), %rbp
xorl %r13d, %r13d
jmp 0x36bb
xorl %r12d, %r12d
jmp 0x3966
movq (%rsp), %rbp
leaq 0x2(%r12), %rsi
pushq $0x1
popq %rdi
callq 0x10b0
testq %rax, %rax
je 0x36b6
movq %rax, %r13
leaq 0x8(,%r12,8), %r14
movq %r14, %rdi
callq 0x10f0
testq %rax, %rax
je 0x36b9
movq %rax, %rbx
movq %r14, %rdi
callq 0x10f0
testq %rax, %rax
je 0x36bb
movq 0x10(%rsp), %rcx
movq %r12, 0x38(%rcx)
movq %r15, 0x60(%rcx)
movq 0x28(%rsp), %rdx
movl %edx, 0x40(%rcx)
movq %rbp, 0x48(%rcx)
incq %r13
movq %r13, 0x68(%rcx)
movq %rbx, 0x70(%rcx)
andq $0x0, 0x78(%rcx)
movq %rax, 0x80(%rcx)
andq $0x0, 0x50(%rcx)
decq %r12
movq %r12, 0x58(%rcx)
xorl %eax, %eax
jmp 0x36e8