// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/corel.c
// Function: do_clb_item
static int do_clb_item(deark *c, struct clb_ctx *d, i64 pos1)
{
	i64 pos = pos1;
	i64 nlen;
	i64 imglen;
	i64 n;
	de_ucstring *name = NULL;
	de_ucstring *tmps = NULL;
	de_finfo *fi = NULL;
	int retval = 0;
	int saved_indent_level;
	int bitmap_ok = 1;
	u8 need_errmsg = 0;
	de_module_params *mparams2 = NULL;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "item at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);

	nlen = de_getu16le_p(&pos);
	if(nlen<1 || nlen>63) {
		need_errmsg = 1;
		goto done;
	}
	name = ucstring_create(c);
	dbuf_read_to_ucstring(c->infile, pos, nlen, name, DE_CONVFLAG_STOP_AT_NUL,
		d->input_encoding);
	de_dbg(c, "name: \"%s\"", ucstring_getpsz_d(name));
	pos += nlen;

	imglen = de_getu32le_p(&pos);
	de_dbg(c, "bitmap size: %"I64_FMT, imglen);

	// Look ahead at the DDB bmBits field.
	// It seems to be used, and it seems to be an absolute file position.
	// Bail out if it's not what we expect.
	n = de_getu32le(pos+12);
	if(n!=0 && n!=pos+16) {
		de_err(c, "Unexpected value for bmBits field");
		bitmap_ok = 0;
	}

	if(bitmap_ok) {
		de_dbg(c, "bitmap at %"I64_FMT, pos);
		de_dbg_indent(c, 1);
		fi = de_finfo_create(c);
		if(c->filenames_from_file) {
			ucstring_append_char(name, '.');
		}
		else {
			ucstring_empty(name);
		}
		ucstring_append_sz(name, "preview", DE_ENCODING_LATIN1);
		de_finfo_set_name_from_ucstring(c, fi, name, 0);

		mparams2 = de_malloc(c, sizeof(de_module_params));
		// N = Image structure starts with a "file type" field.
		// C = Ignore the rightmost column and bottom row (in most cases).
		if(d->adjdim_flag) {
			mparams2->in_params.codes = "NC";
		}
		else {
			mparams2->in_params.codes = "N";
		}
		mparams2->in_params.fi = fi;
		de_run_module_by_id_on_slice(c, "ddb", mparams2, c->infile, pos+2, imglen-2);
		de_dbg_indent(c, -1);
	}

	pos += imglen;

	n = de_getu32le_p(&pos);
	if(pos+n > c->infile->len) {
		need_errmsg = 1;
		goto done;
	}
	tmps = ucstring_create(c);
	dbuf_read_to_ucstring_n(c->infile, pos, n, DE_DBG_MAX_STRLEN, tmps,
		DE_CONVFLAG_STOP_AT_NUL, d->input_encoding);
	de_dbg(c, "keywords: \"%s\"", ucstring_getpsz_d(tmps));
	pos += n;

	n = de_getu32le_p(&pos);
	// This is a reference to the original file from which this preview was derived
	// (should be in the companion .CLH file).
	de_dbg(c, "original file size: %"I64_FMT, n);

	d->bytes_consumed = pos-pos1;
	retval = 1;
done:
	if(need_errmsg) {
		de_err(c, "Failed to parse item at %"I64_FMT, pos1);
	}
	de_free(c, mparams2);
	de_finfo_destroy(c, fi);
	ucstring_destroy(name);
	ucstring_destroy(tmps);
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x1, -0x5c(%rbp)
movb $0x0, -0x5d(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x14428d(%rip), %rsi    # 0x1bc77a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x28(%rbp)
cmpq $0x1, -0x28(%rbp)
jl 0x78525
cmpq $0x3f, -0x28(%rbp)
jle 0x7852e
movb $0x1, -0x5d(%rbp)
jmp 0x787ff
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movl (%rax), %r9d
movl $0x1, %r8d
callq 0x1669f0
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rdi
callq 0x172650
movq -0x70(%rbp), %rdi
movq %rax, %rdx
leaq 0x135c50(%rip), %rsi    # 0x1ae1d0
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x133efd(%rip), %rsi    # 0x1ac4b4
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0xc, %rsi
callq 0x165540
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x78608
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
addq $0x10, %rcx
cmpq %rcx, %rax
je 0x78608
movq -0x8(%rbp), %rdi
leaq 0x133ecb(%rip), %rsi    # 0x1ac4c5
movb $0x0, %al
callq 0x15bfb0
movl $0x0, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x78711
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x1498e6(%rip), %rsi    # 0x1c1f07
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0xd0(%rax)
je 0x78660
movq -0x40(%rbp), %rdi
movl $0x2e, %esi
callq 0x1714c0
jmp 0x78669
movq -0x40(%rbp), %rdi
callq 0x171210
movq -0x40(%rbp), %rdi
leaq 0x128e91(%rip), %rsi    # 0x1a1505
movl $0x5, %edx
callq 0x1715e0
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x40(%rbp), %rdx
xorl %ecx, %ecx
callq 0x15d2c0
movq -0x8(%rbp), %rdi
movl $0x70, %esi
callq 0x15b780
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x786bd
movq -0x68(%rbp), %rax
leaq 0x133e2f(%rip), %rcx    # 0x1ac4e7
movq %rcx, (%rax)
jmp 0x786cb
movq -0x68(%rbp), %rax
leaq 0x127734(%rip), %rcx    # 0x19fdfc
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x20(%rbp), %r8
addq $0x2, %r8
movq -0x30(%rbp), %r9
subq $0x2, %r9
leaq 0x1366b3(%rip), %rsi    # 0x1aedb1
callq 0x15c9f0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x30(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
addq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x78751
movb $0x1, -0x5d(%rbp)
jmp 0x787ff
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %r8
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl $0x1f4, %ecx            # imm = 0x1F4
movl $0x1, %r9d
movl %eax, (%rsp)
callq 0x166a40
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x48(%rbp), %rdi
callq 0x172650
movq -0x78(%rbp), %rdi
movq %rax, %rdx
leaq 0x133d40(%rip), %rsi    # 0x1ac4ea
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x133d18(%rip), %rsi    # 0x1ac4f9
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rcx
subq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x1, -0x54(%rbp)
cmpb $0x0, -0x5d(%rbp)
je 0x7881b
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x133cfd(%rip), %rsi    # 0x1ac511
movb $0x0, %al
callq 0x15bfb0
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x15d260
movq -0x40(%rbp), %rdi
callq 0x171750
movq -0x48(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movl -0x58(%rbp), %esi
callq 0x15b5a0
movl -0x54(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop