// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/shg.c
// Function: do_picture
static int do_picture(deark *c, lctx *d, i64 pic_index)
{
	i64 pic_offset;
	const char *ptname;
	struct picture_ctx *pctx = NULL;
	int retval = 0;

	pctx = de_malloc(c, sizeof(struct picture_ctx));
	de_dbg(c, "picture #%d", (int)pic_index);
	de_dbg_indent(c, 1);

	pic_offset = de_getu32le(d->shg_startpos + 4 + 4*pic_index);
	pic_offset += d->shg_startpos;
	de_dbg(c, "picture data at %d", (int)pic_offset);
	if(pic_offset >= c->infile->len) {
		goto done;
	}

	pctx->picture_type = de_getbyte(pic_offset);
	pctx->packing_method = de_getbyte(pic_offset+1);

	switch(pctx->picture_type) {
	case 5: ptname="DDB"; break;
	case 6: ptname="DIB"; break;
	case 8: ptname="metafile"; break;
	default: ptname="?";
	}
	de_dbg(c, "picture type: %d (%s)", (int)pctx->picture_type, ptname);
	de_dbg(c, "packing method: %d", (int)pctx->packing_method);

	if(pctx->picture_type==5 || pctx->picture_type==6) { // DDB or DIB
		do_dib_ddb(c, d, pctx, pic_offset);
	}
	else if(pctx->picture_type==8) { // WMF
		do_wmf(c, d, pctx, pic_offset);
	}
	else {
		de_warn(c, "Unsupported picture type: %d", (int)pctx->picture_type);
	}

	retval = 1;
done:
	de_free(c, pctx);
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl $0x70, %esi
callq 0x15b780
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0xa1a13(%rip), %rsi     # 0x1c6bb9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x4, %rsi
movq -0x18(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x165540
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0xa19c1(%rip), %rsi     # 0x1c6bc5
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x125222
jmp 0x12535a
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165060
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
incq %rsi
callq 0x165060
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x30(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x38(%rbp)
subl $0x5, %eax
je 0x12527d
jmp 0x125269
movl -0x38(%rbp), %eax
subl $0x6, %eax
je 0x12528a
jmp 0x125273
movl -0x38(%rbp), %eax
subl $0x8, %eax
je 0x125297
jmp 0x1252a4
leaq 0xa1b42(%rip), %rax     # 0x1c6dc6
movq %rax, -0x28(%rbp)
jmp 0x1252af
leaq 0xa749c(%rip), %rax     # 0x1cc72d
movq %rax, -0x28(%rbp)
jmp 0x1252af
leaq 0xa193a(%rip), %rax     # 0x1c6bd8
movq %rax, -0x28(%rbp)
jmp 0x1252af
leaq 0x92982(%rip), %rax     # 0x1b7c2d
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movzbl (%rax), %edx
movq -0x28(%rbp), %rcx
leaq 0xa191c(%rip), %rsi     # 0x1c6be1
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movzbl 0x1(%rax), %edx
leaq 0xa1918(%rip), %rsi     # 0x1c6bf7
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x5, %eax
je 0x1252fe
movq -0x30(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x6, %eax
jne 0x125315
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x125380
jmp 0x125353
movq -0x30(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x8, %eax
jne 0x125338
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x1259e0
jmp 0x125351
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movzbl (%rax), %edx
leaq 0xa18c0(%rip), %rsi     # 0x1c6c0a
movb $0x0, %al
callq 0x15bc10
jmp 0x125353
movl $0x1, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x34(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop