// File: /workspace/github_c_makefile_star2_O1/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 0xe969b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb7d1
movl %eax, 0x8(%r14)
movl $0xd, 0xc(%r14)
leaq 0xc387e(%rip), %rsi     # 0x123122
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
jne 0x5f8c0
leaq 0xc386e(%rip), %rsi     # 0x123126
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
je 0x5f8db
movq %rax, %rdi
callq 0xed185
testl %eax, %eax
movl $0xd, %ecx
cmovnel %eax, %ecx
movl %ecx, 0xc(%r14)
leaq 0xc384b(%rip), %rsi     # 0x12312d
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xea727
testl %eax, %eax
jg 0x5f8fe
je 0x5f903
cmpl $0x2, 0x90(%rbx)
jl 0x5f903
movb $0x1, 0x4(%r14)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef1ed
movl %eax, (%r14)
leaq 0xbd26f(%rip), %rsi     # 0x11cb8a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movl $0xffff3cad, %eax       # imm = 0xFFFF3CAD
addl (%r14), %eax
cmpl $-0x4, %eax
ja 0x5f94a
leaq 0xc3801(%rip), %rsi     # 0x12313c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x5fb07
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0xef1ed
movq %rax, 0x10(%r14)
leaq 0xc37ed(%rip), %rsi     # 0x123153
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
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 0xea259
movq %rax, 0x30(%r14)
leaq 0xc37b3(%rip), %rsi     # 0x123161
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
cmpq $0x0, 0x10(%r14)
jle 0x5fa74
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 0x5f9fd
callq 0xef1ed
jmp 0x5fa02
callq 0xef3a0
movl %eax, -0xc(%rbp,%r13)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef3a0
movq %rax, (%rbp,%r13)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef3a0
movq %rax, -0x8(%rbp,%r13)
cmpl $0x0, -0xc(%rbp,%r13)
jne 0x5fa3a
movq $0x0, (%rbp,%r13)
movq (%rbp,%r13), %rcx
testq %rcx, %rcx
jle 0x5fa63
cmpq 0x28(%r14), %rax
jl 0x5faf3
addq %rax, %rcx
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %rcx
jg 0x5faf3
movq %rcx, 0x28(%r14)
incq %r15
addq $0x18, %r13
cmpq 0x10(%r14), %r15
jl 0x5f9d1
cmpl $0x0, 0x10(%r14)
je 0x5fabb
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x30(%r14), %rax
movl 0x4(%rax,%r12), %eax
cmpl $0x10, %eax
je 0x5fa94
cmpl $0x9, %eax
jne 0x5faab
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x5fb9b
movq 0x30(%r14), %rax
movb $0x1, (%rax,%r12)
incq %r15
movl 0x10(%r14), %eax
addq $0x18, %r12
cmpq %rax, %r15
jb 0x5fa81
cmpl $0x0, 0x10(%r14)
je 0x5fb07
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x30(%r14), %rax
cmpb $0x0, (%rax,%r12)
jne 0x5fae1
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x5fb9b
incq %r15
movl 0x10(%r14), %eax
addq $0x18, %r12
cmpq %rax, %r15
jb 0x5fac8
jmp 0x5fb07
leaq 0xc3678(%rip), %rsi     # 0x123172
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9df7
movq 0x30(%r14), %rsi
movq %rbx, %rdi
callq 0xe9752
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq