// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/bsave.c
// Function: do_2color
static void do_2color(deark *c, lctx *d)
{
	i64 w, h;
	i64 j;
	i64 src_rowspan;
	i64 pos;
	de_bitmap *img = NULL;

	pos = BSAVE_HDRSIZE;

	if(d->has_dimension_fields) {
		// 11-byte header that includes width & height
		w = d->metrics.maybe_bitsperrow;
		h = d->metrics.maybe_nrows;
		pos+=4;
	}
	else if(!d->interlaced) {
		w = get_width(c, d, 640);
		src_rowspan = (w+7)/8;
		h = d->data_size / src_rowspan;
		h = get_height(c, d, h);
	}
	else {
		w = get_width(c, d, 640);
		h = get_height(c, d, 200);
	}

	de_dbg_dimensions(c, w, h);
	src_rowspan = (w+7)/8;

	if(!de_good_image_dimensions(c, w, h)) goto done;
	img = de_bitmap_create(c, w, h, 1);

	for(j=0; j<h; j++) {
		if(d->interlaced) {
			de_convert_row_bilevel(c->infile, pos + (j%2)*8192 + (j/2)*src_rowspan,
				img, j, 0);
		}
		else {
			de_convert_row_bilevel(c->infile, pos + j*src_rowspan, img, j, 0);
		}
	}

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x7, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x2d(%rax)
je 0x4c0b9
movq -0x10(%rbp), %rax
movq 0x440(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x448(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
jmp 0x4c146
movq -0x10(%rbp), %rax
cmpb $0x0, 0x2c(%rax)
jne 0x4c118
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x280, %edx            # imm = 0x280
callq 0x4cc30
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
cqto
idivq -0x30(%rbp)
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x4cca0
movq %rax, -0x20(%rbp)
jmp 0x4c144
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x280, %edx            # imm = 0x280
callq 0x4cc30
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0xc8, %edx
callq 0x4cca0
movq %rax, -0x20(%rbp)
jmp 0x4c146
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x15bba0
movq -0x18(%rbp), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x4c188
jmp 0x4c255
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl $0x1, %ecx
callq 0x16b750
movq %rax, -0x40(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x4c246
movq -0x10(%rbp), %rax
cmpb $0x0, 0x2c(%rax)
je 0x4c20b
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
shlq $0xd, %rdx
addq %rdx, %rsi
movq -0x28(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
imulq -0x30(%rbp), %rax
addq %rax, %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
xorl %r8d, %r8d
callq 0x16be90
jmp 0x4c233
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rax
imulq -0x30(%rbp), %rax
addq %rax, %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
xorl %r8d, %r8d
callq 0x16be90
jmp 0x4c235
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x4c1aa
movq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x16afd0
movq -0x40(%rbp), %rdi
callq 0x16af60
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)