// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: screencapture_writeframe
static int screencapture_writeframe(BFILE *fil, char mode, void *v,
	void (*writeline)(unsigned char *, int, int, BFILE *, void *))
{
	int y, ystart, yend, yinc, j;
	unsigned char *ptr, *buf;
	char inverseit = 0, bottotop = 0;

	inverseit = (mode & 1);
	bottotop = (mode & 2);

#if USE_POLYMOST && USE_OPENGL
	if (rendmode >= 3 && qsetmode == 200) {
		char bgr = (mode & 4);

		// OpenGL returns bottom-to-top ordered lines.
		if (bottotop) {
			ystart = 0;
			yend = ydim;
			yinc = 1;
		} else {
			ystart = ydim-1;
			yend = -1;
			yinc = -1;
		}
		buf = kmalloc(xdim*ydim*3);
		if (buf) {
			glfunc.glReadPixels(0,0,xdim,ydim,GL_RGB,GL_UNSIGNED_BYTE,buf);
			if (bgr) {
				for (j=(xdim*ydim-1)*3; j>=0; j-=3) {
					swapchar(&buf[j+0], &buf[j+2]);
				}
			}
			for (y = ystart; y != yend; y += yinc) {
				ptr = buf + y*xdim*3;
				writeline(ptr, xdim, 3, fil, v);
			}
			kfree(buf);
		}
		return(0);
	}
#endif

	ptr = (unsigned char *)frameplace;
	if (bottotop) {
		ystart = ydim-1;
		yend = -1;
		yinc = -1;
	} else {
		ystart = 0;
		yend = ydim;
		yinc = 1;
	}

	if (inverseit && qsetmode != 200) {
		buf = kmalloc(bytesperline);
		if (buf) {
			for (y = ystart; y != yend; y += yinc) {
				copybuf(ptr + y*bytesperline, buf, xdim >> 2);
				for (j=(bytesperline>>2)-1; j>=0; j--) ((int *)buf)[j] ^= 0x0f0f0f0fL;
				writeline(buf, xdim, 1, fil, v);
			}
			kfree(buf);
		}
	} else {
		for (y = ystart; y != yend; y += yinc) {
			writeline(ptr + y*bytesperline, xdim, 1, fil, v);
		}
	}

	return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movb $0x0, -0x51(%rbp)
movb $0x0, -0x52(%rbp)
movsbl -0x11(%rbp), %eax
andl $0x1, %eax
movb %al, -0x51(%rbp)
movsbl -0x11(%rbp), %eax
andl $0x2, %eax
movb %al, -0x52(%rbp)
leaq 0x58c3e3(%rip), %rax    # 0x5ed920
cmpl $0x3, (%rax)
jl 0x616ac
cmpl $0xc8, 0x194038(%rip)   # 0x1f5588
jne 0x616ac
movsbl -0x11(%rbp), %eax
andl $0x4, %eax
movb %al, -0x53(%rbp)
cmpb $0x0, -0x52(%rbp)
je 0x6157f
movl $0x0, -0x30(%rbp)
movl 0x3e17dd(%rip), %eax    # 0x442d50
movl %eax, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
jmp 0x61599
movl 0x3e17cb(%rip), %eax    # 0x442d50
subl $0x1, %eax
movl %eax, -0x30(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movl 0x3e17ad(%rip), %eax    # 0x442d4c
imull 0x3e17aa(%rip), %eax    # 0x442d50
imull $0x3, %eax, %eax
movslq %eax, %rdi
callq 0x35ef0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x616a0
leaq 0x58c149(%rip), %rax    # 0x5ed710
movq 0xb0(%rax), %rax
movl 0x3e1778(%rip), %edx    # 0x442d4c
movl 0x3e1776(%rip), %ecx    # 0x442d50
movq -0x50(%rbp), %r10
xorl %esi, %esi
movl $0x1907, %r8d           # imm = 0x1907
movl $0x1401, %r9d           # imm = 0x1401
movl %esi, %edi
movq %r10, (%rsp)
callq *%rax
cmpb $0x0, -0x53(%rbp)
je 0x61646
movl 0x3e174c(%rip), %eax    # 0x442d4c
imull 0x3e1749(%rip), %eax    # 0x442d50
subl $0x1, %eax
imull $0x3, %eax, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x61644
movq -0x50(%rbp), %rdi
movl -0x3c(%rbp), %eax
addl $0x0, %eax
cltq
addq %rax, %rdi
movq -0x50(%rbp), %rsi
movl -0x3c(%rbp), %eax
addl $0x2, %eax
cltq
addq %rax, %rsi
callq 0x58810
movl -0x3c(%rbp), %eax
subl $0x3, %eax
movl %eax, -0x3c(%rbp)
jmp 0x61610
jmp 0x61646
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x61697
movq -0x50(%rbp), %rax
movl -0x2c(%rbp), %ecx
imull 0x3e16ea(%rip), %ecx    # 0x442d4c
imull $0x3, %ecx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq -0x48(%rbp), %rdi
movl 0x3e16cf(%rip), %esi    # 0x442d4c
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x3, %edx
callq *%rax
movl -0x38(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x6164c
movq -0x50(%rbp), %rdi
callq 0x35f10
movl $0x0, -0x4(%rbp)
jmp 0x61829
leaq 0x15955d(%rip), %rax    # 0x1bac10
movq (%rax), %rax
movq %rax, -0x48(%rbp)
cmpb $0x0, -0x52(%rbp)
je 0x616dc
movl 0x3e168a(%rip), %eax    # 0x442d50
subl $0x1, %eax
movl %eax, -0x30(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
jmp 0x616f3
movl $0x0, -0x30(%rbp)
movl 0x3e1667(%rip), %eax    # 0x442d50
movl %eax, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
movsbl -0x51(%rbp), %eax
cmpl $0x0, %eax
je 0x617d7
cmpl $0xc8, 0x193e7e(%rip)   # 0x1f5588
je 0x617d7
leaq 0x1596cd(%rip), %rax    # 0x1bade4
movslq (%rax), %rdi
callq 0x35ef0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x617d5
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x617cc
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %eax
leaq 0x159696(%rip), %rcx    # 0x1bade4
imull (%rcx), %eax
cltq
addq %rax, %rdi
movq -0x50(%rbp), %rsi
movl 0x3e15ec(%rip), %edx    # 0x442d4c
sarl $0x2, %edx
callq 0x6ed90
leaq 0x159675(%rip), %rax    # 0x1bade4
movl (%rax), %eax
sarl $0x2, %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x617a1
movq -0x50(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movslq (%rax,%rcx,4), %rdx
xorq $0xf0f0f0f, %rdx        # imm = 0xF0F0F0F
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6177a
movq -0x28(%rbp), %rax
movq -0x50(%rbp), %rdi
movl 0x3e159d(%rip), %esi    # 0x442d4c
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x1, %edx
callq *%rax
movl -0x38(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x61734
movq -0x50(%rbp), %rdi
callq 0x35f10
jmp 0x61822
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x61820
movq -0x28(%rbp), %rax
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %ecx
leaq 0x1595ed(%rip), %rdx    # 0x1bade4
imull (%rdx), %ecx
movslq %ecx, %rcx
addq %rcx, %rdi
movl 0x3e1546(%rip), %esi    # 0x442d4c
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x1, %edx
callq *%rax
movl -0x38(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x617dd
jmp 0x61822
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)