// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/pict.c
// Function: do_handle_qtif_idsc
static void do_handle_qtif_idsc(deark *c, lctx *d, i64 pos, i64 len)
{
	i64 idsc_dpos, idsc_dlen;
	i64 idat_dpos, idat_dlen;
	dbuf *outf = NULL;
	struct de_fourcc cmpr4cc;

	if(d->decode_qt) {
		if(do_decode_qt(c, d, pos, len)) {
			goto done;
		}
		de_dbg(c, "[failed to decode QuickTime image, extracting to .qtif instead]");
	}

	// Try to construct a .qtif file.
	// This way, we do something potentially useful even if the image has
	// a compression scheme that our qtif module doesn't support.

	idsc_dpos = pos;
	idsc_dlen = de_getu32be(idsc_dpos);
	de_dbg(c, "idsc: pos=%"I64_FMT", len=%"I64_FMT, idsc_dpos, idsc_dlen);
	if(idsc_dpos+idsc_dlen > pos+len) goto done;

	dbuf_read_fourcc(c->infile, idsc_dpos+4, &cmpr4cc, 4, 0x0);
	de_dbg(c, "compression type: \"%s\"", cmpr4cc.id_dbgstr);

	idat_dpos = idsc_dpos + idsc_dlen;
	idat_dlen = de_getu32be(idsc_dpos+44);
	de_dbg(c, "idat: pos=%"I64_FMT", len=%"I64_FMT, idat_dpos, idat_dlen);
	if(idat_dlen==0) {
		idat_dlen = pos+len-idat_dpos; // ??
	}
	if(idat_dpos+idat_dlen > pos+len) goto done;

#define CODE_idat 0x69646174U
#define CODE_idsc 0x69647363U
	outf = dbuf_create_output_file(c, "qtif", NULL, 0);

	dbuf_writeu32be(outf, 8+idsc_dlen);
	dbuf_writeu32be(outf, CODE_idsc);
	dbuf_copy(c->infile, idsc_dpos, idsc_dlen, outf);

	dbuf_writeu32be(outf, 8+idat_dlen);
	dbuf_writeu32be(outf, CODE_idat);
	dbuf_copy(c->infile, idat_dpos, idat_dlen, outf);

done:
	dbuf_close(outf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0x108e9e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x109040
cmpl $0x0, %eax
je 0x108e8c
jmp 0x109024
movq -0x8(%rbp), %rdi
leaq 0xb9bd1(%rip), %rsi     # 0x1c2a68
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165470
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
leaq 0xb9bda(%rip), %rsi     # 0x1c2aa8
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
addq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
addq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jle 0x108eef
jmp 0x109024
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x4, %rsi
leaq -0x78(%rbp), %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movq -0x8(%rbp), %rdi
leaq -0x78(%rbp), %rdx
addq $0x10, %rdx
leaq 0xbcce0(%rip), %rsi     # 0x1c5c03
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x2c, %rsi
callq 0x165470
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
leaq 0xb9b5d(%rip), %rsi     # 0x1c2abf
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0x40(%rbp)
jne 0x108f80
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
addq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jle 0x108f9a
jmp 0x109024
movq -0x8(%rbp), %rdi
leaq 0xb9b31(%rip), %rsi     # 0x1c2ad6
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x166c60
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
callq 0x168b80
movq -0x48(%rbp), %rdi
movl $0x69647363, %esi       # imm = 0x69647363
callq 0x168b80
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rcx
callq 0x166070
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x8, %rsi
callq 0x168b80
movq -0x48(%rbp), %rdi
movl $0x69646174, %esi       # imm = 0x69646174
callq 0x168b80
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
callq 0x166070
movq -0x48(%rbp), %rdi
callq 0x1676a0
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)