// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/shg.c
// Function: do_wmf
static int do_wmf(deark *c, lctx *d, struct picture_ctx *pctx, i64 pos1)
{
	i64 pos;
	i64 mapping_mode;
	i64 width, height;
	i64 decompressed_size;
	i64 compressed_size;
	i64 hotspot_size;
	i64 compressed_offset;
	i64 hotspot_offset;
	dbuf *pixels_final = NULL;
	dbuf *outf = NULL;
	int retval = 0;

	pos = pos1 + 2;

	mapping_mode = fmtutil_hlp_get_cus_p(c->infile, &pos);
	width = de_getu16le(pos);
	pos+=2;
	height = de_getu16le(pos);
	pos+=2;
	de_dbg(c, "mapping mode: %d, nominal dimensions: %d"DE_CHAR_TIMES"%d",
		(int)mapping_mode, (int)width, (int)height);
	decompressed_size = fmtutil_hlp_get_cul_p(c->infile, &pos);
	compressed_size = fmtutil_hlp_get_cul_p(c->infile, &pos);
	hotspot_size = fmtutil_hlp_get_cul_p(c->infile, &pos);
	compressed_offset = de_getu32le(pos);
	pos+=4;
	compressed_offset += pos1;
	hotspot_offset = de_getu32le(pos);
	pos+=4;
	hotspot_offset += pos1;

	de_dbg(c, "wmf offset=%d, size=%d", (int)compressed_offset,
		(int)compressed_size);
	de_dbg(c, "hotspot offset=%d, size=%d", (int)hotspot_offset,
		(int)hotspot_size);
	if(compressed_offset+compressed_size>c->infile->len) {
		de_err(c, "WMF data goes beyond end of file");
		goto done;
	}

	pixels_final = dbuf_create_membuf(c, decompressed_size, 0x1);
	dbuf_enable_wbuffer(pixels_final);
	if(!do_uncompress_picture_data(c, d, pctx, compressed_offset, compressed_size,
		pixels_final, decompressed_size))
	{
		goto done;
	}

	if(pixels_final->len != decompressed_size) {
		de_warn(c, "Expected %d bytes after decompression, got %d",
			(int)decompressed_size, (int)pixels_final->len);
	}

	outf = dbuf_create_output_file(c, "wmf", NULL, 0);
	dbuf_copy(pixels_final, 0, pixels_final->len, outf);

	retval = 1;
done:
	dbuf_close(outf);
	dbuf_close(pixels_final);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1760d0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165280
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165280
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %eax, %r8d
leaq 0xa1337(%rip), %rsi     # 0x1c6dca
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1761f0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1761f0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1761f0
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165540
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165540
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl %eax, %edx
movq -0x50(%rbp), %rax
movl %eax, %ecx
leaq 0xa12ad(%rip), %rsi     # 0x1c6df7
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rax
movl %eax, %edx
movq -0x58(%rbp), %rax
movl %eax, %ecx
leaq 0xa12a6(%rip), %rsi     # 0x1c6e0e
movb $0x0, %al
callq 0x15b0d0
movq -0x60(%rbp), %rax
addq -0x50(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x125b9c
movq -0x8(%rbp), %rdi
leaq 0xa1299(%rip), %rsi     # 0x1c6e29
movb $0x0, %al
callq 0x15bfb0
jmp 0x125c51
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x70(%rbp), %r9
movq -0x48(%rbp), %rax
movq %rax, (%rsp)
callq 0x125c70
cmpl $0x0, %eax
jne 0x125be7
jmp 0x125c51
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x48(%rbp), %rax
je 0x125c17
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %ecx
leaq 0xa123a(%rip), %rsi     # 0x1c6e4a
movb $0x0, %al
callq 0x15bc10
movq -0x8(%rbp), %rdi
leaq 0x82531(%rip), %rsi     # 0x1a8153
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x166c60
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x78(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
callq 0x166070
movl $0x1, -0x7c(%rbp)
movq -0x78(%rbp), %rdi
callq 0x1676a0
movq -0x70(%rbp), %rdi
callq 0x1676a0
movl -0x7c(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nop