// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/fmtutil.c
// Function: fmtutil_handle_photoshop_rsrc2
void fmtutil_handle_photoshop_rsrc2(deark *c, dbuf *f, i64 pos, i64 len,
	unsigned int flags, struct de_module_out_params *oparams)
{
	int should_decode;
	int should_extract;
	int extract_fmt = 1; // 0=raw, 1=TIFF-wrapped

	if(flags&0x1) {
		should_decode = 0;
		should_extract = 1;
	}
	else if(de_get_ext_option_bool(c, "extract8bim", 0)) {
		should_extract = 1;
		should_decode = 0;
		if(flags&0x2) {
			// Avoid "extracting" in a way that would just recreate the exact same file.
			extract_fmt = 0;
		}
	}
	else {
		should_decode = 1;
		should_extract = 0;
	}

	if(should_decode) {
		de_module_params *mparams = NULL;

		mparams = de_malloc(c, sizeof(de_module_params));
		mparams->in_params.codes = "R";
		if(oparams) {
			// Since mparams->out_params is an embedded struct, not a pointer,
			// we have to copy oparam's fields to and from it.
			mparams->out_params = *oparams; // struct copy
		}
		de_run_module_by_id_on_slice(c, "psd", mparams, f, pos, len);
		if(oparams) {
			*oparams = mparams->out_params; // struct copy
		}
		de_free(c, mparams);
	}

	if(should_extract && extract_fmt==0) {
		dbuf_create_file_from_slice(f, pos, len, "8bim", NULL, DE_CREATEFLAG_IS_AUX);
	}
	else if(should_extract && extract_fmt==1) {
		wrap_in_tiff(c, f, pos, len, "Deark extracted 8BIM", 34377, "8bimtiff",
			DE_CREATEFLAG_IS_AUX);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movl $0x1, -0x3c(%rbp)
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x173a72
movl $0x0, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
jmp 0x173abb
movq -0x8(%rbp), %rdi
leaq 0x4aefc(%rip), %rsi     # 0x1be979
xorl %edx, %edx
callq 0x15cbc0
cmpl $0x0, %eax
je 0x173aab
movl $0x1, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x173aa9
movl $0x0, -0x3c(%rbp)
jmp 0x173ab9
movl $0x1, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
jmp 0x173abb
cmpl $0x0, -0x34(%rbp)
je 0x173b54
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movl $0x70, %esi
callq 0x15b780
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
leaq 0x64089(%rip), %rcx     # 0x1d7b73
movq %rcx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x173b0a
movq -0x48(%rbp), %rdi
addq $0x40, %rdi
movq -0x30(%rbp), %rsi
movl $0x30, %edx
callq 0x191e0
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %r9
leaq 0x4ad3a(%rip), %rsi     # 0x1be85f
callq 0x15c9f0
cmpq $0x0, -0x30(%rbp)
je 0x173b47
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
addq $0x40, %rsi
movl $0x30, %edx
callq 0x191e0
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x15b820
cmpl $0x0, -0x38(%rbp)
je 0x173b85
cmpl $0x0, -0x3c(%rbp)
jne 0x173b85
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq 0x4ae0d(%rip), %rcx     # 0x1be980
xorl %eax, %eax
movl %eax, %r8d
movl $0x1, %r9d
callq 0x166be0
jmp 0x173bc8
cmpl $0x0, -0x38(%rbp)
je 0x173bc6
cmpl $0x1, -0x3c(%rbp)
jne 0x173bc6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq 0x6239d(%rip), %r8      # 0x1d5f45
movl $0x8649, %r9d           # imm = 0x8649
leaq 0x623a5(%rip), %rax     # 0x1d5f5a
movq %rax, (%rsp)
movl $0x1, 0x8(%rsp)
callq 0x173830
jmp 0x173bc8
addq $0x60, %rsp
popq %rbp
retq
nop