// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/tiff.c
// Function: handler_mpentry
static void handler_mpentry(deark *c, lctx *d, const struct taginfo *tg, const struct tagnuminfo *tni)
{
	i64 num_entries;
	i64 k;
	i64 pos = tg->val_offset;
	de_ucstring *s = NULL;
	struct mpfctx_struct mpfctx;

	de_zeromem(&mpfctx, sizeof(struct mpfctx_struct));
	d->mpf_main_image_count = 0;
	// Length is supposed to be 16x{NumberOfImages; tag 45057}. We'll just assume
	// it's correct.
	num_entries = tg->total_size/16;

	s = ucstring_create(c);
	for(k=0; k<num_entries; k++) {
		i64 n;
		i64 imgoffs_rel, imgoffs_abs;
		i64 imgsize;
		u32 attrs;
		u32 dataformat;
		u32 typecode;
		char offset_descr[80];

		de_dbg(c, "entry #%d", (int)(k+1));
		de_dbg_indent(c, 1);

		attrs = (u32)dbuf_getu32x(c->infile, pos, d->is_le);
		dataformat = (attrs&0x07000000)>>24;
		typecode = attrs&0x00ffffff;
		ucstring_empty(s);
		if(attrs&0x80000000U) ucstring_append_flags_item(s, "dependent parent");
		if(attrs&0x40000000U) ucstring_append_flags_item(s, "dependent child");
		if(attrs&0x20000000U) ucstring_append_flags_item(s, "representative image");
		if(dataformat==0) ucstring_append_flags_item(s, "JPEG");
		if(typecode==0x030000U) ucstring_append_flags_item(s, "baseline MP primary image");
		if(typecode==0x010001U) ucstring_append_flags_item(s, "large thumbnail class 1");
		if(typecode==0x010002U) ucstring_append_flags_item(s, "large thumbnail class 2");
		if(typecode==0x020001U) ucstring_append_flags_item(s, "multi-frame image panorama");
		if(typecode==0x020002U) ucstring_append_flags_item(s, "multi-frame image disparity");
		if(typecode==0x020003U) ucstring_append_flags_item(s, "multi-frame image multi-angle");

		if(typecode==0x010001U || typecode==0x010002U) {
			mpfctx.is_thumb = 1;
		}
		else {
			// Count that number of non-thumbnail images
			d->mpf_main_image_count++;
			mpfctx.is_thumb = 0;
		}

		de_dbg(c, "image attribs: 0x%08x (%s)", (unsigned int)attrs,
			ucstring_getpsz(s));

		imgsize = dbuf_getu32x(c->infile, pos+4, d->is_le);
		de_dbg(c, "image size: %u", (unsigned int)imgsize);

		imgoffs_rel = dbuf_getu32x(c->infile, pos+8, d->is_le);
		// This is relative to beginning of the payload data (the TIFF header)
		// of the MPF segment, except that 0 is a special case.
		if(imgoffs_rel==0) {
			imgoffs_abs = 0;
			de_strlcpy(offset_descr, "refers to the first image", sizeof(offset_descr));
		}
		else if(d->in_params && (d->in_params->flags&0x01)) {
			imgoffs_abs = d->in_params->offset_in_parent+imgoffs_rel;
			de_snprintf(offset_descr, sizeof(offset_descr), "absolute offset %"I64_FMT,
				imgoffs_abs);
		}
		else {
			imgoffs_abs = imgoffs_rel;
			de_strlcpy(offset_descr, "?", sizeof(offset_descr));
		}
		de_dbg(c, "image offset: %u (%s)", (unsigned int)imgoffs_rel, offset_descr);

		if(imgoffs_rel>0) {
			mpfctx.imgoffs_abs = imgoffs_abs;
			mpfctx.imgsize = imgsize;
			try_to_extract_mpf_image(c, d, tg->pg, &mpfctx);
		}

		n = dbuf_getu16x(c->infile, pos+12, d->is_le);
		de_dbg(c, "dep. image #1 entry: %u", (unsigned int)n);
		n = dbuf_getu16x(c->infile, pos+14, d->is_le);
		de_dbg(c, "dep. image #2 entry: %u", (unsigned int)n);
		de_dbg_indent(c, -1);
		pos += 16;
	}
	ucstring_destroy(s);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x19140
movq -0x10(%rbp), %rax
movl $0x0, 0x78(%rax)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl $0x10, %ecx
cqto
idivq %rcx
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0x132bfb
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
addq $0x1, %rax
movl %eax, %edx
leaq 0x9dc89(%rip), %rsi     # 0x1d04d1
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rax
movl (%rax), %edx
callq 0x1658c0
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
andl $0x7000000, %eax        # imm = 0x7000000
shrl $0x18, %eax
movl %eax, -0x80(%rbp)
movl -0x7c(%rbp), %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
movl %eax, -0x84(%rbp)
movq -0x40(%rbp), %rdi
callq 0x171210
movl -0x7c(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x1328b9
movq -0x40(%rbp), %rdi
leaq 0x98ab6(%rip), %rsi     # 0x1cb36a
callq 0x172680
movl -0x7c(%rbp), %eax
andl $0x40000000, %eax       # imm = 0x40000000
cmpl $0x0, %eax
je 0x1328d6
movq -0x40(%rbp), %rdi
leaq 0x98aaa(%rip), %rsi     # 0x1cb37b
callq 0x172680
movl -0x7c(%rbp), %eax
andl $0x20000000, %eax       # imm = 0x20000000
cmpl $0x0, %eax
je 0x1328f3
movq -0x40(%rbp), %rdi
leaq 0x98a9d(%rip), %rsi     # 0x1cb38b
callq 0x172680
cmpl $0x0, -0x80(%rbp)
jne 0x132909
movq -0x40(%rbp), %rdi
leaq 0x6bd33(%rip), %rsi     # 0x19e637
callq 0x172680
cmpl $0x30000, -0x84(%rbp)   # imm = 0x30000
jne 0x132925
movq -0x40(%rbp), %rdi
leaq 0x98a80(%rip), %rsi     # 0x1cb3a0
callq 0x172680
cmpl $0x10001, -0x84(%rbp)   # imm = 0x10001
jne 0x132941
movq -0x40(%rbp), %rdi
leaq 0x98a7e(%rip), %rsi     # 0x1cb3ba
callq 0x172680
cmpl $0x10002, -0x84(%rbp)   # imm = 0x10002
jne 0x13295d
movq -0x40(%rbp), %rdi
leaq 0x98a7a(%rip), %rsi     # 0x1cb3d2
callq 0x172680
cmpl $0x20001, -0x84(%rbp)   # imm = 0x20001
jne 0x132979
movq -0x40(%rbp), %rdi
leaq 0x98a76(%rip), %rsi     # 0x1cb3ea
callq 0x172680
cmpl $0x20002, -0x84(%rbp)   # imm = 0x20002
jne 0x132995
movq -0x40(%rbp), %rdi
leaq 0x98a75(%rip), %rsi     # 0x1cb405
callq 0x172680
cmpl $0x20003, -0x84(%rbp)   # imm = 0x20003
jne 0x1329b1
movq -0x40(%rbp), %rdi
leaq 0x98a75(%rip), %rsi     # 0x1cb421
callq 0x172680
cmpl $0x10001, -0x84(%rbp)   # imm = 0x10001
je 0x1329c9
cmpl $0x10002, -0x84(%rbp)   # imm = 0x10002
jne 0x1329d2
movl $0x1, -0x54(%rbp)
jmp 0x1329e6
movq -0x10(%rbp), %rax
movl 0x78(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x78(%rax)
movl $0x0, -0x54(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0xe4(%rbp)
movq -0x40(%rbp), %rdi
callq 0x172500
movq -0xf0(%rbp), %rdi
movl -0xe4(%rbp), %edx
movq %rax, %rcx
leaq 0x98a25(%rip), %rsi     # 0x1cb43f
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
addq $0x4, %rsi
movq -0x10(%rbp), %rax
movl (%rax), %edx
callq 0x1658c0
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
movq -0x78(%rbp), %rax
movl %eax, %edx
leaq 0x98a09(%rip), %rsi     # 0x1cb45a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
addq $0x8, %rsi
movq -0x10(%rbp), %rax
movl (%rax), %edx
callq 0x1658c0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x132aa0
movq $0x0, -0x70(%rbp)
leaq -0xe0(%rbp), %rdi
leaq 0x989d5(%rip), %rsi     # 0x1cb469
movl $0x50, %edx
callq 0x15aa30
jmp 0x132b14
movq -0x10(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x132af2
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x132af2
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq 0x18(%rax), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0xe0(%rbp), %rdi
movq -0x70(%rbp), %rcx
movl $0x50, %esi
leaq 0x9899a(%rip), %rdx     # 0x1cb483
movb $0x0, %al
callq 0x15a980
jmp 0x132b12
movq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0xe0(%rbp), %rdi
leaq 0x85125(%rip), %rsi     # 0x1b7c2d
movl $0x50, %edx
callq 0x15aa30
jmp 0x132b14
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rax
movl %eax, %edx
leaq -0xe0(%rbp), %rcx
leaq 0x9896b(%rip), %rsi     # 0x1cb497
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0x68(%rbp)
jle 0x132b62
movq -0x70(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq -0x58(%rbp), %rcx
callq 0x1345c0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
addq $0xc, %rsi
movq -0x10(%rbp), %rax
movl (%rax), %edx
callq 0x165820
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl %eax, %edx
leaq 0x9891b(%rip), %rsi     # 0x1cb4ad
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
addq $0xe, %rsi
movq -0x10(%rbp), %rax
movl (%rax), %edx
callq 0x165820
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl %eax, %edx
leaq 0x988fc(%rip), %rsi     # 0x1cb4c5
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x38(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x132825
movq -0x40(%rbp), %rdi
callq 0x171750
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)