// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/eps.c
// Function: do_decode_epsi
static void do_decode_epsi(deark *c, const char *hdrfields, i64 pos1)
{
	int width, height, depth, lines;
	int ret;
	lctx *d = NULL;

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

	// EPSI is a text-based format, and deark isn't very good at text formats.
	// But we'll give it a try.

	ret = de_sscanf(hdrfields, " %d %d %d %d", &width, &height, &depth, &lines);
	if(ret!=4) {
		de_err(c, "Failed to parse EPSI header line");
		return;
	}
	de_dbg(c, "w=%d h=%d d=%d l=%d", width, height, depth, lines);
	d->npwidth = width;
	d->h = height;
	d->depth = depth;
	d->lines = lines;

	if(d->depth!=1 && d->depth!=2 && d->depth!=4 && d->depth!=8) {
		de_err(c, "Unsupported EPSI bit depth (%d)", (int)d->depth);
		goto done;
	}

	d->src_rowspan = (d->npwidth * d->depth +7)/8;
	d->pdwidth = (d->src_rowspan*8) / d->depth;

	if(!de_good_image_dimensions(c, d->pdwidth, d->h)) {
		goto done;
	}
	if(d->lines>100000 || d->lines<1) {
		de_err(c, "Bad EPSI header");
		goto done;
	}

	do_decode_epsi_image(c, d, pos1);

done:
	de_free(c, d);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl $0x450, %esi            # imm = 0x450
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x149788(%rip), %rsi    # 0x1a81b1
leaq -0x1c(%rbp), %rdx
leaq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %r8
leaq -0x28(%rbp), %r9
movb $0x0, %al
callq 0x19220
movl %eax, -0x2c(%rbp)
cmpl $0x4, -0x2c(%rbp)
je 0x5ea60
movq -0x8(%rbp), %rdi
leaq 0x14976a(%rip), %rsi    # 0x1a81be
movb $0x0, %al
callq 0x15bfb0
jmp 0x5ebb1
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x24(%rbp), %r8d
movl -0x28(%rbp), %r9d
leaq 0x149766(%rip), %rsi    # 0x1a81df
movb $0x0, %al
callq 0x15b0d0
movslq -0x1c(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movslq -0x20(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movslq -0x24(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movslq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x38(%rbp), %rax
cmpq $0x1, 0x18(%rax)
je 0x5eafc
movq -0x38(%rbp), %rax
cmpq $0x2, 0x18(%rax)
je 0x5eafc
movq -0x38(%rbp), %rax
cmpq $0x4, 0x18(%rax)
je 0x5eafc
movq -0x38(%rbp), %rax
cmpq $0x8, 0x18(%rax)
je 0x5eafc
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x149703(%rip), %rsi    # 0x1a81f3
movb $0x0, %al
callq 0x15bfb0
jmp 0x5eba4
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
imulq 0x18(%rcx), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
shlq $0x3, %rax
movq -0x38(%rbp), %rcx
cqto
idivq 0x18(%rcx)
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x5eb66
jmp 0x5eba4
movq -0x38(%rbp), %rax
cmpq $0x186a0, 0x28(%rax)    # imm = 0x186A0
jg 0x5eb7f
movq -0x38(%rbp), %rax
cmpq $0x1, 0x28(%rax)
jge 0x5eb93
movq -0x8(%rbp), %rdi
leaq 0x149689(%rip), %rsi    # 0x1a8213
movb $0x0, %al
callq 0x15bfb0
jmp 0x5eba4
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x5ebc0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)