// File: /workspace/github_c_makefile_star2_O1/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 0xfa6e0
movq (%r14), %rax
movq 0x40(%r14), %rcx
movq %rax, 0x8(%r14)
cmpq $0x20, %rcx
jne 0xb4269
cmpq $0x3, 0x48(%r14)
jne 0xb4269
cmpq $0x8, 0x50(%r14)
jne 0xb4269
leaq 0x3(%rax), %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
sarq $0x2, %rcx
leaq (%rcx,%rcx,2), %rax
movq %rax, 0x8(%r14)
movq 0x8(%r14), %rsi
imulq 0x20(%r14), %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movl $0x1, %edx
callq 0xf0faf
movq %rax, %r15
movq %rax, %rdi
callq 0xf0e3f
movq 0x18(%rbx), %rax
movq %rax, 0x30(%rsp)
movq %r15, 0x50(%rsp)
cmpq $0x0, 0x20(%r14)
jle 0xb43bc
xorl %ebx, %ebx
leaq 0x68(%rsp), %rbp
leaq 0x10(%rsp), %r12
cmpq $0x1, 0x30(%r14)
je 0xb42c4
movq (%r14), %rax
cmpq $0x7, %rax
jg 0xb42f5
movq (%r14), %r13
movq 0x30(%r14), %rax
cmpq $0x1, %rax
je 0xb42d7
cmpq $0x7, (%r14)
jg 0xb4317
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0xefabc
jmp 0xb437d
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rdi
movq %r12, %rsi
cmpq $0xfb, %rax
jl 0xb43ae
callq 0xef193
movq %rax, %r13
jmp 0xb42c7
cmpq $0x3, %rax
jne 0xb4354
cmpq $0x10, 0x40(%r14)
jne 0xb4354
movl $0x2, 0x24(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %r13, 0x40(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq %rbp, %rcx
leaq 0x24(%rsp), %r8
jmp 0xb4378
movq 0x10(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %r13, 0x40(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0xfacff
movq %r15, %rdi
callq 0xf1d13
incq %rbx
movq 0x8(%r14), %rsi
imulq %rbx, %rsi
cmpq %rsi, %rax
je 0xb439d
movq %r15, %rdi
callq 0xf152a
addq %r13, 0x10(%rsp)
cmpq 0x20(%r14), %rbx
jl 0xb42b4
jmp 0xb43bc
callq 0xef14d
movzbl %al, %r13d
jmp 0xb42c7
movq %r15, %rdi
callq 0xf0ea4
cmpl $0x0, 0x74(%r14)
je 0xb43ec
leaq 0x80(%r14), %rdi
movq 0x78(%r14), %rsi
callq 0xf2544
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
leal 0x1(,%rcx,2), %r8d
jmp 0xb43f2
movl $0x3, %r8d
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
movq 0x20(%r14), %rcx
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0xf2ce6
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
callq 0xea9a9
movsd 0x58(%r14), %xmm0
ucomisd 0x60e92(%rip), %xmm0    # 0x1152b8
jb 0xb444f
movsd 0x60(%r14), %xmm1
ucomisd 0x60e82(%rip), %xmm1    # 0x1152b8
jb 0xb444f
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 0xb44c7
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 0xf35b8
movq %rbx, %rdi
movq 0x28(%rsp), %r14
movq %r14, %rsi
movl $0x2, %edx
callq 0xf2917
movq %rbx, %rdi
callq 0xf28d4
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0xea9b3
movq %r15, %rdi
callq 0xf0b13
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 0xb455d
testq %rax, %rax
jle 0xb4483
xorl %r13d, %r13d
cmpq $0x0, 0x18(%r14)
jle 0xb454f
movl $0x1, %r12d
xorl %ebp, %ebp
movq 0x8(%r14), %rax
imulq %r13, %rax
leaq (%r12,%rax), %rsi
decq %rsi
movq %r15, %rdi
callq 0xef0d5
movl %eax, %ebx
movq 0x8(%r14), %rsi
imulq %r13, %rsi
addq %r12, %rsi
movq %r15, %rdi
callq 0xef0d5
movzbl %bl, %ecx
movq 0x18(%rsp), %rbx
shll $0x8, %ecx
movzbl %al, %edi
orl %ecx, %edi
callq 0xecf84
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %eax, %ecx
callq 0xf2afd
incq %rbp
addq $0x2, %r12
cmpq 0x18(%r14), %rbp
jl 0xb44f1
incq %r13
cmpq 0x20(%r14), %r13
jl 0xb44e2
jmp 0xb4483
testq %rax, %rax
jle 0xb4483
xorl %ebp, %ebp
movq 0x18(%r14), %rax
testq %rax, %rax
jle 0xb4621
xorl %r13d, %r13d
movq 0x48(%r14), %rcx
addq $-0x3, %rcx
imulq %rax, %rcx
movq 0x8(%r14), %rsi
imulq %rbp, %rsi
addq %r13, %rsi
addq %rcx, %rsi
movq %r15, %rdi
callq 0xef0d5
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 0xef0d5
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 0xef0d5
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 0xf2afd
incq %r13
movq 0x18(%r14), %rax
cmpq %rax, %r13
jl 0xb4578
incq %rbp
cmpq 0x20(%r14), %rbp
jl 0xb4568
jmp 0xb4483
nop