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

	pattype = (UI)dbuf_getu16be_p(h->inf, &pos);
	de_dbg(c, "PatType: %u", pattype);
	pos += 8; // Pat1Data

	if(pattype==2) { // ditherPat(?)
		pos += 6; // RGB
		retval = 1;
		goto done;
	}

	bi = de_malloc(c, sizeof(struct fmtutil_macbitmap_info));

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

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

	if(!get_pixdata_size(c, h->d, bi, pos, &pixdata_size)) {
		goto done;
	}
	// Note: We could extract the "PixMap" pattern easily enough here, by calling
	// decode_pixdata(). But if we do that, maybe we should also extract the
	// Pat1Data data above, as well as other opcodes like BkPat.
	pos += pixdata_size;
	retval = 1;

done:
	if(!retval && needmsg) {
		de_err(c, "Failed to parse PixPat data");
	}
	if(retval) {
		h->data_len = pos - h->data_pos;
	}
	if(!retval) {
		h->fatal_errflag = 1;
	}
	de_free(c, bi);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165210
movl %eax, -0xc(%rbp)
movq -0x40(%rbp), %rdi
movl -0xc(%rbp), %edx
leaq 0xbb5d7(%rip), %rsi     # 0x1c2692
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
cmpl $0x2, -0xc(%rbp)
jne 0x1070ec
movq -0x18(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x18(%rbp)
movl $0x1, -0x20(%rbp)
jmp 0x1071ba
movq -0x40(%rbp), %rdi
movl $0x480, %esi            # imm = 0x480
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0x1759a0
movq -0x18(%rbp), %rax
addq $0xa, %rax
movq %rax, -0x18(%rbp)
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0x175ba0
movq -0x18(%rbp), %rax
addq $0x24, %rax
movq %rax, -0x18(%rbp)
movq -0x38(%rbp), %rax
movl $0x1, 0x74(%rax)
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq -0x28(%rbp), %r8
callq 0x175eb0
cmpl $0x0, %eax
jne 0x107177
jmp 0x1071ba
movq -0x28(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq -0x30(%rbp), %r8
callq 0x107ed0
cmpl $0x0, %eax
jne 0x1071a7
jmp 0x1071ba
movq -0x30(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x1, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x1071d8
cmpl $0x0, -0x1c(%rbp)
je 0x1071d8
movq -0x40(%rbp), %rdi
leaq 0xbb4cd(%rip), %rsi     # 0x1c269e
movb $0x0, %al
callq 0x15bfb0
cmpl $0x0, -0x20(%rbp)
je 0x1071f2
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
subq 0x28(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
cmpl $0x0, -0x20(%rbp)
jne 0x107200
movq -0x8(%rbp), %rax
movb $0x1, 0x38(%rax)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)