// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/bmp.c
// Function: do_ddb_bitmap
static void do_ddb_bitmap(deark *c, struct ddbctx_struct *d, i64 pos1)
{
	i64 pos = pos1;
	UI bmType;
	i64 bmWidth, bmHeight;
	i64 pdwidth;
	i64 bmPlanes;
	i64 bmBitsPixel;
	i64 src_realbitsperpixel;
	de_bitmap *img = NULL;

	bmType = (UI)de_getu16le_p(&pos);
	de_dbg(c, "bmType: %u", bmType);

	bmWidth = de_getu16le_p(&pos);
	bmHeight = de_getu16le_p(&pos);
	de_dbg_dimensions(c, bmWidth, bmHeight);

	d->bmWidthBytes = de_getu16le_p(&pos);
	de_dbg(c, "bytes/row: %d", (int)d->bmWidthBytes);

	bmPlanes = (i64)de_getbyte_p(&pos);
	de_dbg(c, "planes: %d", (int)bmPlanes);

	bmBitsPixel = (i64)de_getbyte_p(&pos);
	de_dbg(c, "bmBitsPixel: %d", (int)bmBitsPixel);

	pos += 4; // Placeholder for a pointer?

	if((bmBitsPixel==1 && bmPlanes==1) ||
		(bmBitsPixel==1 && bmPlanes==4) ||
		(bmBitsPixel==8 && bmPlanes==1) ||
		(bmBitsPixel==32 && bmPlanes==1))
	{
		;
	}
	else {
		de_err(c, "This type of DDB bitmap is not supported "
			"(bmBitsPixel=%d, planes=%d)", (int)bmBitsPixel, (int)bmPlanes);
		goto done;
	}

	de_dbg(c, "pixels at %"I64_FMT, pos);

	src_realbitsperpixel = bmBitsPixel * bmPlanes;

	if(d->cdr_adjdim_flag && src_realbitsperpixel==1 &&
		bmWidth==bmHeight && (bmWidth==90 || bmWidth==128))
	{
		// See comments in the cdr_wl module about "adjdim".
		bmWidth--;
		bmHeight--;
		de_dbg(c, "adjusted dimensions: %"I64_FMT DE_CHAR_TIMES"%"I64_FMT,
			bmWidth, bmHeight);
	}

	if(!de_good_image_dimensions(c, bmWidth, bmHeight)) goto done;

	pdwidth = (d->bmWidthBytes*8) / bmBitsPixel;
	img = de_bitmap_create2(c, bmWidth, pdwidth, bmHeight, (src_realbitsperpixel==1)?1:3);

	if(bmBitsPixel==1 && bmPlanes==1) {
		de_convert_image_bilevel(c->infile, pos, d->bmWidthBytes, img, 0);
	}
	else if(bmBitsPixel==1 && bmPlanes==4) {
		ddb_convert_pal4planar(c, d, pos, img);
	}
	else if(bmBitsPixel==8 && bmPlanes==1) {
		ddb_convert_pal8(c, d, pos, img);
	}
	else if(bmBitsPixel==32 && bmPlanes==1) {
		ddb_convert_32bit(c, d, pos, img);
	}

	de_bitmap_write_to_file_finfo(img, d->fi, DE_CREATEFLAG_OPT_IMAGE | d->createflags);

done:
	de_bitmap_destroy(img);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %edx
leaq 0x15ce22(%rip), %rsi    # 0x1a3b98
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x15bba0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
leaq 0x17aec4(%rip), %rsi    # 0x1c1cab
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
leaq 0x17fee8(%rip), %rsi    # 0x1c6cff
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %edx
leaq 0x15cd5c(%rip), %rsi    # 0x1a3ba3
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
cmpq $0x1, -0x50(%rbp)
jne 0x46e68
cmpq $0x1, -0x48(%rbp)
je 0x46e92
cmpq $0x1, -0x50(%rbp)
jne 0x46e76
cmpq $0x4, -0x48(%rbp)
je 0x46e92
cmpq $0x8, -0x50(%rbp)
jne 0x46e84
cmpq $0x1, -0x48(%rbp)
je 0x46e92
cmpq $0x20, -0x50(%rbp)
jne 0x46e94
cmpq $0x1, -0x48(%rbp)
jne 0x46e94
jmp 0x46eb7
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %edx
movq -0x48(%rbp), %rax
movl %eax, %ecx
leaq 0x15cd08(%rip), %rsi    # 0x1a3bb3
movb $0x0, %al
callq 0x15bfb0
jmp 0x47058
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x18689e(%rip), %rsi    # 0x1cd764
movb $0x0, %al
callq 0x15b0d0
movq -0x50(%rbp), %rax
imulq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xc(%rax), %eax
cmpl $0x0, %eax
je 0x46f3b
cmpq $0x1, -0x58(%rbp)
jne 0x46f3b
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0x46f3b
cmpq $0x5a, -0x30(%rbp)
je 0x46f09
cmpq $0x80, -0x30(%rbp)
jne 0x46f3b
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x15ccc4(%rip), %rsi    # 0x1a3bf8
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x46f56
jmp 0x47058
movq -0x10(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
cqto
idivq -0x50(%rbp)
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x58(%rbp), %r9
movl $0x3, %r8d
movl $0x1, %eax
cmpq $0x1, %r9
cmovel %eax, %r8d
callq 0x16b7f0
movq %rax, -0x60(%rbp)
cmpq $0x1, -0x50(%rbp)
jne 0x46fca
cmpq $0x1, -0x48(%rbp)
jne 0x46fca
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movq -0x60(%rbp), %rcx
xorl %r8d, %r8d
callq 0x16bee0
jmp 0x4703d
cmpq $0x1, -0x50(%rbp)
jne 0x46fef
cmpq $0x4, -0x48(%rbp)
jne 0x46fef
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x60(%rbp), %rcx
callq 0x47070
jmp 0x4703b
cmpq $0x8, -0x50(%rbp)
jne 0x47014
cmpq $0x1, -0x48(%rbp)
jne 0x47014
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x60(%rbp), %rcx
callq 0x47100
jmp 0x47039
cmpq $0x20, -0x50(%rbp)
jne 0x47037
cmpq $0x1, -0x48(%rbp)
jne 0x47037
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x60(%rbp), %rcx
callq 0x472a0
jmp 0x47039
jmp 0x4703b
jmp 0x4703d
movq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
orl $0x2, %edx
callq 0x16afa0
movq -0x60(%rbp), %rdi
callq 0x16af60
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)