// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/emf.c
// Function: emf_handler_50_51
static int emf_handler_50_51(deark *c, lctx *d, struct decoder_params *dp)
{
	i64 rop;
	i64 bmi_offs;
	i64 bmi_len;
	i64 bits_offs;
	i64 bits_len;
	i64 fixed_header_len;
	i64 num_scans;

	if(dp->rectype==0x50)
		fixed_header_len = 76;
	else
		fixed_header_len = 80;

	if(dp->recsize_bytes<fixed_header_len) return 1;

	bmi_offs = de_getu32le(dp->recpos+48);
	bmi_len = de_getu32le(dp->recpos+52);
	de_dbg(c, "bmi offset=%"I64_FMT", len=%"I64_FMT, bmi_offs, bmi_len);
	bits_offs = de_getu32le(dp->recpos+56);
	bits_len = de_getu32le(dp->recpos+60);
	de_dbg(c, "bits offset=%"I64_FMT", len=%"I64_FMT, bits_offs, bits_len);

	if(dp->rectype==0x51) {
		rop = de_getu32le(dp->recpos+68);
		de_dbg(c, "raster operation: 0x%08x", (UI)rop);
	}

	if(dp->rectype==0x50) {
		num_scans = de_getu32le(dp->recpos+72);
		de_dbg(c, "number of scanlines: %u", (UI)num_scans);
	}

	if(bmi_len<12) return 1;
	if(bmi_offs<fixed_header_len) return 1;
	if(bmi_offs+bmi_len>dp->recsize_bytes) return 1;
	if(bits_len<1) return 1;
	if(bits_offs<fixed_header_len) return 1;
	if(bits_offs+bits_len>dp->recsize_bytes) return 1;
	extract_dib(c, d, dp->recpos+bmi_offs, bmi_len, dp->recpos+bits_offs, bits_len);

	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x50, (%rax)
jne 0x5b0f7
movq $0x4c, -0x50(%rbp)
jmp 0x5b0ff
movq $0x50, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x50(%rbp), %rax
jge 0x5b119
movl $0x1, -0x4(%rbp)
jmp 0x5b2f3
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x30, %rsi
callq 0x165540
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x34, %rsi
callq 0x165540
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x14c965(%rip), %rsi    # 0x1a7acb
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x38, %rsi
callq 0x165540
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x3c, %rsi
callq 0x165540
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
leaq 0x14c929(%rip), %rsi    # 0x1a7ae3
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
cmpl $0x51, (%rax)
jne 0x5b1ff
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x44, %rsi
callq 0x165540
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x14c8ba(%rip), %rsi    # 0x1a7ab2
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
cmpl $0x50, (%rax)
jne 0x5b23d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x48, %rsi
callq 0x165540
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rax
movl %eax, %edx
leaq 0x14c8d5(%rip), %rsi    # 0x1a7b0b
movb $0x0, %al
callq 0x15b0d0
cmpq $0xc, -0x38(%rbp)
jge 0x5b250
movl $0x1, -0x4(%rbp)
jmp 0x5b2f3
movq -0x30(%rbp), %rax
cmpq -0x50(%rbp), %rax
jge 0x5b266
movl $0x1, -0x4(%rbp)
jmp 0x5b2f3
movq -0x30(%rbp), %rax
addq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jle 0x5b281
movl $0x1, -0x4(%rbp)
jmp 0x5b2f3
cmpq $0x1, -0x48(%rbp)
jge 0x5b291
movl $0x1, -0x4(%rbp)
jmp 0x5b2f3
movq -0x40(%rbp), %rax
cmpq -0x50(%rbp), %rax
jge 0x5b2a4
movl $0x1, -0x4(%rbp)
jmp 0x5b2f3
movq -0x40(%rbp), %rax
addq -0x48(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jle 0x5b2bf
movl $0x1, -0x4(%rbp)
jmp 0x5b2f3
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdx
addq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %r8
addq -0x40(%rbp), %r8
movq -0x48(%rbp), %r9
callq 0x5c370
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)