// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq %rdx, 0x8(%rsp)
leaq 0x7ceec(%rip), %rsi     # 0x129ab8
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movq 0x20(%r12), %r8
cmpq $0x10000, %r8           # imm = 0x10000
jb 0xacc09
leaq 0x7ced2(%rip), %rsi     # 0x129ac7
movq %rbx, %rdi
movq %r8, %rdx
xorl %eax, %eax
callq 0xdf2a5
xorl %ebp, %ebp
jmp 0xaccf0
movq 0x40(%r12), %rax
imulq 0x10(%r12), %rax
movq (%r12), %rcx
pushq $0x8
popq %rsi
cqto
idivq %rsi
addq $0x3e8, %rax            # imm = 0x3E8
cmpq %rax, %rcx
jle 0xacc45
leaq 0x7ceb1(%rip), %rsi     # 0x129ae3
xorl %ebp, %ebp
movq %rbx, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0xdf2a5
jmp 0xaccf0
movq 0x30(%r12), %rdx
cmpq $0x2, %rdx
jg 0xacc63
testq %rdx, %rdx
setne %al
cmpq $0x8, %rcx
setl %sil
orb %al, %sil
jne 0xaccaf
movq %r14, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x8(%rsp), %r13
movq %r15, %rcx
cmpq %r8, %r14
jge 0xaccd1
cmpq $0xfb, (%r12)
movq 0x18(%rbx), %rdi
movq %r13, %rsi
jl 0xacc93
callq 0xe3f6e
movq %rax, %rcx
jmp 0xacc9b
callq 0xe3f2a
movzbl %al, %ecx
addq 0x8(%rsp), %rcx
movq %rcx, 0x8(%rsp)
incq %r14
movq 0x20(%r12), %r8
jmp 0xacc73
cmpq $0x1, %rdx
je 0xaccc0
testq %rdx, %rdx
jne 0xacd0c
cmpq $0x7, %rcx
jg 0xacd0c
movq %r14, 0x10(%rsp)
imulq %r8, %rcx
addq %r15, %rcx
movq %rcx, 0x8(%rsp)
subq %r15, %rcx
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
leaq 0x7ce35(%rip), %rsi     # 0x129b18
movq %rbx, %rdi
movq %rcx, %rdx
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7cde8(%rip), %rsi     # 0x129afb
xorl %ebp, %ebp
movq %rbx, %rdi
jmp 0xacc39