// File: /workspace/github_c_makefile_star2_O3/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 0xe8a1c
movl $0x48, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r14
movl %ebp, (%rax)
movq %rbx, %rdi
callq 0xea504
movq %rax, 0x10(%r14)
movq %rbx, %rdi
callq 0xf6410
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 0xc38c1(%rip), %rsi     # 0x123375
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
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 0x5fb12
leaq 0xcc650(%rip), %rsi     # 0x12c151
movl $0x20, %edx
movq %r12, %rdi
callq 0xe8219
xorl %eax, %eax
jmp 0x5fb35
leaq 0x122077(%rip), %rcx    # 0x181b90
movq (%rcx,%rax,8), %rcx
leaq 0xc389b(%rip), %rdx     # 0x1233bf
movl $0x20, %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0xe8193
movb $0x1, %al
movb %al, 0x20(%r14)
movq 0x20(%rsp), %r15
movl 0x4(%r15), %edx
leaq 0xc3844(%rip), %rsi     # 0x12338d
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0xe8617
cmpl $0x0, 0x4(%r15)
je 0x600c4
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 0xbbe91(%rip), %rsi     # 0x11ba17
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x10(%rsp), %rax
cmpl $0xc350, (%rax)         # imm = 0xC350
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rcx
jne 0x5fbbe
movl 0x8(%rax), %r9d
movl $0x4f, %edx
movq %r13, %rsi
movl $0x1, %r8d
callq 0xefbd7
jmp 0x5fbdd
movl $0x9e, %edx
movq %r13, %rsi
xorl %r8d, %r8d
movl $0x3, %r9d
callq 0xefbd7
movq 0x18(%r14), %rdi
callq 0xf6461
movq 0x18(%r14), %rdi
callq 0xf70f6
leaq 0xc2b8e(%rip), %rsi     # 0x12277b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
cmpq $0x0, 0x10(%r15)
jle 0x600c4
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r13
cmpb $0x0, 0xd0(%rbx)
je 0x5fc56
movq 0x18(%r14), %rax
cmpq $0x0, 0x10(%rax)
jle 0x5fc56
xorl %ecx, %ecx
xorl %r15d, %r15d
movq 0x8(%rax), %rdx
movl (%rdx,%r15,4), %esi
testl %ecx, %ecx
jne 0x5fc3f
movl $0x1, %ecx
cmpl $0x26, %esi
je 0x5fc4d
movq %r13, %rdi
callq 0xf6542
movq 0x18(%r14), %rax
xorl %ecx, %ecx
incq %r15
cmpq 0x10(%rax), %r15
jl 0x5fc29
movl $0x80, %eax
movq 0x20(%rsp), %r15
orl 0x4(%r15), %eax
cmpl $0x82, %eax
jne 0x5fc98
movq %r13, %rdi
callq 0xf67a3
testl %eax, %eax
je 0x5fc84
movq %r13, %rdi
movl $0x2e, %esi
callq 0xf6542
leaq 0xc3742(%rip), %rsi     # 0x1233cd
movq %r13, %rdi
movl $0x5, %edx
callq 0xf65e3
movq %r13, %rdi
callq 0xf678d
testl %eax, %eax
je 0x5fcbb
cmpb $0x0, 0x20(%r14)
je 0x5fcbb
movq %r13, %rdi
movq %r12, %rsi
movl $0x2, %edx
callq 0xf65e3
movq %r13, %rdi
callq 0xf67a3
testl %eax, %eax
je 0x5fcd8
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xea53f
movq %r13, %rdi
callq 0xf6753
movl 0x3c(%rbx), %ebp
movl 0x4(%r15), %eax
cmpl $0x80, %eax
jg 0x5fd80
leal -0x1(%rax), %ecx
cmpl $0x10, %ecx
ja 0x6005b
leaq 0xc35a3(%rip), %rdx     # 0x1232a8
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r12
leaq 0xc36e2(%rip), %rsi     # 0x123407
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x10(%r14), %rax
movq %rax, 0x28(%r12)
movq 0x18(%rbx), %rcx
movq 0x8(%r15), %r8
movq 0x10(%r15), %r9
leaq 0xc36b7(%rip), %rsi     # 0x12340f
movq %rbx, %rdi
movq %r12, %rdx
callq 0xe9aa3
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe8be2
jmp 0x6005b
cmpl $0x81, %eax
je 0x5fe65
cmpl $0x83, %eax
je 0x5fef7
cmpl $0x82, %eax
jne 0x6005b
movl %ebp, %r13d
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r12
leaq 0xc360a(%rip), %rsi     # 0x1233c5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
leaq 0xb40ee(%rip), %rax     # 0x113ec7
movq %rax, (%r12)
movq 0x10(%r14), %rax
movq %rax, 0x28(%r12)
movq 0x10(%rsp), %rax
cmpb $0x0, 0x38(%rax)
je 0x5fdfa
addq $0x3c, %rax
movq %rax, 0x38(%r12)
movl 0x3c(%rbx), %ebp
movq 0x18(%rbx), %rcx
movq 0x8(%r15), %r8
movq 0x10(%r15), %r9
leaq 0xc35bd(%rip), %rsi     # 0x1233cd
movq %rbx, %rdi
movq %r12, %rdx
callq 0xe9aa3
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
cmpl %ebp, 0x3c(%rbx)
jle 0x5fe52
movq 0x10(%rsp), %rax
cmpb $0x0, 0x5(%rax)
jne 0x5fe52
leaq 0xc3592(%rip), %rsi     # 0x1233d1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
movq 0x10(%rsp), %rax
movb $0x1, 0x5(%rax)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe8be2
movl %r13d, %ebp
jmp 0x6005b
movq 0x10(%r15), %r12
cmpl $0xc, %eax
jg 0x5fe90
cmpl $0x1, %eax
je 0x5fea4
cmpl $0x7, %eax
jne 0x6005b
movq 0x10(%rsp), %rax
movzbl 0xc(%rax), %eax
orl $0x300, %eax            # imm = 0x300
movl %eax, 0x1c(%rsp)
jmp 0x5fec0
cmpl $0xd, %eax
je 0x5ffc0
cmpl $0x81, %eax
jne 0x6005b
movq 0x10(%rsp), %rcx
movzbl 0x8(%rcx), %ecx
orl $0x300, %ecx            # imm = 0x300
movl %ecx, 0x1c(%rsp)
cmpl $0xd, %eax
je 0x5ffc8
movl %ebp, 0xc(%rsp)
leaq 0x30(%rsp), %r8
movq $0x0, (%r8)
movq 0x18(%rbx), %rdi
movq 0x8(%r15), %rdx
xorl %esi, %esi
movq %r12, %rcx
callq 0xefa77
testl %eax, %eax
je 0x5feef
movq 0x30(%rsp), %r12
subq 0x8(%r15), %r12
movq %r12, %rbp
jmp 0x5fffa
movq 0x10(%r15), %rdx
cmpq $0x9, %rdx
jl 0x6005b
movq 0x18(%rbx), %rdi
movq 0x8(%r15), %rsi
addq $0x8, %rsi
addq $-0x8, %rdx
movq 0x10(%r14), %r8
leaq 0xbc657(%rip), %rcx     # 0x11c577
xorl %r9d, %r9d
callq 0xefd48
jmp 0x6005b
movq 0x10(%rsp), %rax
cmpb $0x0, 0x38(%rax)
jne 0x6005b
movq 0x8(%r15), %r12
movq 0x10(%r15), %r13
addq $0x4, %r12
leaq -0x4(%r13), %r15
leaq 0xc34c0(%rip), %rsi     # 0x123413
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl %ebp, 0xc(%rsp)
movq 0x10(%rsp), %rbp
movb $0x1, 0x38(%rbp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
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 0xf2c4e
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
jmp 0x6005b
movl $0x3, 0x1c(%rsp)
movl %ebp, 0xc(%rsp)
leaq 0x30(%rsp), %r13
movq $0x0, (%r13)
movq 0x18(%rbx), %rdi
movq 0x8(%r15), %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0xf1607
movq (%r13), %rbp
addq $-0x2, %rbp
testl %eax, %eax
cmoveq %r12, %rbp
movq 0x18(%rbx), %r12
movq 0x8(%r15), %r15
movq 0x10(%r14), %rdx
movq 0x8(%r12), %rdi
leaq 0xca29e(%rip), %rsi     # 0x12a2b0
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r13
movq 0x8(%r12), %rax
cmpb $0x0, 0xcc(%rax)
je 0x60037
movq %r13, %rdi
movl $0xfeff, %esi           # imm = 0xFEFF
callq 0xec1c4
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl 0x1c(%rsp), %ecx
movq %r13, %r8
xorl %r9d, %r9d
callq 0xf1883
movq %r13, %rdi
callq 0xf052b
movl 0xc(%rsp), %ebp
cmpl %ebp, 0x3c(%rbx)
jne 0x600c4
movq 0x10(%rsp), %rax
cmpb $0x0, 0x4(%rax)
je 0x60096
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdx
testq %rdx, %rdx
jle 0x600c4
movq 0x18(%rbx), %rdi
movq 0x8(%rax), %rsi
movq 0x10(%r14), %r8
leaq 0xd5731(%rip), %rcx     # 0x1357bd
xorl %r9d, %r9d
callq 0xefd48
jmp 0x600c4
cmpl $0x2, (%rbx)
movq 0x20(%rsp), %rax
jl 0x600c4
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 0xe8bea
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xea50e
movq 0x18(%r14), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
movl 0x2c(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop