// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ecx
movq %rdi, %rbx
movq 0xe8(%rdi), %rax
cmpl 0xc8(%rbx), %ecx
jae 0xf79bc
movq %rax, %rdx
subq $0x1, %rdx
jb 0xf79d8
movq 0xd0(%rbx), %rsi
movl %ecx, %ecx
imulq $0x6, %rcx, %rcx
cmpb $0x2, 0x3(%rsi,%rcx)
jne 0xf798b
movb 0xa0(%rbx), %cl
movq 0xf0(%rbx), %rsi
movb %cl, -0x1(%rsi,%rax)
movl 0x98(%rbx), %ecx
movq %rdx, %rax
jmp 0xf794a
addq %rcx, %rsi
movb 0x2(%rsi), %sil
movq 0xf0(%rbx), %rdi
movb %sil, -0x1(%rdi,%rax)
movq 0xd0(%rbx), %rdi
leaq (%rdi,%rcx), %rsi
cmpb $0x1, 0x3(%rdi,%rcx)
je 0xf7a4e
movzwl (%rsi), %ecx
movq %rdx, %rax
jmp 0xf794a
leaq 0x47015(%rip), %rdx     # 0x13e9d8
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xf7625
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf75d3
cmpl $0x4, 0x10(%rbx)
jl 0xf7acb
pushq $0x4
popq %r12
leaq 0x46ff0(%rip), %r14     # 0x13e9ea
pushq $0x4
popq %rbp
xorl %r15d, %r15d
movl 0xa4(%rbx), %eax
cmpq %rax, %r15
jae 0xf7acb
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 %ebp, %esi
movq %r14, %rdx
movl %r15d, %ecx
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0xf7516
popq %rax
popq %rcx
incq %r15
addq $0x6, %r12
jmp 0xf7a00
movb 0x2(%rsi), %cl
movb %cl, 0xa0(%rbx)
cmpl $0x0, 0x60(%rbx)
jne 0xf7acb
movq 0xe8(%rbx), %rcx
movq %rcx, %r14
subq %rax, %r14
incq %r14
cmpb $0x0, 0x31(%rbx)
je 0xf7a91
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 0xf7acb
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 0xf7abf
movzbl (%rsi), %esi
callq 0xe5bc5
jmp 0xf7ac7
movq %r14, %rdx
callq 0xe46ba
addq %r14, 0x70(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq