// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/libsmacker/smacker.c
// Function: smk_huff8_build_rec
static int _smk_huff8_build_rec(struct smk_huff8_t * const t, struct smk_bit_t * const bs)
{
	int bit, value;
	assert(t);
	assert(bs);

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

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

	if (bit) {
		/* Bit set: this forms a Branch node.
			what we have to do is build the left-hand branch,
			assign the "jump" address,
			then build the right hand branch from there.
		*/
		/* track the current index */
		value = t->size ++;

		/* go build the left branch */
		if (! _smk_huff8_build_rec(t, bs)) {
			fputs("libsmacker::_smk_huff8_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_HUFF8_BRANCH | t->size;

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

		/* store to tree */
		t->tree[t->size ++] = value;
	}

	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x48239
jmp 0x48258
leaq 0x92a75(%rip), %rdi     # 0xdacb5
leaq 0xa507c(%rip), %rsi     # 0xed2c3
movl $0x76, %edx
leaq 0xa6513(%rip), %rcx     # 0xee766
callq 0x8230
cmpq $0x0, -0x18(%rbp)
je 0x48261
jmp 0x48280
leaq 0xa7272(%rip), %rdi     # 0xef4da
leaq 0xa5054(%rip), %rsi     # 0xed2c3
movl $0x77, %edx
leaq 0xa64eb(%rip), %rcx     # 0xee766
callq 0x8230
movq -0x10(%rbp), %rax
cmpq $0x1ff, (%rax)          # imm = 0x1FF
jb 0x482af
movq 0xd0d44(%rip), %rax     # 0x118fd8
movq (%rax), %rsi
leaq 0xa6515(%rip), %rdi     # 0xee7b3
callq 0x8430
movl $0x0, -0x4(%rbp)
jmp 0x483db
movq -0x18(%rbp), %rdi
callq 0x47bc0
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
jge 0x482e2
movq 0xd0d11(%rip), %rax     # 0x118fd8
movq (%rax), %rsi
leaq 0xa651d(%rip), %rdi     # 0xee7ee
callq 0x8430
movl $0x0, -0x4(%rbp)
jmp 0x483db
cmpl $0x0, -0x1c(%rbp)
je 0x48384
movq -0x10(%rbp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x48220
cmpl $0x0, %eax
jne 0x48334
movq 0xd0cbf(%rip), %rax     # 0x118fd8
movq (%rax), %rsi
leaq 0xa650c(%rip), %rdi     # 0xee82f
callq 0x8430
movl $0x0, -0x4(%rbp)
jmp 0x483db
movq -0x10(%rbp), %rax
movq (%rax), %rax
orq $0x8000, %rax           # imm = 0x8000
movw %ax, %dx
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movw %dx, 0x8(%rax,%rcx,2)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x48220
cmpl $0x0, %eax
jne 0x48382
movq 0xd0c6e(%rip), %rax     # 0x118fd8
movq (%rax), %rsi
leaq 0xa6506(%rip), %rdi     # 0xee87a
callq 0x8430
movl $0x0, -0x4(%rbp)
jmp 0x483db
jmp 0x483d4
movq -0x18(%rbp), %rdi
callq 0x47dd0
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
jge 0x483b4
movq 0xd0c3c(%rip), %rax     # 0x118fd8
movq (%rax), %rsi
leaq 0xa6520(%rip), %rdi     # 0xee8c6
callq 0x8430
movl $0x0, -0x4(%rbp)
jmp 0x483db
movl -0x20(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movw %dx, 0x8(%rax,%rcx,2)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)