// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x3c(%rsp), %rsi
callq 0xdebae
pushq $0x48
popq %rsi
movq %r15, %rdi
callq 0xdecaf
movq %rax, %r12
movl %ebp, (%rax)
movq %r15, %rdi
callq 0xdfd1a
movq %rax, 0x10(%r12)
movq %r15, %rdi
callq 0xeac74
movq %rax, 0x18(%r12)
movl (%r12), %edx
movq %rdx, %r13
imulq 0x20(%rbx), %r13
addq 0x18(%rbx), %r13
imulq $0x18, %rdx, %r14
movq %r13, 0x8(%r12)
movq 0x30(%rbx), %rbp
leaq (%r14,%rbp), %rax
movq %rax, 0x28(%rsp)
leaq 0xb9a65(%rip), %rsi     # 0x1161b5
movq %r15, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %r15, 0x20(%rsp)
movq %r15, %rdi
callq 0xdeba7
movq %rbx, 0x10(%rsp)
cmpl $0xc350, (%rbx)         # imm = 0xC350
setne %dl
movl 0x4(%rbp,%r14), %eax
movq %r12, 0x30(%rsp)
addq $0x21, %r12
leal -0x12(%rax), %ecx
movl %edx, %r14d
cmpl $-0x11, %ecx
jae 0x5c7aa
leaq 0xc2746(%rip), %rsi     # 0x11eee1
pushq $0x20
popq %rdx
movq %r12, %rdi
callq 0xde492
xorl %eax, %eax
jmp 0x5c7cb
leaq 0x1283ef(%rip), %rcx    # 0x184ba0
movq (%rcx,%rax,8), %rcx
leaq 0xb9a43(%rip), %rdx     # 0x1161ff
pushq $0x20
popq %rsi
movq %r12, %rdi
xorl %eax, %eax
callq 0xde40c
movb $0x1, %al
movq 0x30(%rsp), %rbx
movb %al, 0x20(%rbx)
movq 0x28(%rsp), %r15
movl 0x4(%r15), %edx
leaq 0xb99ea(%rip), %rsi     # 0x1161cd
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0xde896
cmpl $0x0, 0x4(%r15)
je 0x5cd27
xorl %eax, %eax
movb %r14b, %al
leaq 0x2(,%rax,2), %rax
addq %rax, %r13
addq $0x8, %r13
movq 0x8(%r15), %rdx
movq 0x10(%r15), %rcx
leaq 0xb2104(%rip), %rsi     # 0x10e927
movq %rbp, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x10(%rsp), %rax
cmpl $0xc350, (%rax)         # imm = 0xC350
movq 0x18(%rbp), %rdi
movq 0x18(%rbx), %rcx
jne 0x5c857
movl 0x8(%rax), %r9d
pushq $0x4f
popq %rdx
pushq $0x1
popq %r8
movq %r13, %rsi
callq 0xe4c9a
jmp 0x5c874
pushq $0x3
popq %r9
movl $0x9e, %edx
movq %r13, %rsi
xorl %r8d, %r8d
callq 0xe4c9a
movq 0x18(%rbx), %rdi
callq 0xeacc0
movq 0x18(%rbx), %rdi
callq 0xeb877
leaq 0xb8d37(%rip), %rsi     # 0x1155bb
movq %rbp, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
cmpq $0x0, 0x10(%r15)
jle 0x5cd27
movq %rbp, %rdi
callq 0xeac74
movq %rax, %r13
cmpb $0x0, 0xd0(%rbp)
je 0x5c8e2
xorl %r15d, %r15d
xorl %eax, %eax
movq 0x18(%rbx), %rcx
cmpq 0x10(%rcx), %r15
jge 0x5c8e2
movq 0x8(%rcx), %rcx
movl (%rcx,%r15,4), %esi
testl %eax, %eax
jne 0x5c8d3
pushq $0x1
popq %rax
cmpl $0x26, %esi
je 0x5c8dd
movq %r13, %rdi
callq 0xeada5
xorl %eax, %eax
incq %r15
jmp 0x5c8b5
movl $0x80, %eax
movq 0x28(%rsp), %r15
orl 0x4(%r15), %eax
cmpl $0x82, %eax
jne 0x5c920
movq %r13, %rdi
callq 0xeaf8a
testl %eax, %eax
je 0x5c90e
pushq $0x2e
popq %rsi
movq %r13, %rdi
callq 0xeada5
leaq 0xb98f8(%rip), %rsi     # 0x11620d
pushq $0x5
popq %rdx
movq %r13, %rdi
callq 0xeae42
movq %r13, %rdi
callq 0xeaf76
testl %eax, %eax
je 0x5c940
cmpb $0x0, 0x20(%rbx)
je 0x5c940
pushq $0x2
popq %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0xeae42
movq %r13, %rdi
callq 0xeaf8a
testl %eax, %eax
je 0x5c95d
movq 0x10(%rbx), %rsi
movq %rbp, %rdi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xdfd55
movq %r13, %rdi
callq 0xeaf3c
movl 0x3c(%rbp), %r13d
movl 0x4(%r15), %eax
leal -0x1(%rax), %ecx
cmpl $0x10, %ecx
ja 0x5c9e6
leaq 0xb976c(%rip), %rdx     # 0x1160e8
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
pushq $0x70
popq %rsi
movq %rbp, %rdi
callq 0xdecaf
movq %rax, %r12
leaq 0xb98ad(%rip), %rsi     # 0x116247
movq %rbp, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbp, %rdi
callq 0xdeba7
movq 0x10(%rbx), %rax
movq %rax, 0x28(%r12)
movq 0x18(%rbp), %rcx
movq 0x8(%r15), %r8
movq 0x10(%r15), %r9
leaq 0xb9884(%rip), %rsi     # 0x11624f
movq %rbp, %rdi
movq %r12, %rdx
callq 0xdf9b8
pushq $-0x1
popq %rsi
movq %rbp, %rdi
callq 0xdeba7
jmp 0x5cac7
cmpl $0x81, %eax
je 0x5cad7
cmpl $0x83, %eax
je 0x5cb0c
cmpl $0x82, %eax
jne 0x5ccb2
pushq $0x70
popq %rsi
movq %rbp, %rdi
callq 0xdecaf
movq %rax, %r12
leaq 0xb97e9(%rip), %rsi     # 0x116205
movq %rbp, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbp, %rdi
callq 0xdeba7
leaq 0xaa42f(%rip), %rax     # 0x106e67
movq %rax, (%r12)
movq 0x10(%rbx), %rax
movq %rax, 0x28(%r12)
movq 0x10(%rsp), %rax
cmpb $0x0, 0x38(%rax)
je 0x5ca59
addq $0x3c, %rax
movq %rax, 0x38(%r12)
movq 0x20(%rsp), %rax
movl 0x3c(%rax), %ebp
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x8(%r15), %r8
movq 0x10(%r15), %r9
leaq 0xb9794(%rip), %rsi     # 0x11620d
movq 0x20(%rsp), %rdi
movq %r12, %rdx
callq 0xdf9b8
pushq $-0x1
popq %rsi
movq 0x20(%rsp), %rdi
callq 0xdeba7
movq 0x20(%rsp), %rax
cmpl %ebp, 0x3c(%rax)
movq 0x20(%rsp), %rbp
movq 0x10(%rsp), %rax
jle 0x5cac7
cmpb $0x0, 0x5(%rax)
jne 0x5cac7
leaq 0xb975d(%rip), %rsi     # 0x116211
movq %rbp, %rdi
xorl %eax, %eax
callq 0xdf05a
movq 0x10(%rsp), %rax
movb $0x1, 0x5(%rax)
movq %rbp, %rdi
movq %r12, %rsi
callq 0xded32
jmp 0x5ccb2
movq 0x10(%r15), %r12
cmpl $0x1, %eax
je 0x5cb42
cmpl $0x81, %eax
je 0x5cb42
cmpl $0xd, %eax
je 0x5cc18
cmpl $0x7, %eax
jne 0x5ccb2
movq 0x10(%rsp), %rax
movzbl 0xc(%rax), %r14d
orl $0x300, %r14d           # imm = 0x300
jmp 0x5cb5c
movq 0x10(%r15), %rdx
cmpq $0x9, %rdx
jl 0x5ccb2
movq 0x18(%rbp), %rdi
movq 0x8(%r15), %rsi
addq $0x8, %rsi
addq $-0x8, %rdx
movq 0x10(%rbx), %r8
leaq 0xb2952(%rip), %rcx     # 0x10f487
xorl %r9d, %r9d
callq 0xe4e0b
jmp 0x5ccb2
movq 0x10(%rsp), %rcx
movzbl 0x8(%rcx), %r14d
orl $0x300, %r14d           # imm = 0x300
cmpl $0xd, %eax
je 0x5cc1c
movl %r13d, 0x1c(%rsp)
leaq 0x40(%rsp), %r8
andq $0x0, (%r8)
movq 0x18(%rbp), %rdi
movq 0x8(%r15), %rdx
xorl %esi, %esi
movq %r12, %rcx
callq 0xe4b21
testl %eax, %eax
je 0x5cb89
movq 0x40(%rsp), %r12
subq 0x8(%r15), %r12
movq %r12, %r13
jmp 0x5cc4c
movq 0x10(%rsp), %rax
cmpb $0x0, 0x38(%rax)
jne 0x5ccb2
movq 0x8(%r15), %r12
movl %r13d, 0x1c(%rsp)
movq 0x10(%r15), %r13
addq $0x4, %r12
addq $-0x4, %r13
leaq 0xb9697(%rip), %rsi     # 0x116253
movq %rbp, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x10(%rsp), %r14
movb $0x1, 0x38(%r14)
pushq $0x1
popq %rsi
movq %rbp, %rdi
callq 0xdeba7
movq 0x18(%rbp), %rdi
pushq $0x4
popq %rcx
movq %r13, %rax
movl 0x1c(%rsp), %r13d
cqto
idivq %rcx
leaq 0x3c(%r14), %r8
andl $0x0, (%rsp)
movl $0x100, %r9d            # imm = 0x100
movq %r12, %rsi
movq %rax, %rdx
callq 0xe7963
pushq $-0x1
popq %rsi
movq %rbp, %rdi
callq 0xdeba7
jmp 0x5ccb2
pushq $0x3
popq %r14
movl %r13d, 0x1c(%rsp)
leaq 0x40(%rsp), %r13
andq $0x0, (%r13)
movq 0x18(%rbp), %rdi
movq 0x8(%r15), %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0xe642e
movq (%r13), %r13
addq $-0x2, %r13
testl %eax, %eax
cmoveq %r12, %r13
movq 0x18(%rbp), %r12
movq 0x8(%r15), %r15
movq 0x10(%rbx), %rdx
movq 0x8(%r12), %rdi
leaq 0xc03fc(%rip), %rsi     # 0x11d060
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %rbp
movq 0x8(%r12), %rax
cmpb $0x0, 0xcc(%rax)
je 0x5cc89
movq %rbp, %rdi
movl $0xfeff, %esi           # imm = 0xFEFF
callq 0xe1790
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
movl %r14d, %ecx
movq %rbp, %r8
xorl %r9d, %r9d
callq 0xe66ec
movq %rbp, %rdi
callq 0xe5591
movq 0x20(%rsp), %rbp
movl 0x1c(%rsp), %r13d
cmpl %r13d, 0x3c(%rbp)
jne 0x5cd27
movq 0x10(%rsp), %rax
cmpb $0x0, 0x4(%rax)
je 0x5ccf3
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdx
testq %rdx, %rdx
movq 0x30(%rsp), %rbx
jle 0x5cd27
movq 0x18(%rbp), %rdi
movq 0x8(%rax), %rsi
movq 0x10(%rbx), %r8
leaq 0xcb7f4(%rip), %rcx     # 0x1284dd
xorl %r9d, %r9d
callq 0xe4e0b
jmp 0x5cd27
cmpl $0x2, (%rbp)
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rbx
jl 0x5cd27
movq 0x18(%rbp), %rsi
movq 0x8(%rax), %rdx
movq 0x10(%rax), %rcx
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %rbp, %rdi
xorl %r9d, %r9d
callq 0xded3a
movq 0x10(%rbx), %rsi
movq %rbp, %rdi
callq 0xdfd24
movq 0x18(%rbx), %rdi
callq 0xeaf3c
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xded32
movl 0x3c(%rsp), %esi
movq %rbp, %rdi
callq 0xdebb7
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop