// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/src/fmtutil-lzw.c
// Function: delzw_emit_code
static void delzw_emit_code(delzwctx *dc, DELZW_CODE code1)
{
	DELZW_CODE code = code1;
	size_t valbuf_pos = dc->valbuf_capacity; // = First entry that's used

	while(1) {
		if(code >= dc->ct_capacity) {
			delzw_set_errorf(dc, DELZW_ERRCODE_GENERIC_ERROR, "Bad LZW code (%d)", (int)code);
			return;
		}

		if(valbuf_pos==0) {
			// We must be in an infinite loop (probably an internal error).
			delzw_set_error(dc, DELZW_ERRCODE_GENERIC_ERROR, NULL);
			if(dc->debug_level>=4) {
				delzw_dumptable(dc);
			}
			return;
		}

		// valbuf is a stack, essentially. We fill it in the reverse direction,
		// to make it simpler to write the final byte sequence.
		valbuf_pos--;

		if(dc->ct[code].codetype==DELZW_CODETYPE_DYN_UNUSED) {
			dc->valbuf[valbuf_pos] = dc->last_value;
			code = dc->oldcode;
			continue;
		}

		dc->valbuf[valbuf_pos] = dc->ct[code].value;

		if(dc->ct[code].codetype==DELZW_CODETYPE_STATIC) {
			dc->last_value = dc->ct[code].value;
			break;
		}

		// Traverse the tree, back toward the root codes.
		code = dc->ct[code].parent;
	}

	// Write out the collected values.
	delzw_write(dc, &dc->valbuf[valbuf_pos], dc->valbuf_capacity - valbuf_pos);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ecx
movq %rdi, %rbx
cmpl %esi, 0xc8(%rdi)
jbe 0x10442f
movq 0xe8(%rbx), %rax
movq %rax, %rdx
subq $0x1, %rdx
jb 0x104450
movq 0xd0(%rbx), %rsi
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
cmpb $0x2, 0x3(%rsi,%rcx,2)
jne 0x1043f8
movb 0xa0(%rbx), %cl
movq 0xf0(%rbx), %rsi
movb %cl, -0x1(%rsi,%rax)
movl 0x98(%rbx), %ecx
jmp 0x104424
leaq (%rsi,%rcx,2), %rsi
movb 0x2(%rsi), %sil
movq 0xf0(%rbx), %rdi
movb %sil, -0x1(%rdi,%rax)
movq 0xd0(%rbx), %rsi
leaq (%rsi,%rcx,2), %rcx
cmpb $0x1, 0x3(%rcx)
je 0x1044d5
movzwl (%rcx), %ecx
movq %rdx, %rax
cmpl 0xc8(%rbx), %ecx
jb 0x1043c1
leaq 0x47482(%rip), %rdx     # 0x14b8b8
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x104095
movq %rbx, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x104022
cmpl $0x4, 0x10(%rbx)
jl 0x104552
cmpl $0x0, 0xa4(%rbx)
je 0x104552
movl $0x4, %r12d
leaq 0x47447(%rip), %r14     # 0x14b8ca
xorl %r15d, %r15d
movq 0xd0(%rbx), %rax
movzbl -0x1(%rax,%r12), %r8d
movzwl -0x4(%rax,%r12), %r9d
movzbl -0x2(%rax,%r12), %r10d
movzbl (%rax,%r12), %r11d
movq %rbx, %rdi
movl $0x4, %esi
movq %r14, %rdx
movl %r15d, %ecx
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x103f65
addq $0x10, %rsp
incq %r15
movl 0xa4(%rbx), %eax
addq $0x6, %r12
cmpq %rax, %r15
jb 0x104486
jmp 0x104552
movb 0x2(%rcx), %cl
movb %cl, 0xa0(%rbx)
cmpl $0x0, 0x60(%rbx)
jne 0x104552
movq 0xe8(%rbx), %rcx
movq %rcx, %r14
subq %rax, %r14
incq %r14
cmpb $0x0, 0x31(%rbx)
je 0x104518
movq 0x38(%rbx), %rdx
movq 0x70(%rbx), %rsi
addq %rsi, %rcx
subq %rax, %rcx
incq %rcx
movq %rdx, %rdi
subq %rsi, %rdi
cmpq %rdx, %rcx
cmovgq %rdi, %r14
testq %r14, %r14
jle 0x104552
movq 0xf0(%rbx), %rcx
leaq (%rcx,%rax), %rsi
decq %rsi
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
cmpq $0x1, %r14
jne 0x104546
movzbl (%rsi), %esi
callq 0xf11be
jmp 0x10454e
movq %r14, %rdx
callq 0xefb82
addq %r14, 0x70(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq