// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x11e5da
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x11e5d5
movq -0x8(%rbp), %rdi
leaq 0xa7603(%rip), %rsi     # 0x1c5bd1
movb $0x0, %al
callq 0x15bfb0
jmp 0x11e81a
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jle 0x11e5f3
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x11e5ff
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jg 0x11e613
jmp 0x11e81a
movq -0x10(%rbp), %rax
addq $0x30, %rax
movl (%rax), %eax
subl $0x20776172, %eax       # imm = 0x20776172
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x11e63f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x11e820
jmp 0x11e81a
movq -0x10(%rbp), %rax
addq $0x30, %rax
movl (%rax), %eax
subl $0x6765706a, %eax       # imm = 0x6765706A
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x11e68e
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rdx
leaq 0xa0c85(%rip), %rcx     # 0x1bf2f9
xorl %eax, %eax
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x166be0
movq -0x10(%rbp), %rax
movb $0x1, 0x1(%rax)
jmp 0x11e818
movq -0x10(%rbp), %rax
addq $0x30, %rax
movl (%rax), %eax
subl $0x66666974, %eax       # imm = 0x66666974
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x11e6dd
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rdx
leaq 0xb7854(%rip), %rcx     # 0x1d5f17
xorl %eax, %eax
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x166be0
movq -0x10(%rbp), %rax
movb $0x1, 0x1(%rax)
jmp 0x11e816
movq -0x10(%rbp), %rax
addq $0x30, %rax
movl (%rax), %eax
subl $0x20666967, %eax       # imm = 0x20666967
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x11e72c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rdx
leaq 0x8cf4e(%rip), %rcx     # 0x1ab660
xorl %eax, %eax
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x166be0
movq -0x10(%rbp), %rax
movb $0x1, 0x1(%rax)
jmp 0x11e814
movq -0x10(%rbp), %rax
addq $0x30, %rax
movl (%rax), %eax
subl $0x20676e70, %eax       # imm = 0x20676E70
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x11e77b
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rdx
leaq 0x95777(%rip), %rcx     # 0x1b3ed8
xorl %eax, %eax
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x166be0
movq -0x10(%rbp), %rax
movb $0x1, 0x1(%rax)
jmp 0x11e812
movq -0x10(%rbp), %rax
addq $0x30, %rax
movl (%rax), %eax
subl $0x6463706b, %eax       # imm = 0x6463706B
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x11e7c7
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rdx
leaq 0xa7443(%rip), %rcx     # 0x1c5bf3
xorl %eax, %eax
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x166be0
movq -0x10(%rbp), %rax
movb $0x1, 0x1(%rax)
jmp 0x11e810
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x11e7f0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x30, %rdx
addq $0x8, %rdx
leaq 0xa7410(%rip), %rsi     # 0x1c5bf7
movb $0x0, %al
callq 0x15b0d0
jmp 0x11e80e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x30, %rdx
addq $0x8, %rdx
leaq 0xa73f0(%rip), %rsi     # 0x1c5bf7
movb $0x0, %al
callq 0x15bfb0
jmp 0x11e810
jmp 0x11e812
jmp 0x11e814
jmp 0x11e816
jmp 0x11e818
jmp 0x11e81a
addq $0x20, %rsp
popq %rbp
retq