// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/insetpix.c
// Function: do_bitmap
static void do_bitmap(deark *c, lctx *d)
{
	i64 item;
	de_bitmap *img = NULL;
	de_finfo *fi = NULL;

	de_dbg(c, "reading image data");
	de_dbg_indent(c, 1);

	if(!de_good_image_dimensions(c, d->npwidth, d->height)) goto done;

	d->rowspan = d->page_cols/8;
	d->compression_bytes_per_row = (d->rowspan+7)/8; // Just a guess. Spec doesn't say.

	if(c->padpix) {
		d->pdwidth = d->page_cols * d->stp_cols;
	}
	else {
		d->pdwidth = d->npwidth;
	}

	img = de_bitmap_create2(c, d->npwidth, d->pdwidth, d->height, d->is_grayscale?1:3);

	// Read through the items again, this time looking only at the image tiles.
	for(item=0; item<d->item_count; item++) {
		struct insetpix_item_data itd;
		i64 pos;

		pos = 4 + 8*item;
		if(pos+8 > c->infile->len) break;

		insetpix_read_item(c, pos, &itd);
		if(!itd.is_tile) continue;
		insetpix_dbg_item(c, &itd, item);

		de_dbg_indent(c, 1);
		do_render_tile(c, d, img, &itd);
		de_dbg_indent(c, -1);
	}

	fi = de_finfo_create(c);
	fi->density.code = DE_DENSITY_UNK_UNITS;
	fi->density.xdens = (double)d->haspect;
	fi->density.ydens = (double)d->vaspect;
	de_bitmap_write_to_file_finfo(img, fi, DE_CREATEFLAG_OPT_IMAGE);

done:
	de_bitmap_destroy(img);
	de_finfo_destroy(c, fi);
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xfccad(%rip), %rsi     # 0x1b5608
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0xb8993
jmp 0xb8b68
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x10(%rbp), %rax
movq 0xc8(%rax), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x8(%rbp), %rax
cmpb $0x0, 0xd5(%rax)
je 0xb8a0b
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rcx
movq -0x10(%rbp), %rax
imulq 0xc0(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
jmp 0xb8a1b
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
movq -0x10(%rbp), %rax
movl 0xd8(%rax), %r9d
movl $0x3, %r8d
movl $0x1, %eax
cmpl $0x0, %r9d
cmovnel %eax, %r8d
callq 0x16b7f0
movq %rax, -0x20(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jge 0xb8b0c
movq -0x18(%rbp), %rax
shlq $0x3, %rax
addq $0x4, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq $0x8, %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xb8aa0
jmp 0xb8b0c
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0xb7ad0
cmpb $0x0, -0x3f(%rbp)
jne 0xb8ab9
jmp 0xb8afb
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x48(%rbp), %rsi
callq 0xb7bc0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0xb8fc0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xb8a66
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0x1, 0x78(%rax)
movq -0x10(%rbp), %rax
cvtsi2sdq 0x98(%rax), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x80(%rax)
movq -0x10(%rbp), %rax
cvtsi2sdq 0xa0(%rax), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x88(%rax)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x2, %edx
callq 0x16afa0
movq -0x20(%rbp), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)