// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xb8, %rsp
movl %edi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movq %rcx, 0x98(%rsp)
movq %r8, 0x90(%rsp)
movq %r9, 0x88(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x88(%rsp), %rdi
movq 0xa0(%rsp), %rax
movl $0x4, %ecx
cqto
idivq %rcx
movq %rax, %rdx
addq $0x1, %rdx
movl $0x20, %esi
callq 0x6db0
cmpl $0x0, %eax
jge 0x5bc8
jmp 0x5f34
movq 0xa0(%rsp), %rdi
shlq $0x3, %rdi
callq 0x10f0
movq %rax, 0x30(%rsp)
cmpq $0x0, %rax
jne 0x5be9
jmp 0x5f34
movq 0x98(%rsp), %rax
movq (%rax), %rax
andq $0x60, %rax
cmpq $0x40, %rax
jne 0x5c14
movq $0x0, 0x70(%rsp)
movl $0x0, 0x84(%rsp)
jmp 0x5c72
movq 0xa0(%rsp), %rax
movl %eax, %edi
callq 0x79f0
movl %eax, 0x84(%rsp)
movl 0x84(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
cltq
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rdi
shlq $0x3, %rdi
callq 0x10f0
movq %rax, 0x20(%rsp)
cmpq $0x0, %rax
jne 0x5c5d
jmp 0x5f34
movq 0x20(%rsp), %rdi
movq 0x70(%rsp), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x1090
movq $0x0, 0x78(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x6d70
movq %rax, 0x58(%rsp)
movq %rax, 0x50(%rsp)
cmpq $0x0, %rax
je 0x5df4
movq 0x58(%rsp), %rax
addq 0x68(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x48(%rsp), %rax
jae 0x5df2
movq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rsi
movq 0x98(%rsp), %rax
movq (%rax), %rdx
leaq 0x50(%rsp), %rdi
callq 0x7680
movq %rax, 0x60(%rsp)
movq 0x78(%rsp), %rax
cmpq 0xa0(%rsp), %rax
jl 0x5d3b
movq 0xa0(%rsp), %rax
shlq %rax
movq %rax, 0xa0(%rsp)
movq 0x30(%rsp), %rdi
movq 0xa0(%rsp), %rsi
shlq $0x3, %rsi
callq 0x1100
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
jne 0x5d31
jmp 0x5f34
movq 0x28(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x88(%rsp), %rdi
callq 0x6e80
movq %rax, 0x38(%rsp)
cmpq $0x0, %rax
jne 0x5d58
jmp 0x5f34
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x50(%rsp), %rcx
movq 0x40(%rsp), %rax
subq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x60(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rax
movq 0x78(%rsp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x78(%rsp)
movq %rdx, (%rax,%rcx,8)
movq 0x98(%rsp), %rax
movq (%rax), %rax
andq $0x60, %rax
cmpq $0x40, %rax
je 0x5ded
movl 0xb0(%rsp), %edi
movq 0x90(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl 0x84(%rsp), %ecx
movq 0x38(%rsp), %r8
callq 0x60a0
cmpl $0x0, %eax
jge 0x5ded
jmp 0x5f34
jmp 0x5cb0
jmp 0x5df4
movq 0x78(%rsp), %rdi
addq $0x2, %rdi
shlq $0x0, %rdi
callq 0x10f0
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
jne 0x5e16
jmp 0x5f34
movq 0x10(%rsp), %rdi
movq 0x78(%rsp), %rdx
addq $0x2, %rdx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x1090
movq 0x78(%rsp), %rdi
addq $0x1, %rdi
shlq $0x3, %rdi
callq 0x10f0
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
jne 0x5e51
jmp 0x5f34
movq 0x78(%rsp), %rdi
addq $0x1, %rdi
shlq $0x3, %rdi
callq 0x10f0
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
jne 0x5e73
jmp 0x5f34
movq 0x78(%rsp), %rcx
movq 0x88(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x30(%rsp), %rcx
movq 0x88(%rsp), %rax
movq %rcx, 0x60(%rax)
movl 0x84(%rsp), %ecx
movq 0x88(%rsp), %rax
movl %ecx, 0x40(%rax)
movq 0x20(%rsp), %rcx
movq 0x88(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x10(%rsp), %rcx
addq $0x1, %rcx
movq 0x88(%rsp), %rax
movq %rcx, 0x68(%rax)
movq 0x8(%rsp), %rcx
movq 0x88(%rsp), %rax
movq %rcx, 0x70(%rax)
movq 0x88(%rsp), %rax
movq $0x0, 0x78(%rax)
movq 0x18(%rsp), %rcx
movq 0x88(%rsp), %rax
movq %rcx, 0x80(%rax)
movq 0x88(%rsp), %rax
movq $0x0, 0x50(%rax)
movq 0x78(%rsp), %rcx
subq $0x1, %rcx
movq 0x88(%rsp), %rax
movq %rcx, 0x58(%rax)
movl $0x0, 0xb4(%rsp)
jmp 0x5f7e
movq 0x18(%rsp), %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movq 0x20(%rsp), %rdi
callq 0x1030
movq 0x30(%rsp), %rdi
callq 0x1030
movq 0x88(%rsp), %rdi
callq 0x6e30
movl $0xffffffff, 0xb4(%rsp) # imm = 0xFFFFFFFF
movl 0xb4(%rsp), %eax
addq $0xb8, %rsp
retq
nopl (%rax)