// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl $0x440, %esi            # imm = 0x440
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x9, %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl $0xd, 0xc(%rax)
movq -0x8(%rbp), %rdi
leaq 0x125ff3(%rip), %rsi    # 0x1aece6
callq 0x15cb30
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x88d17
movq -0x8(%rbp), %rdi
leaq 0x125fdc(%rip), %rsi    # 0x1aecea
callq 0x15cb30
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x88d47
movq -0x20(%rbp), %rdi
callq 0x161de0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x88d45
movq -0x18(%rbp), %rax
movl $0xd, 0xc(%rax)
jmp 0x88d47
movq -0x8(%rbp), %rdi
leaq 0x125f9f(%rip), %rsi    # 0x1aecf1
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x15cbc0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jg 0x88d78
movq -0x8(%rbp), %rax
cmpl $0x2, 0x90(%rax)
jl 0x88d80
cmpl $0x0, -0x24(%rbp)
je 0x88d80
movq -0x18(%rbp), %rax
movb $0x1, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %edx
leaq 0x11faa1(%rip), %rsi    # 0x1a884b
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpl $0xc350, (%rax)         # imm = 0xC350
jb 0x88dc9
movq -0x18(%rbp), %rax
cmpl $0xc352, (%rax)         # imm = 0xC352
jbe 0x88de0
movq -0x8(%rbp), %rdi
leaq 0x125f2c(%rip), %rsi    # 0x1aed00
movb $0x0, %al
callq 0x15bfb0
jmp 0x88e69
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %edx
leaq 0x125f06(%rip), %rsi    # 0x1aed17
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %edx
movl $0xac, %eax
movl $0x59, %ecx
cmpl $0xc350, %edx           # imm = 0xC350
cmovel %ecx, %eax
movslq %eax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x88f50
cmpl $0x0, %eax
jne 0x88e5c
jmp 0x88e69
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x89110
cmpq $0x0, -0x18(%rbp)
je 0x88e8e
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)