// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/../foreign/lzhuf.h
// Function: lzhuf_reconst
static void lzhuf_reconst(struct lzahuf_ctx *cctx)
{
	UI i, j, k;
	UI f, l;

	/* collect leaf nodes in the first half of the table */
	/* and replace the freq by (freq + 1) / 2. */
	j = 0;
	for (i = 0; i < cctx->lzhuf_T; i++) {
		if (get_son(cctx, i) >= cctx->lzhuf_T) {
			set_freq(cctx, j, (get_freq(cctx, i) + 1) / 2);
			set_son(cctx, j, get_son(cctx, i));
			j++;
		}
	}
	/* begin constructing tree by connecting sons */
	for (i = 0, j = cctx->lzhuf_N_CHAR; j < cctx->lzhuf_T; i += 2, j++) {
		UI srcidx, dstidx;

		k = i + 1;
		set_freq(cctx, j, get_freq(cctx, i) + get_freq(cctx, k));
		f = get_freq(cctx, j);

		k = j - 1;
		while(f < get_freq(cctx, k)) {
			k--;
		}

		k++;

		l = (j - k);
		srcidx = k;
		dstidx = k + 1;

		if((l > (UI)DE_ARRAYCOUNT(cctx->freq)) ||
			(srcidx+l > (UI)DE_ARRAYCOUNT(cctx->freq)) ||
			(dstidx+l > (UI)DE_ARRAYCOUNT(cctx->freq)))
		{
			cctx->errflag = 1;
			return;
		}

		de_memmove(&cctx->freq[dstidx], &cctx->freq[srcidx], l*sizeof(cctx->freq[0]));
		set_freq(cctx, k, f);

		if((l > (UI)DE_ARRAYCOUNT(cctx->son)) ||
			(srcidx+l > (UI)DE_ARRAYCOUNT(cctx->son)) ||
			(dstidx+l > (UI)DE_ARRAYCOUNT(cctx->son)))
		{
			cctx->errflag = 1;
			return;
		}

		de_memmove(&cctx->son[dstidx], &cctx->son[srcidx], l*sizeof(cctx->son[0]));
		set_son(cctx, k, i);
	}
	/* connect prnt */
	for (i = 0; i < cctx->lzhuf_T; i++) {
		k = get_son(cctx, i);
		if (k >= cctx->lzhuf_T) {
			set_prnt(cctx, k, i);
		} else {
			set_prnt(cctx, k, i);
			set_prnt(cctx, k + 1, i);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
jae 0x18c19b
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x18bdb0
movzwl %ax, %eax
movq -0x8(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
jb 0x18c18b
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x18c0a0
movq -0x40(%rbp), %rdi
movl -0x34(%rbp), %esi
movzwl %ax, %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movzwl %ax, %edx
callq 0x18c440
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x18bdb0
movq -0x30(%rbp), %rdi
movl -0x28(%rbp), %esi
movzwl %ax, %edx
callq 0x18c4c0
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x18c18d
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x18c0fa
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
jae 0x18c37c
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x18c0a0
movzwl %ax, %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x18c0a0
movq -0x50(%rbp), %rdi
movl -0x48(%rbp), %esi
movw %ax, %cx
movl -0x44(%rbp), %eax
movzwl %cx, %ecx
addl %ecx, %eax
movzwl %ax, %edx
callq 0x18c440
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x18c0a0
movzwl %ax, %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x18c0a0
movw %ax, %cx
movl -0x54(%rbp), %eax
movzwl %cx, %ecx
cmpl %ecx, %eax
jae 0x18c250
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x18c226
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x10(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x278, -0x1c(%rbp)     # imm = 0x278
ja 0x18c294
movl -0x20(%rbp), %eax
addl -0x1c(%rbp), %eax
cmpl $0x278, %eax            # imm = 0x278
ja 0x18c294
movl -0x24(%rbp), %eax
addl -0x1c(%rbp), %eax
cmpl $0x278, %eax            # imm = 0x278
jbe 0x18c2a4
movq -0x8(%rbp), %rax
movl $0x1, 0x54(%rax)
jmp 0x18c3f5
movq -0x8(%rbp), %rdi
addq $0x80, %rdi
movl -0x24(%rbp), %eax
shlq %rax
addq %rax, %rdi
movq -0x8(%rbp), %rsi
addq $0x80, %rsi
movl -0x20(%rbp), %eax
shlq %rax
addq %rax, %rsi
movl -0x1c(%rbp), %eax
movl %eax, %edx
shlq %rdx
callq 0x19260
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %eax
movzwl %ax, %edx
callq 0x18c440
cmpl $0x277, -0x1c(%rbp)     # imm = 0x277
ja 0x18c30e
movl -0x20(%rbp), %eax
addl -0x1c(%rbp), %eax
cmpl $0x277, %eax            # imm = 0x277
ja 0x18c30e
movl -0x24(%rbp), %eax
addl -0x1c(%rbp), %eax
cmpl $0x277, %eax            # imm = 0x277
jbe 0x18c31e
movq -0x8(%rbp), %rax
movl $0x1, 0x54(%rax)
jmp 0x18c3f5
movq -0x8(%rbp), %rdi
addq $0xcd6, %rdi            # imm = 0xCD6
movl -0x24(%rbp), %eax
shlq %rax
addq %rax, %rdi
movq -0x8(%rbp), %rsi
addq $0xcd6, %rsi            # imm = 0xCD6
movl -0x20(%rbp), %eax
shlq %rax
addq %rax, %rsi
movl -0x1c(%rbp), %eax
movl %eax, %edx
shlq %rdx
callq 0x19260
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0xc(%rbp), %eax
movzwl %ax, %edx
callq 0x18c4c0
movl -0xc(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xc(%rbp)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x18c1ac
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
jae 0x18c3f5
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x18bdb0
movzwl %ax, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
jb 0x18c3c1
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0xc(%rbp), %eax
movzwl %ax, %edx
callq 0x18c480
jmp 0x18c3e8
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0xc(%rbp), %eax
movzwl %ax, %edx
callq 0x18c480
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
addl $0x1, %esi
movl -0xc(%rbp), %eax
movzwl %ax, %edx
callq 0x18c480
jmp 0x18c3ea
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x18c383
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)