// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/qtif.c
// Function: do_write_image
static void do_write_image(deark *c, lctx *d)
{
	i64 dsize;

	if(!d->idsc_found) {
		if(!d->fail_gracefully_mode)
			de_err(c, "Missing idsc atom");
		return;
	}

	dsize = (d->idat_data_size>0) ? d->idat_data_size : d->idat_size;
	if(dsize<=0) return;

	if(!de_memcmp(d->cmpr4cc.bytes, "raw ", 4)) {
		do_decode_raw(c, d);
	}
	else if(!de_memcmp(d->cmpr4cc.bytes, "jpeg", 4)) {
		dbuf_create_file_from_slice(c->infile, d->idat_pos, dsize, "jpg", NULL, 0);
		d->decoded_ok = 1;
	}
	else if(!de_memcmp(d->cmpr4cc.bytes, "tiff", 4)) {
		dbuf_create_file_from_slice(c->infile, d->idat_pos, dsize, "tif", NULL, 0);
		d->decoded_ok = 1;
	}
	else if(!de_memcmp(d->cmpr4cc.bytes, "gif ", 4)) {
		dbuf_create_file_from_slice(c->infile, d->idat_pos, dsize, "gif", NULL, 0);
		d->decoded_ok = 1;
	}
	else if(!de_memcmp(d->cmpr4cc.bytes, "png ", 4)) {
		dbuf_create_file_from_slice(c->infile, d->idat_pos, dsize, "png", NULL, 0);
		d->decoded_ok = 1;
	}
	else if(!de_memcmp(d->cmpr4cc.bytes, "kpcd", 4)) { // Kodak Photo CD
		dbuf_create_file_from_slice(c->infile, d->idat_pos, dsize, "pcd", NULL, 0);
		d->decoded_ok = 1;
	}
	else {
		if(d->fail_gracefully_mode) {
			de_dbg(c, "Unsupported compression type: \"%s\"", d->cmpr4cc.id_sanitized_sz);
		}
		else {
			de_err(c, "Unsupported compression type: \"%s\"", d->cmpr4cc.id_sanitized_sz);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x0, 0x18(%rsi)
je 0xc2434
movq 0x28(%rbx), %rdx
testq %rdx, %rdx
jg 0xc23b1
movq 0x10(%rbx), %rdx
testq %rdx, %rdx
jle 0xc2639
cmpl $0x20776172, 0x30(%rbx) # imm = 0x20776172
je 0xc245c
cmpl $0x6765706a, 0x30(%rbx) # imm = 0x6765706A
je 0xc247e
cmpl $0x66666974, 0x30(%rbx) # imm = 0x66666974
je 0xc24b3
cmpl $0x20666967, 0x30(%rbx) # imm = 0x20666967
je 0xc24c7
cmpl $0x20676e70, 0x30(%rbx) # imm = 0x20676E70
je 0xc260a
cmpl $0x6463706b, 0x30(%rbx) # imm = 0x6463706B
je 0xc261b
leaq 0x38(%rbx), %rdx
cmpb $0x0, (%rbx)
je 0xc2648
leaq 0x77c03(%rip), %rsi     # 0x13a01f
movq %r14, %rdi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9226
cmpb $0x0, (%rbx)
jne 0xc2639
leaq 0x77bb5(%rip), %rsi     # 0x139ff9
movq %r14, %rdi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9df7
movq 0x70(%rbx), %rdx
movb (%rbx), %al
cmpq $0x20, %rdx
jne 0xc2492
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
movq %r14, %rdi
testb %al, %al
je 0xc24db
callq 0xf23f0
jmp 0xc24e0
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
leaq 0x7102d(%rip), %rcx     # 0x1334ba
jmp 0xc262a
testb %al, %al
jne 0xc25e3
leaq 0x77ba1(%rip), %rsi     # 0x13a042
xorl %r15d, %r15d
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xc25e6
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
leaq 0x879f5(%rip), %rcx     # 0x149eb7
jmp 0xc262a
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
leaq 0x5d4fa(%rip), %rcx     # 0x11f9d0
jmp 0xc262a
callq 0xf241d
testl %eax, %eax
je 0xc25e3
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
movq %r14, %rdi
movl $0x3, %ecx
callq 0xf2cab
movq %rax, %r12
movq %r14, 0x10(%rsp)
movq %r14, %rdi
callq 0xea9a9
movl $0x2, 0x78(%rax)
movsd 0x80(%rbx), %xmm0
movsd %xmm0, 0x80(%rax)
movsd 0x88(%rbx), %xmm0
movq %rax, 0x18(%rsp)
movsd %xmm0, 0x88(%rax)
movq 0x28(%rbx), %rax
movq 0x60(%rbx), %rsi
shlq $0x2, %rsi
movq 0x68(%rbx), %rcx
cqto
idivq %rcx
cmpq %rsi, %rax
cmovgq %rax, %rsi
movq %rsi, 0x20(%rsp)
testq %rcx, %rcx
jle 0xc25c6
movl $0x1, %eax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
movq 0x10(%rsp), %r14
cmpq $0x0, 0x60(%rbx)
jle 0xc25ae
movq 0x8(%rsp), %r15
xorl %ebp, %ebp
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
addq %r15, %rsi
xorl %edx, %edx
callq 0xefa60
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %eax, %ecx
callq 0xf2afd
incq %rbp
addq $0x4, %r15
cmpq 0x60(%rbx), %rbp
jl 0xc257f
incq %r13
movq 0x8(%rsp), %rax
addq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq 0x68(%rbx), %r13
jl 0xc2571
movq %r12, %rdi
movq 0x18(%rsp), %r15
movq %r15, %rsi
xorl %edx, %edx
callq 0xf2917
movb $0x1, 0x1(%rbx)
movq 0x10(%rsp), %r14
jmp 0xc25e9
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %r12, %rdi
callq 0xf28d4
movq %r14, %rdi
movq %r15, %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xea9b3
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
leaq 0x65ee7(%rip), %rcx     # 0x128500
jmp 0xc262a
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
leaq 0x779f1(%rip), %rcx     # 0x13a01b
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xf0321
movb $0x1, 0x1(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x779d0(%rip), %rsi     # 0x13a01f
movq %r14, %rdi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9df7