// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/clp.c
// Function: de_run_clp
static void de_run_clp(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	const char *tmps;
	int ret;
	i64 pos = 0;

	d = de_malloc(c, sizeof(lctx));

	d->input_encoding_ansi = de_get_input_encoding(c, NULL, DE_ENCODING_WINDOWS1252);

	d->input_encoding_oem = DE_ENCODING_CP437; // default
	tmps = de_get_ext_option(c, "clp:oemenc");
	if(!tmps) {
		tmps = de_get_ext_option(c, "oemenc");
	}
	if(tmps) {
		d->input_encoding_oem = de_encoding_name_to_code(tmps);
		if(d->input_encoding_oem == DE_ENCODING_UNKNOWN) {
			d->input_encoding_oem = DE_ENCODING_CP437;
		}
	}

	ret =  de_get_ext_option_bool(c, "clp:extractall", -1);
	if(ret>0 || (c->extract_level>=2 && ret!=0)) {
		d->extractall = 1;
	}

	d->sig = (UI)de_getu16le_p(&pos);
	de_dbg(c, "signature: 0x%04x", d->sig);
	if(d->sig<0xc350 || d->sig>0xc352) {
		de_err(c, "Not a Windows CLP file");
		goto done;
	}

	d->num_items = de_getu16le_p(&pos);
	de_dbg(c, "num items: %u", (UI)d->num_items);

	d->index_pos = pos;
	d->index_item_len = (d->sig==0xc350) ? 89 : 172;

	if(!do_read_index(c, d)) goto done;
	do_process_items(c, d);

done:
	if(d) {
		de_free(c, d->index_array);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
andq $0x0, 0x8(%rsp)
movl $0x440, %esi            # imm = 0x440
callq 0xdecaf
movq %rax, %r14
pushq $0x9
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x8(%r14)
movl $0xd, 0xc(%r14)
leaq 0xb9d47(%rip), %rsi     # 0x116142
movq %rbx, %rdi
callq 0xdfa87
testq %rax, %rax
jne 0x5c41c
leaq 0xb9d37(%rip), %rsi     # 0x116146
movq %rbx, %rdi
callq 0xdfa87
testq %rax, %rax
je 0x5c430
movq %rax, %rdi
callq 0xe202b
testl %eax, %eax
pushq $0xd
popq %rcx
cmovnel %eax, %ecx
movl %ecx, 0xc(%r14)
leaq 0xb9d16(%rip), %rsi     # 0x11614d
pushq $-0x1
popq %rdx
movq %rbx, %rdi
callq 0xdfae5
testl %eax, %eax
jg 0x5c451
je 0x5c456
cmpl $0x2, 0x90(%rbx)
jl 0x5c456
movb $0x1, 0x4(%r14)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xe3fc4
movl %eax, (%r14)
leaq 0xb373c(%rip), %rsi     # 0x10fbaa
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movl $0xffff3cad, %eax       # imm = 0xFFFF3CAD
addl (%r14), %eax
cmpl $-0x4, %eax
ja 0x5c49d
leaq 0xb9cce(%rip), %rsi     # 0x11615c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x5c649
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r12
movq %r12, %rsi
callq 0xe3fc4
movq %rax, 0x10(%r14)
leaq 0xb9cba(%rip), %rsi     # 0x116173
xorl %r15d, %r15d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq (%r12), %rax
movq %rax, 0x18(%r14)
cmpl $0xc350, (%r14)         # imm = 0xC350
pushq $0x59
popq %rax
movl $0xac, %ecx
cmoveq %rax, %rcx
movq %rcx, 0x20(%r14)
movq 0x10(%r14), %rsi
pushq $0x18
popq %rdx
movq %rbx, %rdi
callq 0xdf66f
movq %rax, 0x30(%r14)
leaq 0xb9c80(%rip), %rsi     # 0x116181
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x10
popq %r13
leaq 0x10(%rsp), %r12
movq 0x10(%r14), %rax
cmpq %rax, %r15
jge 0x5c5be
movq 0x30(%r14), %rbp
movq 0x20(%r14), %rax
imulq %r15, %rax
addq 0x18(%r14), %rax
movq %rax, 0x10(%rsp)
cmpl $0xc350, (%r14)         # imm = 0xC350
movq 0x18(%rbx), %rdi
movq %r12, %rsi
jne 0x5c54d
callq 0xe3fc4
jmp 0x5c552
callq 0xe40bf
movl %eax, -0xc(%rbp,%r13)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
movq %rax, (%rbp,%r13)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
movq %rax, -0x8(%rbp,%r13)
cmpl $0x0, -0xc(%rbp,%r13)
je 0x5c5ac
movq (%rbp,%r13), %rcx
testq %rcx, %rcx
jle 0x5c5b2
cmpq 0x28(%r14), %rax
jl 0x5c635
addq %rax, %rcx
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %rcx
jg 0x5c635
movq %rcx, 0x28(%r14)
jmp 0x5c5b2
andq $0x0, (%rbp,%r13)
incq %r15
addq $0x18, %r13
jmp 0x5c514
xorl %r12d, %r12d
xorl %r15d, %r15d
movl %eax, %ecx
cmpq %rcx, %r15
jae 0x5c602
movq 0x30(%r14), %rcx
movl 0x4(%rcx,%r12), %ecx
cmpl $0x10, %ecx
je 0x5c5de
cmpl $0x9, %ecx
jne 0x5c5f9
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x5c6d9
movq 0x30(%r14), %rax
movb $0x1, (%rax,%r12)
movl 0x10(%r14), %eax
incq %r15
addq $0x18, %r12
jmp 0x5c5c4
xorl %r12d, %r12d
xorl %r15d, %r15d
movl %eax, %ecx
cmpq %rcx, %r15
jae 0x5c649
movq 0x30(%r14), %rcx
cmpb $0x0, (%rcx,%r12)
jne 0x5c62c
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x5c6d9
movl 0x10(%r14), %eax
incq %r15
addq $0x18, %r12
jmp 0x5c608
leaq 0xb9b56(%rip), %rsi     # 0x116192
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xdf2a5
movq 0x30(%r14), %rsi
movq %rbx, %rdi
callq 0xded32
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq