// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/grob.c
// Function: grob_read_binary_bitmap
static void grob_read_binary_bitmap(deark *c, lctx *d, dbuf *inf, i64 pos)
{
	i64 h_logical;
	i64 rowspan;
	i64 pdwidth;
	de_bitmap *img = NULL;
	de_color pal[256];

	if(d->num_planes<=1) {
		de_convert_and_write_image_bilevel2(inf, pos, d->w, d->h_phys, (d->w+7)/8,
			DE_CVTF_WHITEISZERO|DE_CVTF_LSBFIRST, NULL, 0);
		return;
	}
	if(d->num_planes>8) goto done;

	if((d->h_phys % d->num_planes) != 0) {
		de_warn(c, "Number of rows is not divisible by number of planes. The grob:planes "
			"setting is probably not correct.");
	}
	h_logical = d->h_phys/d->num_planes;

	if(!de_good_image_dimensions(c, d->w, h_logical))
		goto done;

	de_dbg(c, "logical dimensions: %d"DE_CHAR_TIMES"%d", (int)d->w, (int)h_logical);

	rowspan = (d->w+7)/8;
	pdwidth = rowspan * 8;
	img = de_bitmap_create2(c, d->w, pdwidth, h_logical, 1);

	de_zeromem(pal, sizeof(pal));
	de_make_grayscale_palette(pal, 1ULL<<d->num_planes, 0x1);

	de_convert_image_paletted_planar(inf, pos, d->num_planes,
		rowspan, h_logical*rowspan, pal, img, 0x1 | (d->grayscale_lsb?0x02:0));

	de_bitmap_write_to_file_finfo(img, NULL, 0);
done:
	de_bitmap_destroy(img);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x1, 0x18(%rax)
jg 0x76de1
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x458(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %rax
addq $0x7, %rax
movl $0x8, %r8d
cqto
idivq %r8
movq -0x458(%rbp), %rdx
movq %rax, %r8
movl $0x3, %r9d
xorl %eax, %eax
xorl %eax, %eax
movq $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x16c000
jmp 0x76f51
movq -0x18(%rbp), %rax
cmpq $0x8, 0x18(%rax)
jle 0x76df1
jmp 0x76f48
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cqto
idivq 0x18(%rcx)
cmpq $0x0, %rdx
je 0x76e1b
movq -0x10(%rbp), %rdi
leaq 0x135259(%rip), %rsi    # 0x1ac06d
movb $0x0, %al
callq 0x15bc10
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cqto
idivq 0x18(%rcx)
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x30(%rbp), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x76e4f
jmp 0x76f48
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
movq -0x30(%rbp), %rax
movl %eax, %ecx
leaq 0x13526a(%rip), %rsi    # 0x1ac0d3
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq (%rax), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
shlq $0x3, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x40(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x1, %r8d
callq 0x16b7f0
movq %rax, -0x48(%rbp)
leaq -0x450(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x19140
leaq -0x450(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
movl $0x1, %esi
shlq %cl, %rsi
movl $0x1, %edx
callq 0x16d580
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
imulq -0x38(%rbp), %r8
leaq -0x450(%rbp), %r9
movq -0x48(%rbp), %r10
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ebx
xorl %eax, %eax
movl $0x2, %r11d
cmpl $0x0, %ebx
cmovnel %r11d, %eax
orl $0x1, %eax
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x16c690
movq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x16afa0
movq -0x48(%rbp), %rdi
callq 0x16af60
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %rbp
retq
nopl (%rax,%rax)