// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/libsmacker/smacker.c
// Function: smk_huff16_build_rec
static int _smk_huff16_build_rec(struct smk_huff16_t * const t, struct smk_bit_t * const bs, const struct smk_huff8_t * const low8, const struct smk_huff8_t * const hi8, const size_t limit)
{
	int bit, value;
	assert(t);
	assert(bs);
	assert(low8);
	assert(hi8);

	/* Make sure we aren't running out of bounds */
	if (t->size >= limit) {
		fputs("libsmacker::_smk_huff16_build_rec() - ERROR: size exceeded\n", stderr);
		return 0;
	}

	/* Read the first bit */
	if ((bit = smk_bs_read_1(bs)) < 0) {
		fputs("libsmacker::_smk_huff16_build_rec() - ERROR: get_bit returned -1\n", stderr);
		return 0;
	}

	if (bit) {
		/* See tree-in-array explanation for HUFF8 above */
		/* track the current index */
		value = t->size ++;

		/* go build the left branch */
		if (! _smk_huff16_build_rec(t, bs, low8, hi8, limit)) {
			fputs("libsmacker::_smk_huff16_build_rec() - ERROR: failed to build left sub-tree\n", stderr);
			return 0;
		}

		/* now go back to our current location, and
			mark our location as a "jump" */
		t->tree[value] = SMK_HUFF16_BRANCH | t->size;

		/* continue building the right side */
		if (! _smk_huff16_build_rec(t, bs, low8, hi8, limit)) {
			fputs("libsmacker::_smk_huff16_build_rec() - ERROR: failed to build right sub-tree\n", stderr);
			return 0;
		}
	} else {
		/* Bit unset signifies a Leaf node. */
		/* Attempt to read LOW value */
		if ((value = smk_huff8_lookup(low8, bs)) < 0) {
			fputs("libsmacker::_smk_huff16_build_rec() - ERROR: get LOW value returned -1\n", stderr);
			return 0;
		}

		t->tree[t->size] = value;

		/* now read HIGH value */
		if ((value = smk_huff8_lookup(hi8, bs)) < 0) {
			fputs("libsmacker::_smk_huff16_build_rec() - ERROR: get HIGH value returned -1\n", stderr);
			return 0;
		}

		/* Looks OK: we got low and hi values. Return a new LEAF */
		t->tree[t->size] |= (value << 8);

		/* Last: when building the tree, some Values may correspond to cache positions.
			Identify these values and set the Escape code byte accordingly. */
		if (t->tree[t->size] == t->cache[0])
			t->tree[t->size] = SMK_HUFF16_CACHE;
		else if (t->tree[t->size] == t->cache[1])
			t->tree[t->size] = SMK_HUFF16_CACHE | 1;
		else if (t->tree[t->size] == t->cache[2])
			t->tree[t->size] = SMK_HUFF16_CACHE | 2;

		t->size ++;
	}

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdx, %rdx
je 0x31731
movq %rcx, %r14
testq %rcx, %rcx
je 0x31750
movq %r8, %r12
movq %rdi, %rbx
cmpq %r8, 0x8(%rdi)
jae 0x316ff
movq %rdx, %r13
movq %rsi, %r15
movq %rsi, %rdi
callq 0x3143b
testl %eax, %eax
js 0x31706
je 0x3168b
movq 0x8(%rbx), %rbp
leaq 0x1(%rbp), %rax
movq %rax, 0x8(%rbx)
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %r12, %r8
callq 0x315dd
testl %eax, %eax
je 0x3170d
movl $0x80000000, %eax       # imm = 0x80000000
orl 0x8(%rbx), %eax
movq (%rbx), %rcx
movslq %ebp, %rdx
movl %eax, (%rcx,%rdx,4)
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %r12, %r8
callq 0x315dd
movl %eax, %ecx
movl $0x1, %eax
testl %ecx, %ecx
jne 0x31722
callq 0x9d0d
jmp 0x31720
movq %r13, %rdi
movq %r15, %rsi
callq 0x3181a
testl %eax, %eax
js 0x31714
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
movl %eax, (%rcx,%rdx,4)
movq %r14, %rdi
movq %r15, %rsi
callq 0x3181a
testl %eax, %eax
js 0x3171b
shll $0x8, %eax
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
orl %eax, (%rcx,%rdx,4)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movl (%rax,%rcx,4), %edx
movzwl 0x10(%rbx), %edi
movl $0x40000000, %esi       # imm = 0x40000000
cmpl %edi, %edx
je 0x316f1
movzwl 0x12(%rbx), %edi
movl $0x40000001, %esi       # imm = 0x40000001
cmpl %edi, %edx
je 0x316f1
movzwl 0x14(%rbx), %edi
movl $0x40000002, %esi       # imm = 0x40000002
cmpl %edi, %edx
jne 0x316f4
movl %esi, (%rax,%rcx,4)
incq 0x8(%rbx)
movl $0x1, %eax
jmp 0x31722
callq 0x9cf7
jmp 0x31720
callq 0x9d65
jmp 0x31720
callq 0x9d23
jmp 0x31720
callq 0x9d4f
jmp 0x31720
callq 0x9d39
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x732fb(%rip), %rdi     # 0xa4a33
leaq 0x71cd4(%rip), %rsi     # 0xa3413
leaq 0x7324e(%rip), %rcx     # 0xa4994
movl $0x10c, %edx            # imm = 0x10C
callq 0x8240
leaq 0x732e1(%rip), %rdi     # 0xa4a38
leaq 0x71cb5(%rip), %rsi     # 0xa3413
leaq 0x7322f(%rip), %rcx     # 0xa4994
movl $0x10d, %edx            # imm = 0x10D
callq 0x8240