// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/pict.c
// Function: get_pixdata_size
static int get_pixdata_size(deark *c, lctx *d, struct fmtutil_macbitmap_info *bi,
	i64 pos1, i64 *pixdata_size)
{
	i64 pos;
	i64 j;
	i64 bytecount;
	int retval = 0;

	pos = pos1;
	de_dbg(c, "PixData at %"I64_FMT, pos);
	de_dbg_indent(c, 1);

	if(bi->height<0 || bi->height>65535) {
		de_err(c, "Invalid bitmap height (%"I64_FMT")", (i64)bi->height);
		goto done;
	}

	// Make sure rowbytes is sane. We use it to decide how much memory to allocate.
	// Note: I've seen valid bitmaps with as many as 284 extra bytes per row.
	if(bi->rowbytes > (bi->npwidth * bi->pixelsize)/8 + 1000) {
		de_err(c, "Bad rowBytes value (%d)", (int)bi->rowbytes);
		goto done;
	}

	if(bi->packing_type>=3 || (bi->packing_type==0 && bi->rowbytes>=8)) {
		for(j=0; j<bi->height; j++) {
			if(bi->rowbytes > 250) {
				bytecount = de_getu16be_p(&pos);
			}
			else {
				bytecount = (i64)de_getbyte_p(&pos);
			}
			pos += bytecount;
		}
	}
	else if(bi->packing_type==1 || (bi->packing_type==0 && bi->rowbytes<8)) {
		pos += bi->rowbytes * bi->height; // uncompressed
	}
	else {
		de_err(c, "Unsupported packing type: %d", (int)bi->packing_type);
		goto done;
	}

	*pixdata_size = pos - pos1;
	de_dbg(c, "PixData size: %"I64_FMT, (i64)*pixdata_size);
	retval = 1;

done:
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0xba7b0(%rip), %rsi     # 0x1c26ba
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jl 0x107f38
movq -0x18(%rbp), %rax
cmpq $0xffff, 0x20(%rax)     # imm = 0xFFFF
jle 0x107f57
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0xba77e(%rip), %rsi     # 0x1c26c9
movb $0x0, %al
callq 0x15bfb0
jmp 0x1080c7
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
imulq 0x40(%rcx), %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x50(%rbp), %rax
addq $0x3e8, %rcx            # imm = 0x3E8
cmpq %rcx, %rax
jle 0x107fb0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
leaq 0xba741(%rip), %rsi     # 0x1c26e5
movb $0x0, %al
callq 0x15bfb0
jmp 0x1080c7
movq -0x18(%rbp), %rax
cmpq $0x3, 0x30(%rax)
jge 0x107fd0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x10803e
movq -0x18(%rbp), %rax
cmpq $0x8, (%rax)
jl 0x10803e
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jge 0x10803c
movq -0x18(%rbp), %rax
cmpq $0xfa, (%rax)
jle 0x10800a
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165210
movq %rax, -0x40(%rbp)
jmp 0x108022
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x107fd8
jmp 0x108098
movq -0x18(%rbp), %rax
cmpq $0x1, 0x30(%rax)
je 0x10805e
movq -0x18(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x108078
movq -0x18(%rbp), %rax
cmpq $0x8, (%rax)
jge 0x108078
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
imulq 0x20(%rcx), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x108096
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, %edx
leaq 0xba670(%rip), %rsi     # 0x1c26fd
movb $0x0, %al
callq 0x15bfb0
jmp 0x1080c7
jmp 0x108098
movq -0x30(%rbp), %rcx
subq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
leaq 0xba661(%rip), %rsi     # 0x1c271a
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x44(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop