// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %r14
movq %rdx, 0x10(%rsp)
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0x68(%rsp), %rcx
movq %rdi, 0x8(%rsp)
callq 0xfa1dc
movq (%r14), %rsi
movq 0x40(%r14), %rax
movq %rsi, 0x8(%r14)
cmpq $0x20, %rax
jne 0xb370b
cmpq $0x3, 0x48(%r14)
jne 0xb370b
cmpq $0x8, 0x50(%r14)
jne 0xb370b
leaq 0x3(%rsi), %rax
testq %rsi, %rsi
cmovnsq %rsi, %rax
sarq $0x2, %rax
leaq (%rax,%rax,2), %rsi
movq %rsi, 0x8(%r14)
imulq 0x20(%r14), %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movl $0x1, %edx
callq 0xf09c5
movq %rax, %r15
movq %rax, %rdi
callq 0xf0855
movq 0x18(%rbx), %rax
movq %rax, 0x30(%rsp)
movq %r15, 0x50(%rsp)
cmpq $0x0, 0x20(%r14)
jle 0xb3854
xorl %ebx, %ebx
leaq 0x10(%rsp), %r12
leaq 0x68(%rsp), %r13
movq (%r14), %rbp
cmpq $0x1, 0x30(%r14)
sete %al
cmpq $0x8, %rbp
setl %cl
orb %al, %cl
jne 0xb379f
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
movq %r12, %rsi
cmpq $0xfb, %rbp
jb 0xb3787
callq 0xeeb91
movq %rax, %rbp
jmp 0xb378f
callq 0xeeb4b
movzbl %al, %ebp
movq 0x30(%r14), %rax
cmpq $0x1, %rax
je 0xb379f
cmpq $0x7, (%r14)
jg 0xb37e9
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0xef481
movq %r15, %rdi
callq 0xf1701
incq %rbx
movq 0x8(%r14), %rsi
imulq %rbx, %rsi
cmpq %rsi, %rax
je 0xb37d8
movq %r15, %rdi
callq 0xf0f27
addq %rbp, 0x10(%rsp)
cmpq 0x20(%r14), %rbx
jl 0xb3752
jmp 0xb3854
cmpq $0x3, %rax
jne 0xb3826
cmpq $0x10, 0x40(%r14)
movq 0x10(%rsp), %rax
jne 0xb382b
movl $0x2, 0x24(%rsp)
movq %rax, 0x38(%rsp)
movq %rbp, 0x40(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq %r13, %rcx
leaq 0x24(%rsp), %r8
jmp 0xb384a
movq 0x10(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %rbp, 0x40(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xfa801
jmp 0xb37b8
movq %r15, %rdi
callq 0xf08ba
cmpl $0x0, 0x74(%r14)
je 0xb3884
leaq 0x80(%r14), %rdi
movq 0x78(%r14), %rsi
callq 0xf1ed8
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
leal 0x1(,%rcx,2), %r8d
jmp 0xb388a
movl $0x3, %r8d
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
movq 0x20(%r14), %rcx
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0xf26a5
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
callq 0xea504
movsd 0x58(%r14), %xmm0
ucomisd 0x61aaa(%rip), %xmm0    # 0x115368
jb 0xb38e7
movsd 0x60(%r14), %xmm1
ucomisd 0x61a9a(%rip), %xmm1    # 0x115368
jb 0xb38e7
movl $0x2, 0x78(%rax)
movsd %xmm0, 0x80(%rax)
movsd %xmm1, 0x88(%rax)
cmpl $0x0, 0x74(%r14)
movq 0x40(%r14), %rdx
movq %rax, 0x28(%rsp)
je 0xb395f
movq 0x8(%r14), %rcx
subq $-0x80, %r14
movl $0x0, (%rsp)
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %r8
movq 0x18(%rsp), %rbx
movq %rbx, %r9
callq 0xf2f79
movq %rbx, %rdi
movq 0x28(%rsp), %r14
movq %r14, %rsi
movl $0x2, %edx
callq 0xf22d0
movq %rbx, %rdi
callq 0xf228d
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0xea50e
movq %r15, %rdi
callq 0xf052b
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%r14), %rax
cmpq $0x10, %rdx
movq 0x18(%rsp), %rbx
jne 0xb39fd
testq %rax, %rax
jle 0xb391b
movq 0x18(%r14), %rcx
xorl %ebp, %ebp
testq %rcx, %rcx
jle 0xb39f0
movl $0x1, %r12d
xorl %r13d, %r13d
movq 0x8(%r14), %rax
imulq %rbp, %rax
leaq (%r12,%rax), %rsi
decq %rsi
movq %r15, %rdi
callq 0xeead3
movl %eax, %ebx
movq 0x8(%r14), %rsi
imulq %rbp, %rsi
addq %r12, %rsi
movq %r15, %rdi
callq 0xeead3
movzbl %bl, %ecx
movq 0x18(%rsp), %rbx
shll $0x8, %ecx
movzbl %al, %edi
orl %ecx, %edi
callq 0xec947
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movl %eax, %ecx
callq 0xf24ba
incq %r13
movq 0x18(%r14), %rcx
addq $0x2, %r12
cmpq %rcx, %r13
jl 0xb398b
movq 0x20(%r14), %rax
incq %rbp
cmpq %rax, %rbp
jl 0xb397d
jmp 0xb391b
testq %rax, %rax
jle 0xb391b
movq 0x18(%r14), %rcx
xorl %ebp, %ebp
testq %rcx, %rcx
jle 0xb3ac5
xorl %r13d, %r13d
movq 0x48(%r14), %rax
addq $-0x3, %rax
imulq %rcx, %rax
movq 0x8(%r14), %rsi
imulq %rbp, %rsi
addq %r13, %rsi
addq %rax, %rsi
movq %r15, %rdi
callq 0xeead3
movl %eax, %ebx
movq 0x48(%r14), %rax
addq $-0x2, %rax
imulq 0x18(%r14), %rax
movq 0x8(%r14), %rsi
imulq %rbp, %rsi
addq %r13, %rsi
addq %rax, %rsi
movq %r15, %rdi
callq 0xeead3
movl %eax, %r12d
movq 0x48(%r14), %rax
decq %rax
imulq 0x18(%r14), %rax
movq 0x8(%r14), %rsi
imulq %rbp, %rsi
addq %r13, %rsi
addq %rax, %rsi
movq %r15, %rdi
callq 0xeead3
movzbl %bl, %ecx
movq 0x18(%rsp), %rbx
shll $0x10, %ecx
movzbl %r12b, %edx
shll $0x8, %edx
orl %ecx, %edx
movzbl %al, %ecx
orl %edx, %ecx
orl $0xff000000, %ecx       # imm = 0xFF000000
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xf24ba
incq %r13
movq 0x18(%r14), %rcx
cmpq %rcx, %r13
jl 0xb3a18
movq 0x20(%r14), %rax
incq %rbp
cmpq %rax, %rbp
jl 0xb3a0c
jmp 0xb391b
nop