// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/tiff.c
// Function: de_run_tiff
static void de_run_tiff(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;

	d = de_malloc(c, sizeof(lctx));

	if(mparams) {
		d->in_params = &mparams->in_params;
	}

	d->opt_decode = (u8)de_get_ext_option_bool(c, "tiff:decode", 1);
	d->opt_dexxa = (u8)de_get_ext_option_bool(c, "tiff:dexxa", 0xff);

	if(de_havemodcode(c, mparams, 'A')) {
		d->fmt = DE_TIFFFMT_APPLEMN;
		d->is_le = 0;
		de_strlcpy(d->errmsgtoken_module, "Apple MakerNote", sizeof(d->errmsgtoken_module));
	}
	else if(de_havemodcode(c, mparams, 'F')) {
		d->fmt = DE_TIFFFMT_FUJIFILMMN;
		d->is_le = 1;
		de_strlcpy(d->errmsgtoken_module, "FujiFilm MakerNote", sizeof(d->errmsgtoken_module));
	}
	else {
		d->fmt = de_identify_tiff_internal(c, &d->is_le);
	}

	if(de_havemodcode(c, mparams, 'N')) {
		de_strlcpy(d->errmsgtoken_module, "Nikon MakerNote", sizeof(d->errmsgtoken_module));
		d->fmt = DE_TIFFFMT_NIKONMN;
	}

	if(de_havemodcode(c, mparams, 'M') && (d->fmt==DE_TIFFFMT_TIFF)) {
		de_strlcpy(d->errmsgtoken_module, "MPF", sizeof(d->errmsgtoken_module));
		d->fmt = DE_TIFFFMT_MPEXT;
	}

	if(de_havemodcode(c, mparams, 'E')) {
		d->is_exif_submodule = 1;
		de_strlcpy(d->errmsgtoken_module, "Exif", sizeof(d->errmsgtoken_module));
	}

	if(d->fmt==DE_TIFFFMT_TIFF) {
		identify_more_formats(c, d);
	}

	switch(d->fmt) {
	case DE_TIFFFMT_TIFF:
		if(d->is_xiff)
			de_declare_fmt(c, "XIFF");
		else
			de_declare_fmt(c, "TIFF");
		break;
	case DE_TIFFFMT_BIGTIFF:
		de_declare_fmt(c, "BigTIFF");
		d->is_bigtiff = 1;
		break;
	case DE_TIFFFMT_PANASONIC:
		de_declare_fmt(c, "Panasonic RAW/RW2");
		break;
	case DE_TIFFFMT_ORF:
		de_declare_fmt(c, "Olympus RAW");
		break;
	case DE_TIFFFMT_DCP:
		de_declare_fmt(c, "DNG Camera Profile");
		break;
	case DE_TIFFFMT_MDI:
		de_declare_fmt(c, "MDI");
		break;
	case DE_TIFFFMT_JPEGXR:
		de_declare_fmt(c, "JPEG XR");
		break;
	}

	if(d->fmt==0) {
		detiff_warn(c, d, NULL, "This is not a known/supported TIFF or TIFF-like format.");
	}

	if(d->fmt==DE_TIFFFMT_TIFF) {
		d->fillorder_strategy = (u8)de_get_ext_option_bool(c, "tiff:fillorderstrategy", 0);
	}

	if(d->is_bigtiff) {
		d->ifdhdrsize = 8;
		d->ifditemsize = 20;
		d->offsetoffset = 12;
		d->offsetsize = 8;
	}
	else {
		d->ifdhdrsize = 2;
		d->ifditemsize = 12;
		d->offsetoffset = 8;
		d->offsetsize = 4;
	}

	d->current_textfield_encoding = DE_ENCODING_ASCII;

	do_tiff(c, d);

	if(mparams) {
		// .out_params.flags:
		//  0x08: has_exif_gps
		//  0x10: first IFD has subsampling=cosited
		//  0x20: uint1 = first IFD's orientation
		//  0x40: uint2 = Exif version
		//  0x80: uint3 = main image count
		if(d->has_exif_gps) {
			mparams->out_params.flags |= 0x08;
		}
		if(d->first_ifd_cosited) {
			mparams->out_params.flags |= 0x10;
		}
		if(d->first_ifd_orientation>0) {
			mparams->out_params.flags |= 0x20;
			mparams->out_params.uint1 = d->first_ifd_orientation;
		}
		if(d->exif_version_as_uint32>0) {
			mparams->out_params.flags |= 0x40;
			mparams->out_params.uint2 = d->exif_version_as_uint32;
		}
		if(d->fmt==DE_TIFFFMT_MPEXT) {
			mparams->out_params.flags |= 0x80;
			mparams->out_params.uint3 = d->mpf_main_image_count;
		}
	}

	if(d) {
		de_free(c, d->ifdstack);
		de_inthashtable_destroy(c, d->ifds_seen);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl $0xa8, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x12d88d
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x8(%rbp), %rdi
leaq 0x9ad93(%rip), %rsi     # 0x1c862b
movl $0x1, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x14(%rax)
movq -0x8(%rbp), %rdi
leaq 0x9ad81(%rip), %rsi     # 0x1c8637
movl $0xff, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x15(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x41, %edx
callq 0x15d1d0
cmpl $0x0, %eax
je 0x12d910
movq -0x18(%rbp), %rax
movl $0xa, 0x4(%rax)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rdi
addq $0x7c, %rdi
leaq 0x9ad3e(%rip), %rsi     # 0x1c8642
movl $0x28, %edx
callq 0x15aa30
jmp 0x12d96f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x46, %edx
callq 0x15d1d0
cmpl $0x0, %eax
je 0x12d957
movq -0x18(%rbp), %rax
movl $0xb, 0x4(%rax)
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x18(%rbp), %rdi
addq $0x7c, %rdi
leaq 0x9ad07(%rip), %rsi     # 0x1c8652
movl $0x28, %edx
callq 0x15aa30
jmp 0x12d96d
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12dd60
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x12d96f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x4e, %edx
callq 0x15d1d0
cmpl $0x0, %eax
je 0x12d9aa
movq -0x18(%rbp), %rdi
addq $0x7c, %rdi
leaq 0x9acd0(%rip), %rsi     # 0x1c8665
movl $0x28, %edx
callq 0x15aa30
movq -0x18(%rbp), %rax
movl $0x9, 0x4(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x4d, %edx
callq 0x15d1d0
cmpl $0x0, %eax
je 0x12d9ef
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x12d9ef
movq -0x18(%rbp), %rdi
addq $0x7c, %rdi
leaq 0x8900c(%rip), %rsi     # 0x1b69e6
movl $0x28, %edx
callq 0x15aa30
movq -0x18(%rbp), %rax
movl $0x8, 0x4(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x45, %edx
callq 0x15d1d0
cmpl $0x0, %eax
je 0x12da2a
movq -0x18(%rbp), %rax
movl $0x1, 0xc(%rax)
movq -0x18(%rbp), %rdi
addq $0x7c, %rdi
leaq 0x899e8(%rip), %rsi     # 0x1b7408
movl $0x28, %edx
callq 0x15aa30
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x12da41
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12dec0
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x6, %eax
ja 0x12db0d
movq -0x20(%rbp), %rax
leaq 0x9a44c(%rip), %rcx     # 0x1c7eb0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
cmpb $0x0, 0x9(%rax)
je 0x12da89
movq -0x8(%rbp), %rdi
leaq 0x9abf3(%rip), %rsi     # 0x1c8675
callq 0x15e380
jmp 0x12da99
movq -0x8(%rbp), %rdi
leaq 0xa875a(%rip), %rsi     # 0x1d61ee
callq 0x15e380
jmp 0x12db0d
movq -0x8(%rbp), %rdi
leaq 0x9abd4(%rip), %rsi     # 0x1c867a
callq 0x15e380
movq -0x18(%rbp), %rax
movb $0x1, 0x8(%rax)
jmp 0x12db0d
movq -0x8(%rbp), %rdi
leaq 0x9abc2(%rip), %rsi     # 0x1c8682
callq 0x15e380
jmp 0x12db0d
movq -0x8(%rbp), %rdi
leaq 0x9abc2(%rip), %rsi     # 0x1c8694
callq 0x15e380
jmp 0x12db0d
movq -0x8(%rbp), %rdi
leaq 0x9abbc(%rip), %rsi     # 0x1c86a0
callq 0x15e380
jmp 0x12db0d
movq -0x8(%rbp), %rdi
leaq 0x9abbd(%rip), %rsi     # 0x1c86b3
callq 0x15e380
jmp 0x12db0d
movq -0x8(%rbp), %rdi
leaq 0x9abaf(%rip), %rsi     # 0x1c86b7
callq 0x15e380
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x12db31
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq 0x9ab95(%rip), %rcx     # 0x1c86bf
movb $0x0, %al
callq 0x12dfd0
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x12db56
movq -0x8(%rbp), %rdi
leaq 0x9abb1(%rip), %rsi     # 0x1c86f7
xorl %edx, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x16(%rax)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x8(%rax)
je 0x12db92
movq -0x18(%rbp), %rax
movq $0x8, 0x50(%rax)
movq -0x18(%rbp), %rax
movq $0x14, 0x58(%rax)
movq -0x18(%rbp), %rax
movq $0xc, 0x60(%rax)
movq -0x18(%rbp), %rax
movq $0x8, 0x68(%rax)
jmp 0x12dbc2
movq -0x18(%rbp), %rax
movq $0x2, 0x50(%rax)
movq -0x18(%rbp), %rax
movq $0xc, 0x58(%rax)
movq -0x18(%rbp), %rax
movq $0x8, 0x60(%rax)
movq -0x18(%rbp), %rax
movq $0x4, 0x68(%rax)
movq -0x18(%rbp), %rax
movl $0x1, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12e170
cmpq $0x0, -0x10(%rbp)
je 0x12dc87
movq -0x18(%rbp), %rax
cmpb $0x0, 0x24(%rax)
je 0x12dbfc
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x40(%rax)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x25(%rax)
je 0x12dc13
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0x40(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jbe 0x12dc38
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
orl $0x20, %ecx
movl %ecx, 0x40(%rax)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x44(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jbe 0x12dc5d
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
orl $0x40, %ecx
movl %ecx, 0x40(%rax)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x48(%rax)
movq -0x18(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x12dc85
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
orl $0x80, %ecx
movl %ecx, 0x40(%rax)
movq -0x18(%rbp), %rax
movl 0x78(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4c(%rax)
jmp 0x12dc87
cmpq $0x0, -0x18(%rbp)
je 0x12dcbd
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0x15e630
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)