// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/tiff.c
// Function: do_tiff
static void do_tiff(deark *c, lctx *d)
{
	i64 pos;
	i64 ifdoffs;
	int ifd_idx;
	int need_to_read_header = 1;

	pos = 0;

	if(d->fmt==DE_TIFFFMT_APPLEMN) {
		push_ifd(c, d, 14, IFDTYPE_APPLEMN, 1);
		need_to_read_header = 0;
	}
	else if(d->fmt==DE_TIFFFMT_FUJIFILMMN) {
		ifdoffs = getfpos(c, d, 8);
		push_ifd(c, d, ifdoffs, IFDTYPE_FUJIFILMMN, 1);
		need_to_read_header = 0;
	}

	if(need_to_read_header) {
		de_dbg(c, "TIFF%s file header at %"I64_FMT,
			(d->is_exif_submodule?"/Exif":""), pos);
		de_dbg_indent(c, 1);

		de_dbg(c, "byte order: %s-endian", d->is_le?"little":"big");

		// Skip over the signature
		if(d->is_bigtiff) {
			pos += 8;
		}
		else {
			pos += 4;
		}

		// Read the first IFD offset
		ifdoffs = getfpos(c, d, pos);
		de_dbg(c, "offset of first IFD: %d", (int)ifdoffs);
		if(d->fmt==DE_TIFFFMT_NIKONMN) {
			push_ifd(c, d, ifdoffs, IFDTYPE_NIKONMN, 1);
		}
		else {
			push_ifd(c, d, ifdoffs, IFDTYPE_NORMAL, 1);
		}

		de_dbg_indent(c, -1);
	}

	// Process IFDs until we run out of them.
	// ifd_idx tracks how many IFDs we have finished processing, but it's not
	// really meaningful except when it's 0.
	ifd_idx = 0;
	while(1) {
		u8 ifdtype = IFDTYPE_NORMAL;
		u8 is_in_main_ifd_list = 0;

		ifdoffs = pop_ifd(c, d, &ifdtype, &is_in_main_ifd_list);
		if(ifdoffs==0) break;
		process_ifd(c, d, ifd_idx, ifdoffs, ifdtype, is_in_main_ifd_list);
		ifd_idx++;
	}

	de_dbg(c, "number of IFDs: %d (%d in main list)", d->ifd_count, d->num_main_ifds_processed);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x28(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0xa, 0x4(%rax)
jne 0x12e1bf
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0xe, %edx
movl $0x8, %ecx
movl $0x1, %r8d
callq 0x12e3a0
movl $0x0, -0x28(%rbp)
jmp 0x12e204
movq -0x10(%rbp), %rax
cmpl $0xb, 0x4(%rax)
jne 0x12e202
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x8, %edx
callq 0x12e580
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl $0xa, %ecx
movl $0x1, %r8d
callq 0x12e3a0
movl $0x0, -0x28(%rbp)
jmp 0x12e204
cmpl $0x0, -0x28(%rbp)
je 0x12e31b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %ecx
leaq 0xa29b0(%rip), %rdx     # 0x1d0bd0
leaq 0x89042(%rip), %rax     # 0x1b7269
cmpl $0x0, %ecx
cmovneq %rax, %rdx
movq -0x18(%rbp), %rcx
leaq 0x9a54d(%rip), %rsi     # 0x1c8786
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %ecx
leaq 0x916dc(%rip), %rdx     # 0x1bf93b
leaq 0x916ce(%rip), %rax     # 0x1bf934
cmpl $0x0, %ecx
cmovneq %rax, %rdx
leaq 0x916aa(%rip), %rsi     # 0x1bf91e
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpb $0x0, 0x8(%rax)
je 0x12e293
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
jmp 0x12e29f
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x12e580
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0x9a4db(%rip), %rsi     # 0x1c87a0
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x9, 0x4(%rax)
jne 0x12e2f4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl $0x6, %ecx
movl $0x1, %r8d
callq 0x12e3a0
jmp 0x12e30d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x12e3a0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl $0x0, -0x24(%rbp)
movb $0x0, -0x29(%rbp)
movb $0x0, -0x2a(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x29(%rbp), %rdx
leaq -0x2a(%rbp), %rcx
callq 0x12e600
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x12e34c
jmp 0x12e377
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x24(%rbp), %edx
movq -0x20(%rbp), %rcx
movb -0x29(%rbp), %al
movzbl %al, %r8d
movzbl -0x2a(%rbp), %r9d
callq 0x12e6d0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x12e322
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x48(%rax), %edx
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %ecx
leaq 0x9a428(%rip), %rsi     # 0x1c87b8
movb $0x0, %al
callq 0x15b0d0
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)