// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/pict.c
// Function: handler_98_9a
static void handler_98_9a(struct item_handler_data *h)
{
	struct fmtutil_macbitmap_info *bi = NULL;
	i64 pixdata_size = 0;
	i64 colortable_size = 0;
	int retval = 0;
	i64 pos;
	deark *c = h->c;

	bi = de_malloc(c, sizeof(struct fmtutil_macbitmap_info));
	pos = h->data_pos;

	if(h->opcode==0x9a || h->opcode==0x9b) {
		fmtutil_macbitmap_read_baseaddr(c, h->inf, bi, pos);
		pos += 4;
	}

	fmtutil_macbitmap_read_rowbytes_and_bounds(c, h->inf, bi, pos);
	pos += 10;

	if(bi->pixmap_flag) {
		fmtutil_macbitmap_read_pixmap_only_fields(c, h->inf, bi, pos);
		pos += 36;
	}

	if((h->opcode==0x90 || h->opcode==0x91 || h->opcode==0x98 || h->opcode==0x99) && bi->pixmap_flag) {
		// Prepare to read the palette
		bi->uses_pal = 1;
		bi->has_colortable = 1;
	}
	else if((h->opcode==0x90 || h->opcode==0x91 || h->opcode==0x98 || h->opcode==0x99) && !bi->pixmap_flag) {
		// Settings implied by the lack of a PixMap header
		bi->pixelsize = 1;
		bi->cmpcount = 1;
		bi->cmpsize = 1;
		bi->uses_pal = 1;
		bi->num_pal_entries = 2;
		bi->pal[0] = DE_STOCKCOLOR_WHITE;
		bi->pal[1] = DE_STOCKCOLOR_BLACK;
	}
	else if((h->opcode==0x9a || h->opcode==0x9b) && !bi->pixmap_flag) {
		de_err(c, "DirectBitsRect image without PixMap flag is not supported");
		goto done;
	}

	if(bi->has_colortable) {
		if(!fmtutil_macbitmap_read_colortable(c, h->inf, bi, pos, &colortable_size)) goto done;
		pos += colortable_size;
	}

	read_src_dst_mode(c, h->d, bi, pos);
	pos += 18;

	if(h->opcode==0x91 || h->opcode==0x99 || h->opcode==0x9b) {
		i64 rgnsize;

		de_dbg(c, "region at %"I64_FMT, pos);
		de_dbg_indent(c, 1);
		rgnsize = de_getu16be(pos);
		de_dbg(c, "region size: %d", (int)rgnsize);
		de_dbg_indent(c, -1);
		if(rgnsize<2) goto done;
		pos += rgnsize;
		if(!c->padpix) {
			de_info(c, "Note: Ignoring clipping region. Output image might have "
				"extraneous pixels.");
		}
	}

	if(!get_pixdata_size(c, h->d, bi, pos, &pixdata_size)) {
		goto done;
	}
	decode_pixdata(c, h->d, bi, pos);
	pos += pixdata_size;

	h->data_len = pos - h->data_pos;

	retval = 1;

done:
	if(!retval) {
		h->fatal_errflag = 1;
	}
	de_free(c, bi);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movq %rax, (%rsp)
movq (%rdi), %r14
movl $0x480, %esi            # imm = 0x480
movq %r14, %rdi
callq 0xe969b
movq %rax, %r15
movq 0x28(%rbx), %r13
movl 0x18(%rbx), %eax
andl $-0x2, %eax
cmpl $0x9a, %eax
jne 0xb371d
movq 0x10(%rbx), %rsi
movq %r14, %rdi
movq %r15, %rdx
movq %r13, %rcx
callq 0xf99bd
addq $0x4, %r13
movq 0x10(%rbx), %rsi
movq %r14, %rdi
movq %r15, %rdx
movq %r13, %rcx
callq 0xf9a19
leaq 0xa(%r13), %r12
cmpl $0x0, 0x6c(%r15)
je 0xb3753
movq 0x10(%rbx), %rsi
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0xf9b30
addq $0x2e, %r13
movq %r13, %r12
movl 0x18(%rbx), %eax
leal -0x90(%rax), %ecx
cmpl $0x9, %ecx
ja 0xb3793
movl $0x303, %edx            # imm = 0x303
btl %ecx, %edx
jae 0xb3793
cmpl $0x0, 0x6c(%r15)
je 0xb3782
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x70(%r15)
jmp 0xb37ec
cmpl $0x9, %ecx
ja 0xb3793
btl %ecx, %edx
jae 0xb3793
cmpl $0x0, 0x6c(%r15)
je 0xb37ba
andl $-0x2, %eax
cmpl $0x9a, %eax
jne 0xb37ec
cmpl $0x0, 0x6c(%r15)
jne 0xb37ec
leaq 0x83327(%rip), %rsi     # 0x136ad2
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xb39da
movl $0x1, %eax
movq %rax, 0x40(%r15)
movq %rax, 0x48(%r15)
movq %rax, 0x50(%r15)
movl $0x1, 0x74(%r15)
movq $0x2, 0x78(%r15)
movabsq $-0xffffff00000001, %rax # imm = 0xFF000000FFFFFFFF
movq %rax, 0x80(%r15)
cmpl $0x0, 0x70(%r15)
je 0xb3814
movq 0x10(%rbx), %rsi
movq %rsp, %r8
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0xf9d2c
testl %eax, %eax
je 0xb39da
addq (%rsp), %r12
leaq 0x10(%rsp), %r13
movq %r12, (%r13)
leaq 0x83341(%rip), %rsi     # 0x136b65
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%r14), %rdi
movq (%r13), %rsi
leaq 0x83343(%rip), %rcx     # 0x136b90
leaq 0x18(%rsp), %rbp
movq %rbp, %rdx
callq 0xb30ef
movq (%r13), %rsi
addq $0x8, %rsi
movq %rsi, (%r13)
movq 0x18(%r14), %rdi
leaq 0x83327(%rip), %rcx     # 0x136b98
movq %rbp, %rdx
callq 0xb30ef
addq $0x8, (%r13)
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xef193
leaq 0x8330f(%rip), %rsi     # 0x136ba0
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
addq $0x12, %r12
movl $0xffffff6f, %eax       # imm = 0xFFFFFF6F
addl 0x18(%rbx), %eax
cmpl $0xa, %eax
ja 0xb3948
movl $0x501, %ecx            # imm = 0x501
btl %eax, %ecx
jae 0xb3948
leaq 0x8323c(%rip), %rsi     # 0x136b0c
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%r14), %rdi
movq %r12, %rsi
callq 0xef169
movq %rax, %r13
leaq 0x82c7e(%rip), %rsi     # 0x13657e
movq %r14, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpq $0x2, %r13
jl 0xb393e
addq %r13, %r12
cmpb $0x0, 0xd6(%r14)
jne 0xb393e
leaq 0x831e6(%rip), %rsi     # 0x136b1a
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9ef5
cmpq $0x2, %r13
jl 0xb39da
leaq 0x8(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xb4094
testl %eax, %eax
je 0xb39da
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x10(%r15), %rdx
testq %rdx, %rdx
je 0xb39e0
movq 0x20(%r15), %rax
testq %rax, %rax
je 0xb39e0
movq %r14, %rdi
movq %rdx, %rsi
movq %rax, %rdx
callq 0xf241d
testl %eax, %eax
je 0xb39f5
movq 0x40(%r15), %rax
cmpq $0x20, %rax
ja 0xb3ad5
movabsq $0x101010116, %rcx      # imm = 0x101010116
btq %rax, %rcx
jae 0xb3ad5
movl 0x74(%r15), %esi
movq 0x38(%r15), %rcx
testl %esi, %esi
je 0xb3a29
testq %rcx, %rcx
je 0xb3a2f
movl 0x38(%r15), %edx
leaq 0x8322e(%rip), %rsi     # 0x136bfc
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xb39f5
movb $0x1, 0x38(%rbx)
jmp 0xb3a0f
movl 0x20(%r15), %ecx
leaq 0x831c7(%rip), %rsi     # 0x136bb2
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9b27
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
addq 0x8(%rsp), %r12
subq 0x28(%rbx), %r12
movq %r12, 0x30(%rbx)
movq %r14, %rdi
movq %r15, %rsi
callq 0xe9752
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x10, %rcx
jne 0xb39c3
movq 0x48(%r15), %rdx
cmpq $0x4, %rdx
ja 0xb3ae6
movl $0x1a, %ecx
btq %rdx, %rcx
jae 0xb3ae6
movq 0x50(%r15), %rcx
cmpq $0x8, %rcx
ja 0xb3b9a
movl $0x136, %edi            # imm = 0x136
btq %rcx, %rdi
jae 0xb3b9a
movq 0x30(%r15), %r8
cmpq $0x4, %r8
ja 0xb3bab
cmpq $0x2, %r8
je 0xb3bab
testl %esi, %esi
sete %dil
cmpq $0x2, %r8
setae %r9b
orb %dil, %r9b
jne 0xb3abb
cmpq $0x8, %rax
ja 0xb3abb
movl $0x116, %edi            # imm = 0x116
btq %rax, %rdi
jae 0xb3abb
movq %rdx, %rdi
xorq $0x1, %rdi
movq %rcx, %r9
xorq %rax, %r9
orq %rdi, %r9
je 0xb3b70
testl %esi, %esi
je 0xb3af5
leaq 0x813bd(%rip), %rsi     # 0x134e83
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xb39f5
leaq 0x830f9(%rip), %rsi     # 0x136bd5
movq %r14, %rdi
movl %eax, %edx
jmp 0xb39d1
leaq 0x8312e(%rip), %rsi     # 0x136c1b
movq %r14, %rdi
jmp 0xb39d1
movq %r8, %rsi
orq $0x2, %rsi
cmpq $0x3, %rsi
jne 0xb3b1f
movq %rax, %rsi
xorq $0x10, %rsi
movq %rdx, %rdi
xorq $0x3, %rdi
orq %rsi, %rdi
movq %rcx, %rsi
xorq $0x5, %rsi
orq %rdi, %rsi
je 0xb3b70
cmpq $0x3, %rdx
jne 0xb3b37
cmpq $0x5, %rcx
jne 0xb3b37
cmpq $0x10, %rax
jne 0xb3b37
cmpq $0x1, %r8
je 0xb3b70
xorq $0x4, %r8
xorq $0x20, %rax
orq %r8, %rax
sete %al
cmpq $0x8, %rcx
jne 0xb3b55
cmpq $0x3, %rdx
jne 0xb3b55
testb %al, %al
jne 0xb3b70
cmpq $0x4, %rdx
sete %sil
cmpq $0x8, %rcx
jne 0xb3abf
andb %al, %sil
je 0xb3abf
cmpq $0x4, %rdx
jne 0xb3b87
leaq 0x83107(%rip), %rsi     # 0x136c84
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9b27
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xb4201
jmp 0xb39f5
leaq 0x8309e(%rip), %rsi     # 0x136c3f
movq %r14, %rdi
movl %ecx, %edx
jmp 0xb39d1
leaq 0x830b1(%rip), %rsi     # 0x136c63
movq %r14, %rdi
movl %r8d, %edx
jmp 0xb39d1