// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/dlmaker.c
// Function: do_v12screen
static void do_v12screen(deark *c, lctx *d, i64 pos)
{
	int single_image;

	single_image = (d->v12.imgs_per_screen<=1 || d->v12.opt_montage);

	if(!d->v12.screen_img) {
		d->v12.screen_img = de_bitmap_create(c, V12_SCREEN_WIDTH, V12_SCREEN_HEIGHT, 3);
		if(!single_image) {
			d->v12.screen_img->is_internal = 1;
		}
	}
	de_convert_image_paletted(c->infile, pos, 8, V12_SCREEN_WIDTH, d->pal, d->v12.screen_img, 0);
	if(single_image) {
		de_bitmap_write_to_file_finfo(d->v12.screen_img, d->fi, 0);
	}
	else {
		i64 i;
		i64 xpos = 0;
		i64 ypos = 0;

		if(!d->v12.img) {
			d->v12.img = de_bitmap_create(c, d->v12.img_xsize, d->v12.img_ysize, 3);
		}

		for(i=0; i<d->v12.imgs_per_screen; i++) {
			de_bitmap_copy_rect(d->v12.screen_img, d->v12.img, xpos, ypos, d->v12.img_xsize, d->v12.img_ysize,
				0, 0, 0);
			de_bitmap_write_to_file_finfo(d->v12.img, d->fi, 0);

			xpos += d->v12.img_xsize;
			if(xpos >= V12_SCREEN_WIDTH) {
				xpos = 0;
				ypos += d->v12.img_ysize;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movb $0x1, %al
cmpq $0x1, 0x20(%rcx)
movb %al, -0x39(%rbp)
jle 0x86d12
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x86d5f
movq -0x8(%rbp), %rdi
movl $0x140, %esi            # imm = 0x140
movl $0xc8, %edx
movl $0x3, %ecx
callq 0x16b750
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
cmpl $0x0, -0x1c(%rbp)
jne 0x86d5d
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movb $0x1, 0x38(%rax)
jmp 0x86d5f
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %r8
addq $0x70, %r8
movq -0x10(%rbp), %rax
movq 0x30(%rax), %r9
movl $0x8, %edx
movl $0x140, %ecx            # imm = 0x140
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16c520
cmpl $0x0, -0x1c(%rbp)
je 0x86db5
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rsi
xorl %edx, %edx
callq 0x16afa0
jmp 0x86ebb
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x86df9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movl $0x3, %ecx
callq 0x16b750
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jge 0x86eb9
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %r8
movq -0x10(%rbp), %rax
movq 0x18(%rax), %r9
xorl %eax, %eax
xorl %eax, %eax
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0x16ce50
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rsi
xorl %edx, %edx
callq 0x16afa0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x140, -0x30(%rbp)     # imm = 0x140
jl 0x86ea6
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x86ea8
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x86e01
jmp 0x86ebb
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)