// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/clp.c
// Function: do_item
static void do_item(deark *c, lctx *d, UI idx)
{
	struct index_item *ii;
	struct member_data *md = NULL;
	i64 pos;
	int old_extract_count;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	md = de_malloc(c, sizeof(struct member_data));
	md->idx = idx;
	md->fi = de_finfo_create(c);
	md->name = ucstring_create(c);
	md->hpos = d->index_pos + (i64)md->idx * d->index_item_len;
	ii = &d->index_array[md->idx];
	pos = md->hpos;

	de_dbg(c, "item #%u, header at %"I64_FMT, md->idx, md->hpos);
	de_dbg_indent(c, 1);
	if(d->sig==0xc350) {
		pos += 2; // clipfmt, already read
	}
	else {
		pos += 4;
	}
	md->clpfmtname_known = get_cf_name(c, d, ii->clpfmt, md->clpfmtname_sz, sizeof(md->clpfmtname_sz));
	de_dbg(c, "format: 0x%04x (%s)", ii->clpfmt, md->clpfmtname_sz);
	if(ii->clpfmt==0) goto done;
	pos += 4; // dlen, already read
	pos += 4; // dpos, already read
	de_dbg(c, "data at %"I64_FMT", len=%"I64_FMT, ii->dpos, ii->dlen);

	if(d->sig==0xc350) {
		dbuf_read_to_ucstring(c->infile, pos, 79, md->name, DE_CONVFLAG_STOP_AT_NUL,
			d->input_encoding_ansi);
	}
	else {
		dbuf_read_to_ucstring(c->infile, pos, 79*2, md->name, 0, DE_ENCODING_UTF16LE);
		ucstring_truncate_at_NUL(md->name);
	}
	de_dbg(c, "name: \"%s\"", ucstring_getpsz_d(md->name));

	if(ii->dlen<1) {
		goto done;
	}

	set_output_filename(c, d, md, ii);

	// So we can figure out if we successfully extracted anything
	old_extract_count = c->num_files_extracted;

	switch(ii->clpfmt) {
	case CFMT_BITMAP: case CFMT_DSPBITMAP:
		extract_ddb(c, d, md, ii);
		break;
	case CFMT_DIB: case CFMT_DIBV5:
		extract_dib(c, d, md, ii);
		break;
	case CFMT_TEXT: case CFMT_OEMTEXT: case CFMT_UNICODETEXT: case CFMT_DSPTEXT:
		extract_text(c, d, md, ii);
		break;
	case CFMT_PALETTE:
		read_palette(c, d, md, ii);
		break;
	case CFMT_METAFILEPICT: case CFMT_DSPMETAFILEPICT:
		extract_wmf(c, d, md, ii);
		break;
	}

	if(c->num_files_extracted==old_extract_count) {
		if(d->extractall) {
			extract_binary(c, d, md, ii);
		}
		else if(c->debug_level>=2) {
			de_dbg_hexdump(c, c->infile, ii->dpos, ii->dlen, 256, NULL, 0x1);
		}
	}

done:
	destroy_md(c, md);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x2c(%rsp), %rsi
callq 0xe958c
movl $0x48, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
movl %ebp, (%rax)
movq %rbx, %rdi
callq 0xea9a9
movq %rax, 0x10(%r14)
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x18(%r14)
movl (%r14), %edx
movq %rdx, %r13
imulq 0x20(%r12), %r13
addq 0x18(%r12), %r13
leaq (%rdx,%rdx,2), %rax
movq %r13, 0x8(%r14)
movq 0x30(%r12), %rcx
leaq (%rcx,%rax,8), %r15
leaq 0xc3587(%rip), %rsi     # 0x123195
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
xorl %ebp, %ebp
movq %r12, 0x10(%rsp)
cmpl $0xc350, (%r12)         # imm = 0xC350
setne 0xc(%rsp)
movq %r15, 0x20(%rsp)
movl 0x4(%r15), %eax
movq %r14, %r12
addq $0x21, %r12
leal -0x12(%rax), %ecx
cmpl $-0x11, %ecx
jae 0x5fc6c
leaq 0xcc20e(%rip), %rsi     # 0x12be69
movl $0x20, %edx
movq %r12, %rdi
callq 0xe8ded
xorl %eax, %eax
jmp 0x5fc8f
leaq 0x121e7d(%rip), %rcx    # 0x181af0
movq (%rcx,%rax,8), %rcx
leaq 0xc3561(%rip), %rdx     # 0x1231df
movl $0x20, %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0xe8d67
movb $0x1, %al
movb %al, 0x20(%r14)
movq 0x20(%rsp), %r15
movl 0x4(%r15), %edx
leaq 0xc350a(%rip), %rsi     # 0x1231ad
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0xe9226
cmpl $0x0, 0x4(%r15)
je 0x6020d
movb 0xc(%rsp), %al
movb %al, %bpl
leaq 0x2(,%rbp,2), %rax
addq %rax, %r13
addq $0x8, %r13
movq 0x8(%r15), %rdx
movq 0x10(%r15), %rcx
leaq 0xbbc0f(%rip), %rsi     # 0x11b8ef
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x10(%rsp), %rax
cmpl $0xc350, (%rax)         # imm = 0xC350
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rcx
jne 0x5fd18
movl 0x8(%rax), %r9d
movl $0x4f, %edx
movq %r13, %rsi
movl $0x1, %r8d
callq 0xf01b0
jmp 0x5fd37
movl $0x9e, %edx
movq %r13, %rsi
xorl %r8d, %r8d
movl $0x3, %r9d
callq 0xf01b0
movq 0x18(%r14), %rdi
callq 0xf68c1
movq 0x18(%r14), %rdi
callq 0xf7557
leaq 0xc282c(%rip), %rsi     # 0x122573
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpq $0x0, 0x10(%r15)
jle 0x6020d
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r13
cmpb $0x0, 0xd0(%rbx)
je 0x5fdb0
movq 0x18(%r14), %rcx
cmpq $0x0, 0x10(%rcx)
jle 0x5fdb0
xorl %eax, %eax
xorl %r15d, %r15d
movq 0x8(%rcx), %rcx
movl (%rcx,%r15,4), %esi
testl %eax, %eax
jne 0x5fd99
movl $0x1, %eax
cmpl $0x26, %esi
je 0x5fda3
movq %r13, %rdi
callq 0xf69a2
xorl %eax, %eax
incq %r15
movq 0x18(%r14), %rcx
cmpq 0x10(%rcx), %r15
jl 0x5fd83
movl $0x80, %eax
movq 0x20(%rsp), %r15
orl 0x4(%r15), %eax
cmpl $0x82, %eax
jne 0x5fdf2
movq %r13, %rdi
callq 0xf6c00
testl %eax, %eax
je 0x5fdde
movq %r13, %rdi
movl $0x2e, %esi
callq 0xf69a2
leaq 0xc3408(%rip), %rsi     # 0x1231ed
movq %r13, %rdi
movl $0x5, %edx
callq 0xf6a40
movq %r13, %rdi
callq 0xf6bea
testl %eax, %eax
je 0x5fe15
cmpb $0x0, 0x20(%r14)
je 0x5fe15
movq %r13, %rdi
movq %r12, %rsi
movl $0x2, %edx
callq 0xf6a40
movq %r13, %rdi
callq 0xf6c00
testl %eax, %eax
je 0x5fe32
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xea9e4
movq %r13, %rdi
callq 0xf6bb0
movl 0x3c(%rbx), %ebp
movl 0x4(%r15), %eax
cmpl $0x80, %eax
jg 0x5feda
leal -0x1(%rax), %ecx
cmpl $0x10, %ecx
ja 0x601a4
leaq 0xc3269(%rip), %rdx     # 0x1230c8
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r12
leaq 0xc33a8(%rip), %rsi     # 0x123227
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x10(%r14), %rax
movq %rax, 0x28(%r12)
movq 0x18(%rbx), %rcx
movq 0x8(%r15), %r8
movq 0x10(%r15), %r9
leaq 0xc337d(%rip), %rsi     # 0x12322f
movq %rbx, %rdi
movq %r12, %rdx
callq 0xea5fa
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe9752
jmp 0x601a4
cmpl $0x81, %eax
je 0x5ffbf
cmpl $0x83, %eax
je 0x6000d
cmpl $0x82, %eax
jne 0x601a4
movl %ebp, %r13d
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r12
leaq 0xc32d0(%rip), %rsi     # 0x1231e5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
leaq 0xb3ee4(%rip), %rax     # 0x113e17
movq %rax, (%r12)
movq 0x10(%r14), %rax
movq %rax, 0x28(%r12)
movq 0x10(%rsp), %rax
cmpb $0x0, 0x38(%rax)
je 0x5ff54
addq $0x3c, %rax
movq %rax, 0x38(%r12)
movl 0x3c(%rbx), %ebp
movq 0x18(%rbx), %rcx
movq 0x8(%r15), %r8
movq 0x10(%r15), %r9
leaq 0xc3283(%rip), %rsi     # 0x1231ed
movq %rbx, %rdi
movq %r12, %rdx
callq 0xea5fa
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpl %ebp, 0x3c(%rbx)
jle 0x5ffac
movq 0x10(%rsp), %rax
cmpb $0x0, 0x5(%rax)
jne 0x5ffac
leaq 0xc3258(%rip), %rsi     # 0x1231f1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
movq 0x10(%rsp), %rax
movb $0x1, 0x5(%rax)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe9752
movl %r13d, %ebp
jmp 0x601a4
movq 0x10(%r15), %r13
cmpl $0xc, %eax
jg 0x5ffe1
cmpl $0x1, %eax
je 0x5fff5
cmpl $0x7, %eax
jne 0x601a4
movq 0x10(%rsp), %rcx
movzbl 0xc(%rcx), %ecx
jmp 0x5fffe
cmpl $0xd, %eax
je 0x600d6
cmpl $0x81, %eax
jne 0x601a4
movq 0x10(%rsp), %rcx
movzbl 0x8(%rcx), %ecx
orl $0x300, %ecx            # imm = 0x300
movl %ecx, 0x1c(%rsp)
jmp 0x600de
movq 0x10(%r15), %rdx
cmpq $0x9, %rdx
jl 0x601a4
movq 0x18(%rbx), %rdi
movq 0x8(%r15), %rsi
addq $0x8, %rsi
addq $-0x8, %rdx
movq 0x10(%r14), %r8
leaq 0xbc431(%rip), %rcx     # 0x11c467
xorl %r9d, %r9d
callq 0xf0321
jmp 0x601a4
movq 0x10(%rsp), %rax
cmpb $0x0, 0x38(%rax)
jne 0x601a4
movq 0x8(%r15), %r12
movq 0x10(%r15), %r13
addq $0x4, %r12
leaq -0x4(%r13), %r15
leaq 0xc31ca(%rip), %rsi     # 0x123233
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl %ebp, 0xc(%rsp)
movq 0x10(%rsp), %rbp
movb $0x1, 0x38(%rbp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
decq %r13
testq %r15, %r15
cmovnsq %r15, %r13
sarq $0x2, %r13
leaq 0x3c(%rbp), %r8
movl 0xc(%rsp), %ebp
movl $0x0, (%rsp)
movl $0x4, %ecx
movl $0x100, %r9d            # imm = 0x100
movq %r12, %rsi
movq %r13, %rdx
callq 0xf328f
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
jmp 0x601a4
movl $0x3, 0x1c(%rsp)
cmpl $0xd, %eax
movl %ebp, 0xc(%rsp)
jne 0x60117
leaq 0x30(%rsp), %r12
movq $0x0, (%r12)
movq 0x18(%rbx), %rdi
movq 0x8(%r15), %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0xf1c0a
movq (%r12), %rcx
addq $-0x2, %rcx
testl %eax, %eax
cmovneq %rcx, %r13
jmp 0x60142
leaq 0x30(%rsp), %r8
movq $0x0, (%r8)
movq 0x18(%rbx), %rdi
movq 0x8(%r15), %rdx
xorl %esi, %esi
movq %r13, %rcx
callq 0xf0057
testl %eax, %eax
je 0x60142
movq 0x30(%rsp), %r13
subq 0x8(%r15), %r13
movq %r13, %rbp
movq 0x18(%rbx), %r13
movq 0x8(%r15), %r15
movq 0x10(%r14), %rdx
movq 0x8(%r13), %rdi
leaq 0xc9ee4(%rip), %rsi     # 0x12a040
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r12
movq 0x8(%r13), %rax
cmpb $0x0, 0xcc(%rax)
je 0x60180
movq %r12, %rdi
movl $0xfeff, %esi           # imm = 0xFEFF
callq 0xec81c
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl 0x1c(%rsp), %ecx
movq %r12, %r8
xorl %r9d, %r9d
callq 0xf1f28
movq %r12, %rdi
callq 0xf0b13
movl 0xc(%rsp), %ebp
cmpl %ebp, 0x3c(%rbx)
jne 0x6020d
movq 0x10(%rsp), %rax
cmpb $0x0, 0x4(%rax)
je 0x601df
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdx
testq %rdx, %rdx
jle 0x6020d
movq 0x18(%rbx), %rdi
movq 0x8(%rax), %rsi
movq 0x10(%r14), %r8
leaq 0xd525c(%rip), %rcx     # 0x135431
xorl %r9d, %r9d
callq 0xf0321
jmp 0x6020d
cmpl $0x2, (%rbx)
movq 0x20(%rsp), %rax
jl 0x6020d
movq 0x18(%rbx), %rsi
movq 0x8(%rax), %rdx
movq 0x10(%rax), %rcx
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
xorl %r9d, %r9d
callq 0xe975a
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xea9b3
movq 0x18(%r14), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movl 0x2c(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq