// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x0, 0x18(%rsi)
je 0xb9e97
movq 0x28(%rbx), %rdx
testq %rdx, %rdx
jg 0xb9e1e
movq 0x10(%rbx), %rdx
testq %rdx, %rdx
jle 0xba06e
cmpl $0x20776172, 0x30(%rbx) # imm = 0x20776172
je 0xb9ebf
leaq 0x30(%rbx), %rax
cmpl $0x6765706a, (%rax)     # imm = 0x6765706A
je 0xb9ee1
cmpl $0x66666974, (%rax)     # imm = 0x66666974
je 0xb9f16
cmpl $0x20666967, (%rax)     # imm = 0x20666967
je 0xb9f2a
cmpl $0x20676e70, (%rax)     # imm = 0x20676E70
je 0xba03f
cmpl $0x6463706b, (%rax)     # imm = 0x6463706B
je 0xba050
leaq 0x38(%rbx), %rdx
cmpb $0x0, (%rbx)
je 0xba07d
leaq 0x73230(%rip), %rsi     # 0x12d0af
movq %r14, %rdi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xde896
cmpb $0x0, (%rbx)
jne 0xba06e
leaq 0x731e2(%rip), %rsi     # 0x12d089
movq %r14, %rdi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xdf2a5
movq 0x70(%rbx), %rdx
movb (%rbx), %al
cmpq $0x20, %rdx
jne 0xb9ef5
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
movq %r14, %rdi
testb %al, %al
je 0xb9f3e
callq 0xe6bb4
jmp 0xb9f43
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
leaq 0x6c6ea(%rip), %rcx     # 0x1265da
jmp 0xba05f
testb %al, %al
jne 0xba001
leaq 0x731ce(%rip), %rsi     # 0x12d0d2
xorl %r15d, %r15d
movq %r14, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0xba004
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
leaq 0x83072(%rip), %rcx     # 0x13cf97
jmp 0xba05f
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
leaq 0x58b13(%rip), %rcx     # 0x112a4c
jmp 0xba05f
callq 0xe6be1
testl %eax, %eax
je 0xba001
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
pushq $0x3
popq %rcx
movq %r14, %rdi
callq 0xe7437
movq %rax, %r12
movq %r14, %rdi
callq 0xdfd1a
movl $0x2, 0x78(%rax)
movups 0x80(%rbx), %xmm0
movq %rax, (%rsp)
movups %xmm0, 0x80(%rax)
movq 0x28(%rbx), %rax
movq 0x60(%rbx), %rcx
leaq (,%rcx,4), %rdi
movq 0x68(%rbx), %rsi
cqto
idivq %rsi
cmpq %rdi, %rax
cmovgq %rax, %rdi
movq %rdi, 0x8(%rsp)
pushq $0x1
popq %r15
xorl %r13d, %r13d
cmpq %rsi, %r13
jge 0xba009
movq %r15, 0x10(%rsp)
xorl %ebp, %ebp
cmpq %rcx, %rbp
jge 0xb9fee
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
addq %r15, %rsi
xorl %edx, %edx
callq 0xe45a4
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %eax, %ecx
callq 0xe7287
incq %rbp
movq 0x60(%rbx), %rcx
addq $0x4, %r15
jmp 0xb9fba
incq %r13
movq 0x68(%rbx), %rsi
movq 0x10(%rsp), %r15
addq 0x8(%rsp), %r15
jmp 0xb9fae
xorl %r15d, %r15d
xorl %r12d, %r12d
jmp 0xba01e
movq %r12, %rdi
movq (%rsp), %r15
movq %r15, %rsi
xorl %edx, %edx
callq 0xe70ab
movb $0x1, 0x1(%rbx)
movq %r12, %rdi
callq 0xe7084
movq %r14, %rdi
movq %r15, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xdfd24
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
leaq 0x614a2(%rip), %rcx     # 0x11b4f0
jmp 0xba05f
movq 0x18(%r14), %rdi
movq 0x8(%rbx), %rsi
leaq 0x7304c(%rip), %rcx     # 0x12d0ab
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xe4e0b
movb $0x1, 0x1(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7302b(%rip), %rsi     # 0x12d0af
movq %r14, %rdi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xdf2a5