// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rax
movq %rax, -0x18(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc8(%rcx), %eax
jb 0x186512
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %ecx
movl $0x1, %esi
leaq 0x51372(%rip), %rdx     # 0x1d7878
movb $0x0, %al
callq 0x185b00
jmp 0x18664e
cmpq $0x0, -0x18(%rbp)
jne 0x186543
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x185850
movq -0x8(%rbp), %rax
cmpl $0x4, 0x10(%rax)
jl 0x18653e
movq -0x8(%rbp), %rdi
callq 0x186880
jmp 0x18664e
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rax
movl -0x10(%rbp), %ecx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movzbl 0x3(%rax), %eax
cmpl $0x2, %eax
jne 0x18659b
movq -0x8(%rbp), %rax
movb 0xa0(%rax), %dl
movq -0x8(%rbp), %rax
movq 0xf0(%rax), %rax
movq -0x18(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x98(%rax), %eax
movl %eax, -0x10(%rbp)
jmp 0x1864e4
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rax
movl -0x10(%rbp), %ecx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movb 0x2(%rax), %dl
movq -0x8(%rbp), %rax
movq 0xf0(%rax), %rax
movq -0x18(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rax
movl -0x10(%rbp), %ecx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movzbl 0x3(%rax), %eax
cmpl $0x1, %eax
jne 0x186607
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rax
movl -0x10(%rbp), %ecx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movb 0x2(%rax), %cl
movq -0x8(%rbp), %rax
movb %cl, 0xa0(%rax)
jmp 0x186627
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rax
movl -0x10(%rbp), %ecx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movzwl (%rax), %eax
movl %eax, -0x10(%rbp)
jmp 0x1864e4
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0xf0(%rax), %rsi
addq -0x18(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rdx
subq -0x18(%rbp), %rdx
callq 0x186950
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)