// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r13
movl %r8d, %ebp
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, 0x18(%rsp)
movq %rdi, %r12
movb $0x1, %al
testb $0x1, %bpl
jne 0xf823f
leaq 0x3a91a(%rip), %rsi     # 0x132b3a
xorl %r14d, %r14d
movq %r12, %rdi
xorl %edx, %edx
callq 0xea727
testl %eax, %eax
je 0xf82cf
andl $0x2, %ebp
sete %al
shrl %ebp
jmp 0xf8241
xorl %ebp, %ebp
movb $0x1, %r14b
testb %r14b, %r14b
jne 0xf830e
movb %al, 0x17(%rsp)
movq %r15, 0x20(%rsp)
movq %rbx, %r15
movl $0x70, %esi
movq %r12, %rdi
callq 0xe969b
movq %rax, %rbx
leaq 0x53956(%rip), %rax     # 0x14bbc6
movq %rax, (%rbx)
testq %r13, %r13
je 0xf82d8
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x60(%rbx)
movups %xmm1, 0x50(%rbx)
movups %xmm0, 0x40(%rbx)
leaq 0x3a786(%rip), %rsi     # 0x132a20
movq %r12, %rdi
movq %rbx, %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq %r15, %r9
callq 0xea5fa
movups 0x40(%rbx), %xmm0
movups 0x50(%rbx), %xmm1
movups 0x60(%rbx), %xmm2
movups %xmm0, (%r13)
movups %xmm1, 0x10(%r13)
movups %xmm2, 0x20(%r13)
jmp 0xf82f7
xorl %ebp, %ebp
movb $0x1, %al
jmp 0xf8244
leaq 0x3a741(%rip), %rsi     # 0x132a20
movq %r12, %rdi
movq %rbx, %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq %r15, %r9
callq 0xea5fa
movq %r12, %rdi
movq %rbx, %rsi
callq 0xe9752
movq %r15, %rbx
movq 0x20(%rsp), %r15
movb 0x17(%rsp), %al
andb %r14b, %bpl
cmpb $0x1, %bpl
jne 0xf8345
leaq 0x3a823(%rip), %rcx     # 0x132b41
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %r8d, %r8d
movl $0x1, %r9d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf0321
andb %al, %r14b
cmpb $0x1, %r14b
jne 0xf8379
leaq 0x51ba5(%rip), %rax     # 0x149efa
movq %rax, (%rsp)
leaq 0x51b85(%rip), %r8      # 0x149ee5
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
movl $0x8649, %r9d           # imm = 0x8649
callq 0xf7fc9
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq