// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-bitmap.c
// Function: de_bitmap16_write_to_file_finfo
void de_bitmap16_write_to_file_finfo(de_bitmap *img, de_bitmap *imglo,
	de_finfo *fi, unsigned int createflags)
{
	deark *c;
	struct image_scan_opt_data optctx;
	struct de_write_image_params wp;

	if(!img) return;
	c = img->c;
	if(img->invalid_image_flag) return;
	de_zeromem(&optctx, sizeof(struct image_scan_opt_data));

	if(!img->bitmap) de_bitmap_alloc_pixels(img);
	if(imglo) {
		if(!imglo->bitmap) de_bitmap_alloc_pixels(imglo);
		if(!valid_imglo(img, imglo)) return;
	}

	de_zeromem(&wp, sizeof(struct de_write_image_params));
	wp.createflags = createflags;

	if(imglo && (createflags & DE_CREATEFLAG_OPT_IMAGE)) {
		// If the high and low bytes are the same in every sample, we don't need
		// the low byte.
		if(!bitmap16_low_bits_important(img, imglo)) {
			imglo = NULL;
		}
	}

	if(imglo) {
		; // The routines below don't support 16-bit images
	}
	else if(createflags & DE_CREATEFLAG_IS_BWIMG) {
		// The BWIMG flag/optimization has to be handled in a different way than the
		// other optimizations, because our de_bitmap object does not support a
		// 1 bit/pixel image type.
		wp.flags2 |= 0x1;
	}
	else if(createflags & DE_CREATEFLAG_OPT_IMAGE) {
		// This should probably be the default, but our optimization routine
		// isn't very efficient, and wouldn't change anything in most cases.
		get_optimized_image(img, &optctx);
		if(optctx.optimg) {
			de_dbg3(c, "reducing image depth (%d->%d)", img->bytes_per_pixel,
				optctx.optimg->bytes_per_pixel);
		}
		if(!optctx.is_nonbilevel) {
			de_dbg3(c, "reducing to bilevel (from %d samples)", img->bytes_per_pixel);
			wp.flags2 |= 0x1;
		}
	}

	if(fi && fi->linear_colorpace) {
		wp.flags2 |= 0x2;
	}

	wp.f = dbuf_create_output_file(c, "png", fi, createflags);
	if(optctx.optimg) {
		wp.img = optctx.optimg;
	}
	else {
		wp.img = img;
		wp.imglo = imglo;
	}
	de_write_png(c, &wp);
	dbuf_close(wp.f);

	if(optctx.optimg) de_bitmap_destroy(optctx.optimg);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x16aae3
jmp 0x16aca7
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x16aafd
jmp 0x16aca7
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x19140
movq -0x8(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x16ab21
movq -0x8(%rbp), %rdi
callq 0x16acb0
cmpq $0x0, -0x10(%rbp)
je 0x16ab55
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x16ab3c
movq -0x10(%rbp), %rdi
callq 0x16acb0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x16ad50
cmpl $0x0, %eax
jne 0x16ab53
jmp 0x16aca7
jmp 0x16ab55
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x19140
movl -0x1c(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x16ab99
movl -0x1c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x16ab99
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x16add0
cmpl $0x0, %eax
jne 0x16ab97
movq $0x0, -0x10(%rbp)
jmp 0x16ab99
cmpq $0x0, -0x10(%rbp)
je 0x16aba5
jmp 0x16ac28
movl -0x1c(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x16abbb
movl -0x3c(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x16ac26
movl -0x1c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x16ac24
movq -0x8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x16ae80
cmpq $0x0, -0x30(%rbp)
je 0x16abfa
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x24(%rax), %edx
movq -0x30(%rbp), %rax
movl 0x24(%rax), %ecx
leaq 0x6a548(%rip), %rsi     # 0x1d513b
movb $0x0, %al
callq 0x15b400
cmpb $0x0, -0x35(%rbp)
jne 0x16ac22
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x24(%rax), %edx
leaq 0x6a547(%rip), %rsi     # 0x1d5159
movb $0x0, %al
callq 0x15b400
movl -0x3c(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x16ac24
jmp 0x16ac26
jmp 0x16ac28
cmpq $0x0, -0x18(%rbp)
je 0x16ac45
movq -0x18(%rbp), %rax
movzbl 0xf(%rax), %eax
cmpl $0x0, %eax
je 0x16ac45
movl -0x3c(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
leaq 0x49281(%rip), %rsi     # 0x1b3ed8
callq 0x166c60
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x16ac71
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x16ac81
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x19aa70
movq -0x48(%rbp), %rdi
callq 0x1676a0
cmpq $0x0, -0x30(%rbp)
je 0x16aca7
movq -0x30(%rbp), %rdi
callq 0x16af60
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)