// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/os2bootlogo.c
// Function: de_run_os2bootlogo
static void de_run_os2bootlogo(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	int k;

	d = de_malloc(c, sizeof(lctx));

	d->max_bytes_per_plane = IMG_WIDTH*IMG_MAX_HEIGHT/8;
	do_read_header(c, d, 0);

	d->unc_pixels = dbuf_create_membuf(c, d->max_bytes_per_plane*NUM_PLANES, 0x1);
	dbuf_enable_wbuffer(d->unc_pixels);
	for(k=0; k<NUM_PLANES; k++) {
		do_decompress_plane(c, d, k);
		if(d->fatal_errflag) goto done;
	}

	// There's a program that makes files that only use RLE compression.
	// Out of curiosity, I want to identify such files.
	de_dbg(c, "cmpr uses lzss: %u", (UI)d->uses_lzss);

	do_write_image(c, d);

done:
	if(d) {
		if(d->need_dcmpr_errmsg) {
			de_err(c, "Decompression failed. This is probably not "
				"an OS/2 Boot Logo.");
		}
		dbuf_close(d->unc_pixels);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
movl $0x78, %esi
callq 0xe8b2b
movq %rax, %r13
movq $0x9600, 0x60(%rax)     # imm = 0x9600
leaq 0x60(%rsp), %r14
movq $0x0, (%r14)
leaq 0x7fdc7(%rip), %rsi     # 0x12337f
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
leaq 0x8f726(%rip), %r15     # 0x132cfe
movq %r13, (%rsp)
xorl %r12d, %r12d
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeed83
movq %rax, (%r13)
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeed83
movq %rax, 0x8(%r13)
movq (%r13), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
movq %rax, %r8
xorl %eax, %eax
callq 0xe8617
incq %r12
addq $0x18, %r13
cmpq $0x4, %r12
jne 0xa35df
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq (%rsp), %r14
movq 0x60(%r14), %rsi
shlq $0x2, %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0xf09c5
movq %rax, 0x70(%r14)
movq %rax, %rdi
callq 0xf0855
xorl %r12d, %r12d
leaq (%r12,%r12,2), %r13
movq (%rsp), %r14
movq (%r14,%r13,8), %rcx
movq %rbx, %rdi
leaq 0x8f6ab(%rip), %rsi     # 0x132d19
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x70(%r14), %rdi
movq 0x60(%r14), %rsi
movq %r12, 0x10(%rsp)
imulq %r12, %rsi
callq 0xf0f27
movq 0x70(%r14), %rdi
callq 0xf08ba
movq %rbx, %rdi
leaq 0x18(%rsp), %r15
movq %r15, %rsi
leaq 0x48(%rsp), %r12
movq %r12, %rdx
leaq 0x60(%rsp), %rcx
callq 0xfa1dc
movq 0x18(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %r13, 0x40(%rsp)
movups (%r14,%r13,8), %xmm0
movups %xmm0, 0x20(%rsp)
movq 0x70(%r14), %rax
movq %rax, 0x48(%rsp)
movq 0x60(%r14), %rcx
movq %rcx, 0x58(%rsp)
movb $0x1, 0x50(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movl $0x30, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r13
movq %r15, (%rax)
movq %r12, 0x8(%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x18(%r13)
addq 0x28(%rsp), %rax
movq %rax, 0x20(%r13)
movq %rbx, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0xfad8f
movq %rax, 0x10(%r13)
leaq 0x4d3(%rip), %rcx       # 0xa3c0d
movq %rcx, 0x8(%rax)
movq %r13, (%rax)
movq 0x18(%r13), %r14
cmpq 0x20(%r13), %r14
jge 0xa3977
movq %r13, %r15
addq $0x18, %r15
movq 0x28(%r13), %rax
cmpq 0x58(%rsp), %rax
jge 0xa3977
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0xeeb4b
testb %al, %al
je 0xa37e3
movl %eax, %r12d
movzbl %al, %r14d
andb $0x3, %r12b
je 0xa383c
movq (%rsp), %rax
movb $0x1, 0x68(%rax)
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0xeeb4b
movl %eax, %ebp
cmpb $0x1, %r12b
je 0xa384e
movzbl %r12b, %eax
cmpl $0x2, %eax
jne 0xa387e
movl %r14d, %r12d
shrl $0x2, %r12d
andl $0x3, %r12d
addl $0x3, %r12d
movzbl %bpl, %eax
shll $0x4, %eax
shrl $0x4, %r14d
movl %r14d, %ebp
orl %eax, %ebp
xorl %r14d, %r14d
leaq 0x7d078(%rip), %rdx     # 0x120856
jmp 0xa38ba
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0xeeb4b
testb %al, %al
je 0xa3963
movzbl %al, %ebp
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0xeeb4b
cmpl $0x4, (%rbx)
movzbl %al, %r14d
jl 0xa3827
movq %rbx, %rdi
leaq 0x8f565(%rip), %rsi     # 0x132d80
movl %r14d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe8617
movq 0x10(%r13), %rdi
movl %r14d, %esi
callq 0xfae4e
decl %ebp
jne 0xa3827
jmp 0xa3953
shrl $0x2, %r14d
xorl %r12d, %r12d
xorl %ebp, %ebp
leaq 0x79aa3(%rip), %rdx     # 0x11d2ef
jmp 0xa38ba
movl %r14d, %eax
shrl $0x2, %eax
andl $0x3, %eax
movl %r14d, %r12d
shrl $0x4, %r12d
andl $0x7, %r12d
addl $0x3, %r12d
movzbl %bpl, %ecx
shrl $0x7, %r14d
leal (%r14,%rcx,2), %ebp
movl %eax, %r14d
leaq 0x9d11a(%rip), %rdx     # 0x140996
jmp 0xa38ba
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0xeeb4b
movl %r14d, %ecx
shrl $0x2, %ecx
andl $0xf, %ecx
movzbl %bpl, %ebp
movl %ebp, %edx
andl $0xf, %edx
shrl $0x6, %r14d
leal (%r14,%rdx,4), %r12d
movzbl %al, %eax
shll $0x4, %eax
shrl $0x4, %ebp
orl %eax, %ebp
movl %ecx, %r14d
leaq 0x9b714(%rip), %rdx     # 0x13efce
cmpl $0x4, (%rbx)
jl 0xa38e6
movq %rbx, %rdi
leaq 0x8f4cc(%rip), %rsi     # 0x132d95
movl %r14d, %ecx
movl %ebp, %r8d
movl %r12d, %r9d
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl %ebp, 0xc(%rsp)
testl %r14d, %r14d
je 0xa3927
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0xeeb4b
cmpl $0x4, (%rbx)
movzbl %al, %ebp
jl 0xa3917
movq %rbx, %rdi
leaq 0xa71ee(%rip), %rsi     # 0x14aafc
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x10(%r13), %rdi
movl %ebp, %esi
callq 0xfae4e
decl %r14d
jne 0xa38ef
cmpl $0x4, (%rbx)
jl 0xa3939
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
testl %r12d, %r12d
movl 0xc(%rsp), %eax
je 0xa3953
movq 0x10(%r13), %rdi
movl 0x10(%rdi), %esi
subl %eax, %esi
movl %r12d, %edx
callq 0xfae7b
movq 0x18(%r13), %r14
cmpq 0x20(%r13), %r14
jl 0xa3756
jmp 0xa3977
movq %rbx, %rdi
leaq 0x8f402(%rip), %rsi     # 0x132d6f
movq %r14, %rdx
xorl %eax, %eax
callq 0xe87e4
movq 0x48(%rsp), %rdi
callq 0xf08ba
movb $0x1, 0x64(%rsp)
movq 0x18(%r13), %rax
subq 0x20(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x10(%r13), %rsi
movq %rbx, %rdi
callq 0xfaed4
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe8be2
cmpl $0x0, 0x60(%rsp)
je 0xa3a0f
movq %rbx, %rdi
leaq 0x60(%rsp), %rsi
callq 0xfa1a4
movq %rbx, %rdi
leaq 0x8f36e(%rip), %rsi     # 0x132d37
movq 0x10(%rsp), %r12
movl %r12d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
movq (%rsp), %rax
movw $0x101, 0x69(%rax)      # imm = 0x101
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq (%rsp), %rax
cmpb $0x0, 0x69(%rax)
jne 0xa3b51
incq %r12
cmpq $0x4, %r12
jne 0xa3658
jmp 0xa3a87
movq (%rsp), %rax
movq 0x40(%rsp), %rcx
leaq (%rax,%rcx,8), %r15
movq 0x70(%rax), %rax
movq 0x18(%rax), %rcx
subq 0x38(%rsp), %rcx
movq %rcx, 0x10(%r15)
movq 0x68(%rsp), %rdx
movq %rbx, %rdi
leaq 0x7db13(%rip), %rsi     # 0x12154f
xorl %eax, %eax
callq 0xe8617
movq 0x8(%r15), %r14
subq 0x68(%rsp), %r14
movq 0x10(%rsp), %r12
je 0xa3a74
movq %rbx, %rdi
leaq 0x8f2fe(%rip), %rsi     # 0x132d5b
movq %r14, %rdx
xorl %eax, %eax
callq 0xe8617
cmpq $0x400, %r14            # imm = 0x400
jg 0xa39db
cmpq $0x270f, 0x10(%r15)     # imm = 0x270F
jle 0xa39db
jmp 0xa39e5
movq (%rsp), %rax
movzbl 0x68(%rax), %edx
leaq 0x8f217(%rip), %rsi     # 0x132cad
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl $0x10, %eax
movq (%rsp), %rcx
cmpq $0x7d01, (%rcx,%rax)    # imm = 0x7D01
jge 0xa3ac5
addq $0x18, %rax
cmpq $0x70, %rax
jne 0xa3aa9
movl $0x190, %r14d           # imm = 0x190
jmp 0xa3acb
movl $0x1e0, %r14d           # imm = 0x1E0
movl $0x280, %esi            # imm = 0x280
movq %rbx, %rdi
movq %r14, %rdx
callq 0xe8f88
movl $0x280, %esi            # imm = 0x280
movq %rbx, %rdi
movq %r14, %rdx
movl $0x3, %ecx
callq 0xf266a
movq %rax, %r14
leaq 0x60(%rsp), %r15
movl $0x10, %r8d
movl $0x32, %edi
movl $0x2, %esi
xorl %edx, %edx
movq %r15, %rcx
xorl %r9d, %r9d
callq 0xec55a
movq (%rsp), %rax
movq 0x60(%rax), %r8
movq 0x70(%rax), %rdi
movl $0x4, %edx
movl $0x50, %ecx
xorl %esi, %esi
movq %r15, %r9
pushq $0x2
pushq %r14
callq 0xf30b3
addq $0x10, %rsp
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf22dc
movq %r14, %rdi
callq 0xf228d
movq (%rsp), %rax
cmpb $0x0, 0x6a(%rax)
je 0xa3b6c
leaq 0x8f15e(%rip), %rsi     # 0x132cc0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq (%rsp), %r14
movq 0x70(%r14), %rdi
callq 0xf052b
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq