// File: /workspace/github_c_makefile_star2_O3/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
movq $0x0, 0x8(%rsp)
movl $0x440, %esi            # imm = 0x440
callq 0xe8b2b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb220
movl %eax, 0x8(%r14)
movl $0xd, 0xc(%r14)
leaq 0xc3bc2(%rip), %rsi     # 0x123302
movq %rbx, %rdi
callq 0xe9b74
testq %rax, %rax
jne 0x5f761
leaq 0xc3bb2(%rip), %rsi     # 0x123306
movq %rbx, %rdi
callq 0xe9b74
testq %rax, %rax
je 0x5f777
movq %rax, %rdi
callq 0xecb12
testl %eax, %eax
movl $0xd, %ecx
cmovnel %eax, %ecx
movl %ecx, 0xc(%r14)
leaq 0xc3b8f(%rip), %rsi     # 0x12330d
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xe9bd0
testl %eax, %eax
jg 0x5f79a
je 0x5f79f
cmpl $0x2, 0x90(%rbx)
jl 0x5f79f
movb $0x1, 0x4(%r14)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xeebeb
movl %eax, (%r14)
leaq 0xbd4e3(%rip), %rsi     # 0x11cc9a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movl $0xffff3cad, %eax       # imm = 0xFFFF3CAD
addl (%r14), %eax
cmpl $-0x4, %eax
ja 0x5f7e6
leaq 0xc3b45(%rip), %rsi     # 0x12331c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x5f9ad
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0xeebeb
movq %rax, 0x10(%r14)
leaq 0xc3b31(%rip), %rsi     # 0x123333
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq (%r15), %rax
movq %rax, 0x18(%r14)
cmpl $0xc350, (%r14)         # imm = 0xC350
movl $0x59, %eax
movl $0xac, %ecx
cmoveq %rax, %rcx
movq %rcx, 0x20(%r14)
movq 0x10(%r14), %rsi
movl $0x18, %edx
movq %rbx, %rdi
callq 0xe96f7
movq %rax, 0x30(%r14)
leaq 0xc3af7(%rip), %rsi     # 0x123341
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x10(%r14), %rax
testq %rax, %rax
jle 0x5f917
movl $0x10, %r13d
xorl %r15d, %r15d
leaq 0x10(%rsp), %r12
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 0x5f89b
callq 0xeebeb
jmp 0x5f8a0
callq 0xeed83
movl %eax, -0xc(%rbp,%r13)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
movq %rax, (%rbp,%r13)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
movq %rax, -0x8(%rbp,%r13)
cmpl $0x0, -0xc(%rbp,%r13)
je 0x5f8fa
movq (%rbp,%r13), %rcx
testq %rcx, %rcx
jle 0x5f903
cmpq 0x28(%r14), %rax
jl 0x5f999
addq %rax, %rcx
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %rcx
jg 0x5f999
movq %rcx, 0x28(%r14)
jmp 0x5f903
movq $0x0, (%rbp,%r13)
incq %r15
movq 0x10(%r14), %rax
addq $0x18, %r13
cmpq %rax, %r15
jl 0x5f86f
testl %eax, %eax
je 0x5f9ad
movq 0x30(%r14), %rcx
xorl %r12d, %r12d
xorl %r15d, %r15d
movl 0x4(%rcx,%r12), %edx
cmpl $0x10, %edx
je 0x5f938
cmpl $0x9, %edx
jne 0x5f953
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x5fa41
movq 0x30(%r14), %rcx
movb $0x1, (%rcx,%r12)
movl 0x10(%r14), %eax
incq %r15
movl %eax, %edx
addq $0x18, %r12
cmpq %rdx, %r15
jb 0x5f929
testq %rdx, %rdx
je 0x5f9ad
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x30(%r14), %rcx
cmpb $0x0, (%rcx,%r12)
jne 0x5f989
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x5fa41
movl 0x10(%r14), %eax
incq %r15
movl %eax, %ecx
addq $0x18, %r12
cmpq %rcx, %r15
jb 0x5f96c
jmp 0x5f9ad
leaq 0xc39b2(%rip), %rsi     # 0x123352
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9295
movq 0x30(%r14), %rsi
movq %rbx, %rdi
callq 0xe8be2
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq