// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc2.c
// Function: do_one_ripicon
static int do_one_ripicon(deark *c, i64 pos1, i64 *pbytes_consumed, int scan_mode)
{
	i64 width, height;
	de_bitmap *img = NULL;
	i64 chunk_span;
	i64 src_rowspan;
	i64 bitmap_len;
	i64 pos = pos1;
	int saved_indent_level;
	de_color pal[16];

	if(pos1+8 > c->infile->len) return 0;
	width = 1 + de_getu16le_p(&pos);
	height = 1 + de_getu16le_p(&pos);
	if(width>MAX_RIPICON_DIMENSION || height>MAX_RIPICON_DIMENSION) return 0;
	chunk_span = (width+7)/8;
	src_rowspan = 4*chunk_span;
	bitmap_len = src_rowspan * height;
	if(pos+bitmap_len > c->infile->len) return 0;

	*pbytes_consumed = 4 + bitmap_len + 2;
	if(scan_mode) return 1;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "image at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);
	de_dbg_dimensions(c, width, height);

	de_dbg(c, "bitmap at %"I64_FMT", len=%"I64_FMT, pos, bitmap_len);
	if(!de_good_image_dimensions(c, width, height)) goto done;
	img = de_bitmap_create2(c, width, chunk_span*8, height, 3);
	de_copy_std_palette(DE_PALID_PC16, 0, 0, pal, 16, 0);
	de_convert_image_paletted_planar(c->infile, pos, 4, src_rowspan, chunk_span,
		pal, img, 0);
	de_bitmap_write_to_file(img, NULL, DE_CREATEFLAG_OPT_IMAGE);

done:
	if(img) de_bitmap_destroy(img);
	de_dbg_indent_restore(c, saved_indent_level);
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x9ae4c
movl $0x0, -0x4(%rbp)
jmp 0x9b03c
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1652c0
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1652c0
addq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x800, -0x30(%rbp)     # imm = 0x800
jg 0x9ae92
cmpq $0x800, -0x38(%rbp)     # imm = 0x800
jle 0x9ae9e
movl $0x0, -0x4(%rbp)
jmp 0x9b03c
movq -0x30(%rbp), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
shlq $0x2, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
imulq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rax
addq -0x58(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x9aeef
movl $0x0, -0x4(%rbp)
jmp 0x9b03c
movq -0x58(%rbp), %rcx
addq $0x4, %rcx
addq $0x2, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x0, -0x24(%rbp)
je 0x9af14
movl $0x1, -0x4(%rbp)
jmp 0x9b03c
movq -0x10(%rbp), %rdi
leaq -0x64(%rbp), %rsi
callq 0x15b580
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x11f3fe(%rip), %rsi    # 0x1ba32e
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x15bba0
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
leaq 0x11fb4f(%rip), %rsi    # 0x1baab8
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x9af8b
jmp 0x9b019
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rdx
shlq $0x3, %rdx
movq -0x38(%rbp), %rcx
movl $0x3, %r8d
callq 0x16b7f0
movq %rax, -0x40(%rbp)
leaq -0xb0(%rbp), %rcx
movl $0x14, %edi
xorl %r9d, %r9d
xorl %eax, %eax
movl %eax, %edx
movl $0x10, %r8d
movl %r9d, %esi
callq 0x161320
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x60(%rbp), %rsi
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %r8
leaq -0xb0(%rbp), %r9
movq -0x40(%rbp), %rax
movl $0x4, %edx
xorl %r10d, %r10d
movq %rax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x16c690
movq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x16afd0
cmpq $0x0, -0x40(%rbp)
je 0x9b029
movq -0x40(%rbp), %rdi
callq 0x16af60
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x15b5a0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)