// File: /workspace/github_c_makefile_star2_O2/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 0x2db3e
movq %rcx, %r14
testq %rcx, %rcx
je 0x2db5d
movq %r8, %r12
movq %rdi, %rbx
cmpq %r8, 0x8(%rdi)
jae 0x2dacb
movq %rdx, %r13
movq %rsi, %r15
movq %rsi, %rdi
callq 0x2d7dc
testl %eax, %eax
js 0x2dade
je 0x2da51
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 0x2d99e
testl %eax, %eax
je 0x2daf1
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 0x2d99e
testl %eax, %eax
jne 0x2dac6
movq 0x99556(%rip), %rax     # 0xc6f98
movq (%rax), %rsi
leaq 0x68f7a(%rip), %rdi     # 0x969c6
jmp 0x2db28
movq %r13, %rdi
movq %r15, %rsi
callq 0x2dc67
testl %eax, %eax
js 0x2db04
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
movl %eax, (%rcx,%rdx,4)
movq %r14, %rdi
movq %r15, %rsi
callq 0x2dc67
testl %eax, %eax
js 0x2db17
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 0x2dabf
movzwl 0x12(%rbx), %edi
movl $0x40000001, %esi       # imm = 0x40000001
cmpl %edi, %edx
je 0x2dabf
movzwl 0x14(%rbx), %edi
movl $0x40000002, %esi       # imm = 0x40000002
cmpl %edi, %edx
jne 0x2dac2
movl %esi, (%rax,%rcx,4)
incq 0x8(%rbx)
pushq $0x1
popq %rax
jmp 0x2db2f
movq 0x994c6(%rip), %rax     # 0xc6f98
movq (%rax), %rsi
leaq 0x68e20(%rip), %rdi     # 0x968fc
jmp 0x2db28
movq 0x994b3(%rip), %rax     # 0xc6f98
movq (%rax), %rsi
leaq 0x68e49(%rip), %rdi     # 0x96938
jmp 0x2db28
movq 0x994a0(%rip), %rax     # 0xc6f98
movq (%rax), %rsi
leaq 0x68e78(%rip), %rdi     # 0x9697a
jmp 0x2db28
movq 0x9948d(%rip), %rax     # 0xc6f98
movq (%rax), %rsi
leaq 0x68efe(%rip), %rdi     # 0x96a13
jmp 0x2db28
movq 0x9947a(%rip), %rax     # 0xc6f98
movq (%rax), %rsi
leaq 0x68f33(%rip), %rdi     # 0x96a5b
callq 0x8470
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68dae(%rip), %rdi     # 0x968f3
leaq 0x67787(%rip), %rsi     # 0x952d3
leaq 0x68d01(%rip), %rcx     # 0x96854
movl $0x10c, %edx            # imm = 0x10C
callq 0x8240
leaq 0x68d94(%rip), %rdi     # 0x968f8
leaq 0x67768(%rip), %rsi     # 0x952d3
leaq 0x68ce2(%rip), %rcx     # 0x96854
movl $0x10d, %edx            # imm = 0x10D
callq 0x8240