// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movl $0x48, %esi
callq 0x15b780
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rdx
imulq 0x20(%rdx), %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl (%rax), %edx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
leaq 0x125a9e(%rip), %rsi    # 0x1aed59
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
cmpl $0xc350, (%rax)         # imm = 0xC350
jne 0x892ea
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
jmp 0x892f6
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x28(%rbp), %rcx
addq $0x21, %rcx
movl $0x20, %r8d
callq 0x895e0
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x28(%rbp), %rcx
addq $0x21, %rcx
leaq 0x125a36(%rip), %rsi    # 0x1aed71
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x89351
jmp 0x895b5
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0x11e2e8(%rip), %rsi    # 0x1a766c
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0xc350, (%rax)         # imm = 0xC350
jne 0x893c5
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %r9d
movl $0x4f, %edx
movl $0x1, %r8d
callq 0x1669f0
jmp 0x893f9
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rcx
movl $0x9e, %edx
xorl %r8d, %r8d
movl $0x3, %r9d
callq 0x1669f0
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x1712b0
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0x40(%rbp), %rdi
movq %rax, %rdx
leaq 0x124db4(%rip), %rsi    # 0x1ae1d0
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
cmpq $0x1, 0x10(%rax)
jge 0x89433
jmp 0x895b5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x89670
movq -0x8(%rbp), %rax
movl 0x3c(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x44(%rbp)
subl $0x1, %eax
je 0x89503
jmp 0x89467
movl -0x44(%rbp), %eax
subl $0x2, %eax
je 0x894d5
jmp 0x89471
movl -0x44(%rbp), %eax
subl $0x3, %eax
je 0x89531
jmp 0x8947f
movl -0x44(%rbp), %eax
subl $0x7, %eax
je 0x89503
jmp 0x89489
movl -0x44(%rbp), %eax
subl $0x8, %eax
je 0x894ec
jmp 0x89493
movl -0x44(%rbp), %eax
subl $0x9, %eax
je 0x8951a
jmp 0x8949d
movl -0x44(%rbp), %eax
subl $0xd, %eax
je 0x89503
jmp 0x894a7
movl -0x44(%rbp), %eax
subl $0x11, %eax
je 0x894ec
jmp 0x894b1
movl -0x44(%rbp), %eax
subl $0x81, %eax
je 0x89503
jmp 0x894bd
movl -0x44(%rbp), %eax
subl $0x82, %eax
je 0x894d5
jmp 0x894c9
movl -0x44(%rbp), %eax
subl $0x83, %eax
je 0x89531
jmp 0x89546
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x897e0
jmp 0x89546
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x89900
jmp 0x89546
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x899b0
jmp 0x89546
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x89b00
jmp 0x89546
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x89bd0
movq -0x8(%rbp), %rax
movl 0x3c(%rax), %eax
cmpl -0x34(%rbp), %eax
jne 0x895b3
movq -0x10(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0x89573
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x89c40
jmp 0x895b1
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x895af
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, (%rsp)
callq 0x15b840
jmp 0x895b1
jmp 0x895b3
jmp 0x895b5
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x89ca0
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x15b5a0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)