// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movl $0x480, %esi            # imm = 0x480
callq 0x15b780
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x9a, 0x18(%rax)
je 0x1077ce
movq -0x8(%rbp), %rax
cmpl $0x9b, 0x18(%rax)
jne 0x1077f3
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x175920
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x1759a0
movq -0x30(%rbp), %rax
addq $0xa, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x6c(%rax)
je 0x107847
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x175ba0
movq -0x30(%rbp), %rax
addq $0x24, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x90, 0x18(%rax)
je 0x10787b
movq -0x8(%rbp), %rax
cmpl $0x91, 0x18(%rax)
je 0x10787b
movq -0x8(%rbp), %rax
cmpl $0x98, 0x18(%rax)
je 0x10787b
movq -0x8(%rbp), %rax
cmpl $0x99, 0x18(%rax)
jne 0x1078a0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x6c(%rax)
je 0x1078a0
movq -0x10(%rbp), %rax
movl $0x1, 0x74(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x70(%rax)
jmp 0x107976
movq -0x8(%rbp), %rax
cmpl $0x90, 0x18(%rax)
je 0x1078d4
movq -0x8(%rbp), %rax
cmpl $0x91, 0x18(%rax)
je 0x1078d4
movq -0x8(%rbp), %rax
cmpl $0x98, 0x18(%rax)
je 0x1078d4
movq -0x8(%rbp), %rax
cmpl $0x99, 0x18(%rax)
jne 0x107937
movq -0x10(%rbp), %rax
cmpl $0x0, 0x6c(%rax)
jne 0x107937
movq -0x10(%rbp), %rax
movq $0x1, 0x40(%rax)
movq -0x10(%rbp), %rax
movq $0x1, 0x48(%rax)
movq -0x10(%rbp), %rax
movq $0x1, 0x50(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x74(%rax)
movq -0x10(%rbp), %rax
movq $0x2, 0x78(%rax)
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x80(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movl $0xff000000, 0x84(%rax) # imm = 0xFF000000
jmp 0x107974
movq -0x8(%rbp), %rax
cmpl $0x9a, 0x18(%rax)
je 0x107951
movq -0x8(%rbp), %rax
cmpl $0x9b, 0x18(%rax)
jne 0x107972
movq -0x10(%rbp), %rax
cmpl $0x0, 0x6c(%rax)
jne 0x107972
movq -0x38(%rbp), %rdi
leaq 0xbae38(%rip), %rsi     # 0x1c279e
movb $0x0, %al
callq 0x15bfb0
jmp 0x107aff
jmp 0x107974
jmp 0x107976
movq -0x10(%rbp), %rax
cmpl $0x0, 0x70(%rax)
je 0x1079b3
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
leaq -0x20(%rbp), %r8
callq 0x175eb0
cmpl $0x0, %eax
jne 0x1079a7
jmp 0x107aff
movq -0x20(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x108170
movq -0x30(%rbp), %rax
addq $0x12, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x91, 0x18(%rax)
je 0x107a03
movq -0x8(%rbp), %rax
cmpl $0x99, 0x18(%rax)
je 0x107a03
movq -0x8(%rbp), %rax
cmpl $0x9b, 0x18(%rax)
jne 0x107a9b
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0xbadc6(%rip), %rsi     # 0x1c27d8
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x1651d0
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0xba7fd(%rip), %rsi     # 0x1c224a
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
cmpq $0x2, -0x40(%rbp)
jge 0x107a6e
jmp 0x107aff
movq -0x40(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
cmpb $0x0, 0xd5(%rax)
jne 0x107a99
movq -0x38(%rbp), %rdi
leaq 0xbad54(%rip), %rsi     # 0x1c27e6
movb $0x0, %al
callq 0x15c0c0
jmp 0x107a9b
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
leaq -0x18(%rbp), %r8
callq 0x107ed0
cmpl $0x0, %eax
jne 0x107abf
jmp 0x107aff
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x108240
movq -0x18(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
subq 0x28(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
movl $0x1, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x107b0d
movq -0x8(%rbp), %rax
movb $0x1, 0x38(%rax)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq