// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movl %esi, %r15d
movq %rdi, 0x18(%rsp)
leaq 0x5b7ad9(%rip), %rax    # 0x5f3950
cmpl $0x3, (%rax)
setge %cl
movl 0x175ba5(%rip), %eax    # 0x1b1a28
cmpl $0xc8, %eax
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x3bf6a
movl %r15d, %eax
andb $0x2, %al
movl 0x3c514f(%rip), %ebp    # 0x400ff0
leal -0x1(%rbp), %r13d
xorl %r14d, %r14d
xorl %ebx, %ebx
testb %al, %al
setne 0x17(%rsp)
cmovnel %r14d, %r13d
cmpb $0x1, %al
sbbl %r14d, %r14d
movl 0x3c512c(%rip), %ecx    # 0x400fec
movl %ebp, %eax
movl %ecx, 0x34(%rsp)
imull %ecx, %eax
leal (%rax,%rax,2), %eax
movslq %eax, %rdi
callq 0x69a0
testq %rax, %rax
je 0x3c07c
movq %rax, %r12
orl %ebp, %r14d
movl %r14d, 0x30(%rsp)
movb 0x17(%rsp), %al
movb %al, %bl
leal -0x1(,%rbx,2), %ebx
leaq 0x5b7844(%rip), %rax    # 0x5f3740
movq %r12, (%rsp)
xorl %edi, %edi
xorl %esi, %esi
movl 0x34(%rsp), %edx
movl %ebp, %ecx
movl $0x1907, %r8d           # imm = 0x1907
movl $0x1401, %r9d           # imm = 0x1401
callq *0xb0(%rax)
testb $0x4, %r15b
jne 0x3c08b
leal (%r13,%r13,2), %r14d
leal (%rbx,%rbx,2), %r15d
subl 0x30(%rsp), %r13d
pushq $0x3
popq %rbp
testl %r13d, %r13d
je 0x3c02d
movl 0x3c50a6(%rip), %esi    # 0x400fec
movl %r14d, %eax
imull %esi, %eax
movslq %eax, %rdi
addq %r12, %rdi
movl %ebp, %edx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
callq *0x28(%rsp)
addl %r15d, %r14d
addl %ebx, %r13d
jmp 0x3bf37
leaq 0x13b13f(%rip), %rcx    # 0x1770b0
movl %r15d, %edx
andb $0x2, %dl
movl %r15d, %esi
shrb %sil
movl 0x3c506d(%rip), %edi    # 0x400ff0
leal -0x1(%rdi), %r13d
xorl %ebp, %ebp
testb %dl, %dl
cmovel %ebp, %r13d
movq (%rcx), %rbx
negb %dl
sbbl %ebp, %ebp
orl %edi, %ebp
movzbl %sil, %r14d
andl $0x1, %r14d
negl %r14d
orl $0x1, %r14d
cmpl $0xc8, %eax
setne %al
testb %al, %r15b
je 0x3c043
leaq 0x13b2c5(%rip), %r15    # 0x177284
movslq (%r15), %rdi
callq 0x69a0
testq %rax, %rax
je 0x3c07c
movq %rax, %r12
cmpl %ebp, %r13d
je 0x3c02d
movslq (%r15), %rax
movslq %r13d, %rdi
imulq %rax, %rdi
addq %rbx, %rdi
movl 0x3c5001(%rip), %edx    # 0x400fec
sarl $0x2, %edx
movq %r12, %rsi
callq 0x444be
movl (%r15), %eax
sarl $0x2, %eax
testl %eax, %eax
jle 0x3c00e
xorl $0xf0f0f0f, -0x4(%r12,%rax,4) # imm = 0xF0F0F0F
decq %rax
jmp 0x3bffc
movl 0x3c4fd8(%rip), %esi    # 0x400fec
movq %r12, %rdi
pushq $0x1
popq %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
callq *0x28(%rsp)
addl %r14d, %r13d
jmp 0x3bfd3
movq %r12, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x61c0
leaq 0x13b23a(%rip), %r15    # 0x177284
pushq $0x1
popq %r12
cmpl %r13d, %ebp
je 0x3c07c
movslq (%r15), %rax
movslq %r13d, %rdi
imulq %rax, %rdi
addq %rbx, %rdi
movl 0x3c4f86(%rip), %esi    # 0x400fec
movl %r12d, %edx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
callq *0x28(%rsp)
addl %r14d, %r13d
jmp 0x3c04e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x3c4f5b(%rip), %eax    # 0x400fec
imull 0x3c4f58(%rip), %eax    # 0x400ff0
leal (%rax,%rax,2), %eax
addq $-0x3, %rax
testl %eax, %eax
js 0x3bf26
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movb (%r12,%rcx), %dl
movb 0x2(%r12,%rcx), %sil
movb %dl, 0x2(%r12,%rcx)
movb %sil, (%r12,%rcx)
jmp 0x3c09b