// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/pict.c
// Function: decode_bitmap
static int decode_bitmap(deark *c, lctx *d, struct fmtutil_macbitmap_info *bi, i64 pos)
{
	i64 j;
	dbuf *unc_pixels = NULL;
	de_bitmap *img = NULL;
	de_finfo *fi = NULL;
	i64 bytecount;
	i64 bitmapsize;
	int dst_nsamples;
	struct de_dfilter_in_params dcmpri;
	struct de_dfilter_out_params dcmpro;
	struct de_dfilter_results dres;

	de_dfilter_init_objects(c, &dcmpri, &dcmpro, &dres);

	bi->rowspan = bi->rowbytes;
	if(bi->pixelsize==32 && bi->cmpcount==3 && bi->cmpsize==8) {
		bi->rowspan = (bi->rowbytes/4)*3;
	}

	bitmapsize = bi->height * bi->rowspan;
	unc_pixels = dbuf_create_membuf(c, bitmapsize, 1);
	dbuf_enable_wbuffer(unc_pixels);

	dcmpri.f = c->infile;
	dcmpro.f = unc_pixels;

	for(j=0; j<bi->height; j++) {
		if(bi->packing_type==1 || bi->rowbytes<8) {
			bytecount = bi->rowbytes;
		}
		else if(bi->rowbytes > 250) {
			bytecount = de_getu16be_p(&pos);
		}
		else {
			bytecount = (i64)de_getbyte_p(&pos);
		}

		if(bi->packing_type==1 || bi->rowbytes<8) {
			dbuf_copy(c->infile, pos, bytecount, unc_pixels);
		}
		else if(bi->packing_type==3 && bi->pixelsize==16) {
			struct de_packbits_params pbparams;

			de_zeromem(&pbparams, sizeof(struct de_packbits_params));
			pbparams.nbytes_per_unit = 2;
			dcmpri.pos = pos;
			dcmpri.len = bytecount;
			fmtutil_decompress_packbits_ex(c, &dcmpri, &dcmpro, &dres, &pbparams);
		}
		else {
			dcmpri.pos = pos;
			dcmpri.len = bytecount;
			fmtutil_decompress_packbits_ex(c, &dcmpri, &dcmpro, &dres, NULL);
		}

		// Make sure the data decompressed to the right number of bytes.
		if(dbuf_get_length(unc_pixels) != (j+1)*bi->rowspan) {
			dbuf_truncate(unc_pixels, (j+1)*bi->rowspan);
		}

		pos += bytecount;
	}
	dbuf_flush(unc_pixels);

	dst_nsamples = 3;
	if(bi->uses_pal) {
		if(de_is_grayscale_palette(bi->pal, bi->num_pal_entries)) {
			dst_nsamples = 1;
		}
	}

	img = de_bitmap_create2(c, bi->npwidth, bi->pdwidth, bi->height, dst_nsamples);

	fi = de_finfo_create(c);

	if(bi->hdpi>=1.0 && bi->vdpi>=1.0) {
		fi->density.code = DE_DENSITY_DPI;
		fi->density.xdens = bi->hdpi;
		fi->density.ydens = bi->vdpi;
	}

	if(bi->uses_pal) {
		decode_bitmap_paletted(c, d, bi, unc_pixels, img, pos);
	}
	else {
		if(bi->pixelsize==16) {
			decode_bitmap_rgb16(c, d, bi, unc_pixels, img, pos);
		}
		else {
			decode_bitmap_rgb24(c, d, bi, unc_pixels, img, pos);
		}
	}

	de_bitmap_write_to_file_finfo(img, fi, DE_CREATEFLAG_OPT_IMAGE);

	de_bitmap_destroy(img);
	de_finfo_destroy(c, fi);
	dbuf_close(unc_pixels);
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0xf0(%rbp), %rcx
callq 0x1773f0
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x20, 0x40(%rax)
jne 0x1086cb
movq -0x18(%rbp), %rax
cmpq $0x3, 0x48(%rax)
jne 0x1086cb
movq -0x18(%rbp), %rax
cmpq $0x8, 0x50(%rax)
jne 0x1086cb
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl $0x4, %ecx
cqto
idivq %rcx
imulq $0x3, %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
imulq 0x8(%rcx), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jge 0x1088b2
movq -0x18(%rbp), %rax
cmpq $0x1, 0x30(%rax)
je 0x108745
movq -0x18(%rbp), %rax
cmpq $0x8, (%rax)
jge 0x108752
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x108790
movq -0x18(%rbp), %rax
cmpq $0xfa, (%rax)
jle 0x108776
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movq %rax, -0x48(%rbp)
jmp 0x10878e
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movq %rax, -0x48(%rbp)
jmp 0x108790
movq -0x18(%rbp), %rax
cmpq $0x1, 0x30(%rax)
je 0x1087a5
movq -0x18(%rbp), %rax
cmpq $0x8, (%rax)
jge 0x1087c3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x166070
jmp 0x10885c
movq -0x18(%rbp), %rax
cmpq $0x3, 0x30(%rax)
jne 0x10882a
movq -0x18(%rbp), %rax
cmpq $0x10, 0x40(%rax)
jne 0x10882a
leaq -0xf4(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x19140
movl $0x2, -0xf4(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0xf0(%rbp), %rcx
leaq -0xf4(%rbp), %r8
callq 0x177e10
jmp 0x10885a
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0xf0(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x177e10
jmp 0x10885c
movq -0x30(%rbp), %rdi
callq 0x169790
movq -0x28(%rbp), %rcx
addq $0x1, %rcx
movq -0x18(%rbp), %rdx
imulq 0x8(%rdx), %rcx
cmpq %rcx, %rax
je 0x108895
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x1, %rsi
movq -0x18(%rbp), %rax
imulq 0x8(%rax), %rsi
callq 0x168900
movq -0x48(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x10871e
movq -0x30(%rbp), %rdi
callq 0x167c30
movl $0x3, -0x54(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x74(%rax)
je 0x1088f2
movq -0x18(%rbp), %rdi
addq $0x80, %rdi
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rsi
callq 0x16aa20
cmpl $0x0, %eax
je 0x1088f0
movl $0x1, -0x54(%rbp)
jmp 0x1088f2
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rcx
movl -0x54(%rbp), %r8d
callq 0x16b7f0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movsd 0x58(%rax), %xmm0
movsd 0x9887f(%rip), %xmm1    # 0x1a11b8
ucomisd %xmm1, %xmm0
jb 0x10898b
movq -0x18(%rbp), %rax
movsd 0x60(%rax), %xmm0
movsd 0x98868(%rip), %xmm1    # 0x1a11b8
ucomisd %xmm1, %xmm0
jb 0x10898b
movq -0x40(%rbp), %rax
movl $0x2, 0x78(%rax)
movq -0x18(%rbp), %rax
movsd 0x58(%rax), %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x80(%rax)
movq -0x18(%rbp), %rax
movsd 0x60(%rax), %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x88(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x74(%rax)
je 0x1089b4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0x108a40
jmp 0x1089fd
movq -0x18(%rbp), %rax
cmpq $0x10, 0x40(%rax)
jne 0x1089de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0x108aa0
jmp 0x1089fb
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0x108ba0
jmp 0x1089fd
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0x2, %edx
callq 0x16afa0
movq -0x38(%rbp), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x15d260
movq -0x30(%rbp), %rdi
callq 0x1676a0
movl $0x1, %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax)