// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/fmtutil-lzw.c
// Function: delzw_process_code
static void delzw_process_code(delzwctx *dc, DELZW_CODE code)
{
	if(dc->debug_level>=3) {
		delzw_debugmsg(dc, 3, "%scode=%d oc=%d lca=%d lv=%d next=%d",
			(dc->special_code_is_pending?"special":""),
			(int)code,
			(int)dc->oldcode, (int)dc->last_code_added, (int)dc->last_value,
			(int)dc->free_code_search_start);
	}

	if(dc->special_code_is_pending) {
		dc->special_code_is_pending = 0;
		if(dc->fmt==DE_LZWFMT_ZIPSHRINK) {
			if(code==1 && (dc->curr_codesize<dc->max_codesize)) {
				delzw_increase_codesize(dc);
			}
			else if(code==2) {
				delzw_partial_clear(dc);
			}
			else {
				delzw_set_error(dc, DELZW_ERRCODE_BAD_CDATA, NULL);
			}
		}
		else if(dc->fmt==DE_LZWFMT_DWC) {
			if(code==0) { // no-op?
				;
			}
			else {
				// TODO: Find out what DWC special codes do
				delzw_set_errorf(dc, DELZW_ERRCODE_UNSUPPORTED_OPTION,
					"Unsupported special code: %u", (UI)code);
			}
		}
		return;
	}

	if(code >= dc->ct_capacity) return;

	switch(dc->ct[code].codetype) {
	case DELZW_CODETYPE_STATIC:
	case DELZW_CODETYPE_DYN_UNUSED:
	case DELZW_CODETYPE_DYN_USED:
		delzw_process_data_code(dc, code);
		break;
	case DELZW_CODETYPE_CLEAR:
		delzw_clear(dc);
		break;
	case DELZW_CODETYPE_STOP:
		delzw_stop(dc, "stop code");
		break;
	case DELZW_CODETYPE_INC_CDSZ:
		delzw_increase_codesize(dc);
		break;
	case DELZW_CODETYPE_SPECIAL:
		if(dc->fmt==DE_LZWFMT_ZIPSHRINK && code==256) {
			dc->special_code_is_pending = 1; // next code is an "escaped" code
		}
		break;
	default:
		delzw_set_errorf(dc, DELZW_ERRCODE_UNSUPPORTED_OPTION,
			"Unsupported or invalid code (%u)", (UI)code);
		break;
	}

	dc->code_counter++;
	if(dc->fmt==DE_LZWFMT_DWC) {
		if((dc->code_counter%512)==256) {
			dc->special_code_is_pending = 1;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x3, 0x10(%rax)
jl 0x18569d
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movzbl 0xb0(%rax), %edx
leaq 0x4b591(%rip), %rcx     # 0x1d0bd0
leaq 0x2ee4a(%rip), %rax     # 0x1b4490
cmpl $0x0, %edx
cmovneq %rax, %rcx
movl -0xc(%rbp), %r8d
movq -0x8(%rbp), %rax
movl 0x98(%rax), %r9d
movq -0x8(%rbp), %rax
movl 0x9c(%rax), %r11d
movq -0x8(%rbp), %rax
movzbl 0xa0(%rax), %r10d
movq -0x8(%rbp), %rax
movl 0xa8(%rax), %eax
movl $0x3, %esi
leaq 0x520ef(%rip), %rdx     # 0x1d7778
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x1848d0
movq -0x8(%rbp), %rax
cmpb $0x0, 0xb0(%rax)
je 0x185743
movq -0x8(%rbp), %rax
movb $0x0, 0xb0(%rax)
movq -0x8(%rbp), %rax
cmpl $0x3, 0x14(%rax)
jne 0x18570e
cmpl $0x1, -0xc(%rbp)
jne 0x1856e7
movq -0x8(%rbp), %rax
movl 0x90(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x48(%rcx), %eax
jae 0x1856e7
movq -0x8(%rbp), %rdi
callq 0x185e60
jmp 0x18570c
cmpl $0x2, -0xc(%rbp)
jne 0x1856f8
movq -0x8(%rbp), %rdi
callq 0x185ef0
jmp 0x18570a
movq -0x8(%rbp), %rdi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x185850
jmp 0x18570c
jmp 0x18573e
movq -0x8(%rbp), %rax
cmpl $0x8, 0x14(%rax)
jne 0x18573c
cmpl $0x0, -0xc(%rbp)
jne 0x185720
jmp 0x18573a
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %ecx
movl $0x9, %esi
leaq 0x5206a(%rip), %rdx     # 0x1d779d
movb $0x0, %al
callq 0x185b00
jmp 0x18573c
jmp 0x18573e
jmp 0x18584a
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc8(%rcx), %eax
jb 0x185757
jmp 0x18584a
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rax
movl -0xc(%rbp), %ecx
leaq (%rcx,%rcx,2), %rcx
movzbl 0x3(%rax,%rcx,2), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x18(%rbp)
subl $0xe, %eax
ja 0x1857e5
movq -0x18(%rbp), %rax
leaq 0x51dde(%rip), %rcx     # 0x1d7564
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x186040
jmp 0x1857ff
movq -0x8(%rbp), %rdi
callq 0x1861f0
jmp 0x1857ff
movq -0x8(%rbp), %rdi
leaq 0x24a8a(%rip), %rsi     # 0x1aa23d
callq 0x184880
jmp 0x1857ff
movq -0x8(%rbp), %rdi
callq 0x185e60
jmp 0x1857ff
movq -0x8(%rbp), %rax
cmpl $0x3, 0x14(%rax)
jne 0x1857e3
cmpl $0x100, -0xc(%rbp)      # imm = 0x100
jne 0x1857e3
movq -0x8(%rbp), %rax
movb $0x1, 0xb0(%rax)
jmp 0x1857ff
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %ecx
movl $0x9, %esi
leaq 0x51fc2(%rip), %rdx     # 0x1d77ba
movb $0x0, %al
callq 0x185b00
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x88(%rax)
movq -0x8(%rbp), %rax
cmpl $0x8, 0x14(%rax)
jne 0x18584a
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
cqto
idivq %rcx
cmpq $0x100, %rdx            # imm = 0x100
jne 0x185848
movq -0x8(%rbp), %rax
movb $0x1, 0xb0(%rax)
jmp 0x18584a
addq $0x30, %rsp
popq %rbp
retq