// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq (%rdi), %r14
movl $0x480, %esi            # imm = 0x480
movq %r14, %rdi
callq 0xe8b2b
movq %rax, %r15
movq 0x28(%rbx), %r12
movl 0x18(%rbx), %eax
andl $-0x2, %eax
cmpl $0x9a, %eax
jne 0xb2c29
movq 0x10(%rbx), %rsi
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0xf94b0
addq $0x4, %r12
movq 0x10(%rbx), %rsi
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0xf950c
leaq 0xa(%r12), %r13
cmpl $0x0, 0x6c(%r15)
je 0xb2c60
movq 0x10(%rbx), %rsi
movq %r14, %rdi
movq %r15, %rdx
movq %r13, %rcx
callq 0xf9623
addq $0x2e, %r12
movq %r12, %r13
movl 0x18(%rbx), %eax
leal -0x90(%rax), %ecx
cmpl $0x9, %ecx
ja 0xb2ccd
movl $0x303, %edx            # imm = 0x303
btl %ecx, %edx
jae 0xb2ccd
cmpl $0x0, 0x6c(%r15)
je 0xb2c8f
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x70(%r15)
jmp 0xb2ce2
cmpl $0x9, %ecx
ja 0xb2ccd
btl %ecx, %edx
jae 0xb2ccd
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)
jmp 0xb2ce2
andl $-0x2, %eax
cmpl $0x9a, %eax
jne 0xb2ce2
cmpl $0x0, 0x6c(%r15)
je 0xb2ef5
cmpl $0x0, 0x70(%r15)
je 0xb2d0d
movq 0x10(%rbx), %rsi
leaq 0x8(%rsp), %r8
movq %r14, %rdi
movq %r15, %rdx
movq %r13, %rcx
callq 0xf9824
testl %eax, %eax
je 0xb2f06
addq 0x8(%rsp), %r13
leaq 0x8421b(%rip), %rsi     # 0x136f2f
movq %r14, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%r14), %rdi
leaq 0x84221(%rip), %rcx     # 0x136f5a
leaq 0x20(%rsp), %r12
movq %r13, %rsi
movq %r12, %rdx
callq 0xb260a
leaq 0x8(%r13), %rsi
movq 0x18(%r14), %rdi
leaq 0x8420a(%rip), %rcx     # 0x136f62
movq %r12, %rdx
callq 0xb260a
leaq 0x10(%r13), %rax
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
movq 0x18(%r14), %rdi
callq 0xeeb91
leaq 0x841ee(%rip), %rsi     # 0x136f6a
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
addq $0x12, %r13
movl $0xffffff6f, %eax       # imm = 0xFFFFFF6F
addl 0x18(%rbx), %eax
cmpl $0xa, %eax
ja 0xb2e2f
movl $0x501, %ecx            # imm = 0x501
btl %eax, %ecx
jae 0xb2e2f
leaq 0x8411b(%rip), %rsi     # 0x136ed6
movq %r14, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xeeb67
movq %rax, %r12
leaq 0x83b5d(%rip), %rsi     # 0x136948
movq %r14, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
cmpq $0x2, %r12
jl 0xb2f06
addq %r13, %r12
cmpb $0x0, 0xd6(%r14)
jne 0xb2e32
leaq 0x840c1(%rip), %rsi     # 0x136ee4
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9393
jmp 0xb2e32
movq %r13, %r12
leaq 0x10(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xb3537
testl %eax, %eax
je 0xb2f06
movq %r14, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x10(%r15), %rdx
movq 0x20(%r15), %rcx
testq %rdx, %rdx
je 0xb2ec8
testq %rcx, %rcx
je 0xb2ec6
movq %r14, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
callq 0xf1db1
testl %eax, %eax
je 0xb2ed9
movq 0x40(%r15), %rdx
cmpq $0x20, %rdx
ja 0xb2fa3
movabsq $0x101010116, %rax      # imm = 0x101010116
btq %rdx, %rax
jae 0xb2fa3
movl 0x74(%r15), %esi
movq 0x38(%r15), %rax
testl %esi, %esi
je 0xb2f23
testq %rax, %rax
je 0xb2f29
leaq 0x8410e(%rip), %rsi     # 0x136fc6
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9295
jmp 0xb2ed9
xorl %ecx, %ecx
leaq 0x840ad(%rip), %rsi     # 0x136f7c
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8faa
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
addq 0x10(%rsp), %r12
subq 0x28(%rbx), %r12
movq %r12, 0x30(%rbx)
jmp 0xb2f0a
leaq 0x83fa0(%rip), %rsi     # 0x136e9c
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9295
movb $0x1, 0x38(%rbx)
movq %r14, %rdi
movq %r15, %rsi
callq 0xe8be2
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
cmpq $0x10, %rax
jne 0xb2eb1
movq 0x48(%r15), %rax
cmpq $0x4, %rax
ja 0xb2fb2
movl $0x1a, %ecx
btq %rax, %rcx
jae 0xb2fb2
movq 0x50(%r15), %rcx
cmpq $0x8, %rcx
ja 0xb2ff7
movl $0x136, %edi            # imm = 0x136
btq %rcx, %rdi
jae 0xb2ff7
movq 0x30(%r15), %r8
cmpq $0x4, %r8
ja 0xb3008
cmpq $0x2, %r8
je 0xb3008
testl %esi, %esi
je 0xb2fbe
cmpq $0x1, %r8
ja 0xb304d
cmpq $0x8, %rdx
ja 0xb304d
movl $0x116, %esi            # imm = 0x116
btq %rdx, %rsi
jae 0xb304d
xorq $0x1, %rax
xorq %rdx, %rcx
jmp 0xb2fdf
leaq 0x83ff5(%rip), %rsi     # 0x136f9f
movq %r14, %rdi
jmp 0xb2ebd
leaq 0x8402c(%rip), %rsi     # 0x136fe5
jmp 0xb2eb8
cmpq $0x1, %r8
je 0xb2fd0
cmpq $0x4, %r8
je 0xb301a
cmpq $0x3, %r8
jne 0xb304d
xorq $0x10, %rdx
xorq $0x3, %rax
orq %rdx, %rax
xorq $0x5, %rcx
orq %rax, %rcx
jne 0xb304d
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xb36a3
jmp 0xb2ed9
leaq 0x8400b(%rip), %rsi     # 0x137009
movq %r14, %rdi
movl %ecx, %edx
jmp 0xb2ebd
leaq 0x8401e(%rip), %rsi     # 0x13702d
movq %r14, %rdi
movl %r8d, %edx
jmp 0xb2ebd
cmpq $0x20, %rdx
jne 0xb304d
cmpq $0x4, %rax
je 0xb3034
cmpq $0x3, %rax
jne 0xb304d
cmpq $0x8, %rcx
je 0xb2fe4
jmp 0xb304d
cmpq $0x8, %rcx
jne 0xb304d
leaq 0x8400d(%rip), %rsi     # 0x13704e
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8faa
jmp 0xb2fe4
leaq 0x821bb(%rip), %rsi     # 0x13520f
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0xb2ed9