// File: /workspace/github_c_makefile_star2_O1/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 0x303ef
movq %rcx, %r14
testq %rcx, %rcx
je 0x3040e
movq %r8, %r12
movq %rdi, %rbx
cmpq %r8, 0x8(%rdi)
jae 0x303bd
movq %rdx, %r13
movq %rsi, %r15
movq %rsi, %rdi
callq 0x300f9
testl %eax, %eax
js 0x303c4
je 0x30349
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 0x3029b
testl %eax, %eax
je 0x303cb
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 0x3029b
movl %eax, %ecx
movl $0x1, %eax
testl %ecx, %ecx
jne 0x303e0
callq 0x9cf6
jmp 0x303de
movq %r13, %rdi
movq %r15, %rsi
callq 0x304d8
testl %eax, %eax
js 0x303d2
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
movl %eax, (%rcx,%rdx,4)
movq %r14, %rdi
movq %r15, %rsi
callq 0x304d8
testl %eax, %eax
js 0x303d9
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 0x303af
movzwl 0x12(%rbx), %edi
movl $0x40000001, %esi       # imm = 0x40000001
cmpl %edi, %edx
je 0x303af
movzwl 0x14(%rbx), %edi
movl $0x40000002, %esi       # imm = 0x40000002
cmpl %edi, %edx
jne 0x303b2
movl %esi, (%rax,%rcx,4)
incq 0x8(%rbx)
movl $0x1, %eax
jmp 0x303e0
callq 0x9ce0
jmp 0x303de
callq 0x9d4e
jmp 0x303de
callq 0x9d0c
jmp 0x303de
callq 0x9d38
jmp 0x303de
callq 0x9d22
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7148d(%rip), %rdi     # 0xa1883
leaq 0x6fe66(%rip), %rsi     # 0xa0263
leaq 0x713e0(%rip), %rcx     # 0xa17e4
movl $0x10c, %edx            # imm = 0x10C
callq 0x8240
leaq 0x71473(%rip), %rdi     # 0xa1888
leaq 0x6fe47(%rip), %rsi     # 0xa0263
leaq 0x713c1(%rip), %rcx     # 0xa17e4
movl $0x10d, %edx            # imm = 0x10D
callq 0x8240