// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdi, %rbx
leaq 0x5b9d29(%rip), %rax    # 0x5f9950
cmpl $0x3, (%rax)
setge %r9b
movl 0x177df4(%rip), %eax    # 0x1b7a28
cmpl $0xc8, %eax
sete %dil
andb %r9b, %dil
cmpb $0x1, %dil
jne 0x3fd86
movl %esi, 0x18(%rsp)
movl %esi, %eax
andb $0x2, %al
movl 0x3c7397(%rip), %r13d   # 0x406ff0
leal -0x1(%r13), %esi
xorl %ebp, %ebp
testb %al, %al
setne 0x17(%rsp)
cmovnel %ebp, %esi
movq %rsi, 0x20(%rsp)
cmpb $0x1, %al
sbbl %ebp, %ebp
movl 0x3c7374(%rip), %esi    # 0x406fec
movl %r13d, %eax
movl %esi, 0x28(%rsp)
imull %esi, %eax
leal (%rax,%rax,2), %eax
movslq %eax, %rdi
movq %rdx, %r14
movq %rcx, %r15
callq 0x69a0
testq %rax, %rax
je 0x3fee4
movq %rax, %r12
movq %rbx, 0x30(%rsp)
movq %r14, 0x40(%rsp)
movq %r15, 0x38(%rsp)
orl %r13d, %ebp
leaq 0x5b9a88(%rip), %rax    # 0x5f9740
movq %r12, (%rsp)
xorl %edi, %edi
xorl %esi, %esi
movl 0x28(%rsp), %edx
movl %r13d, %ecx
movl $0x1907, %r8d           # imm = 0x1907
movl $0x1401, %r9d           # imm = 0x1401
callq *0xb0(%rax)
testb $0x4, 0x18(%rsp)
je 0x3fd19
movl 0x3c7306(%rip), %eax    # 0x406fec
imull 0x3c7303(%rip), %eax    # 0x406ff0
leal (%rax,%rax,2), %eax
addl $-0x3, %eax
js 0x3fd19
movl %eax, %eax
addq $0x3, %rax
movb -0x3(%r12,%rax), %cl
movb -0x1(%r12,%rax), %dl
movb %cl, -0x1(%r12,%rax)
movb %dl, -0x3(%r12,%rax)
addq $-0x3, %rax
cmpq $0x2, %rax
jg 0x3fcfb
movq 0x20(%rsp), %rax
movl %eax, %r13d
subl %ebp, %r13d
je 0x3fe81
xorl %ecx, %ecx
movb 0x17(%rsp), %dl
movb %dl, %cl
leal -0x1(,%rcx,2), %ecx
leal (%rax,%rax,2), %ebx
movq %rcx, 0x18(%rsp)
leal (%rcx,%rcx,2), %eax
movl %eax, 0x20(%rsp)
movq 0x38(%rsp), %r15
movq 0x40(%rsp), %r14
movq 0x30(%rsp), %rbp
movl 0x3c728f(%rip), %esi    # 0x406fec
movl %ebx, %eax
imull %esi, %eax
movslq %eax, %rdi
addq %r12, %rdi
movl $0x3, %edx
movq %rbp, %rcx
movq %r14, %r8
callq *%r15
addl 0x20(%rsp), %ebx
addl 0x18(%rsp), %r13d
jne 0x3fd57
jmp 0x3fe81
movq %rbx, 0x30(%rsp)
movq %rdx, %rbx
movq %rcx, 0x38(%rsp)
leaq 0x13d316(%rip), %rcx    # 0x17d0b0
movl %esi, %edx
andb $0x2, %dl
movl %esi, %r8d
shrb %r8b
movl 0x3c7245(%rip), %edi    # 0x406ff0
leal -0x1(%rdi), %r13d
xorl %ebp, %ebp
testb %dl, %dl
cmovel %ebp, %r13d
movq (%rcx), %rcx
movq %rcx, 0x28(%rsp)
negb %dl
sbbl %ebp, %ebp
orl %edi, %ebp
movzbl %r8b, %ecx
andl $0x1, %ecx
negl %ecx
orl $0x1, %ecx
movl %ecx, 0x18(%rsp)
cmpl $0xc8, %eax
setne %al
testb %al, %sil
je 0x3fe97
leaq 0x13d497(%rip), %rax    # 0x17d284
movslq (%rax), %rdi
callq 0x69a0
testq %rax, %rax
je 0x3fee4
movq %rax, %r12
cmpl %ebp, %r13d
movl %ebp, 0x20(%rsp)
je 0x3fe81
movq %rbx, %rbp
movq 0x28(%rsp), %rbx
movl 0x18(%rsp), %r14d
leaq 0x13d466(%rip), %r15    # 0x17d284
movslq (%r15), %rax
movslq %r13d, %rdi
imulq %rax, %rdi
addq %rbx, %rdi
movl 0x3c71bb(%rip), %edx    # 0x406fec
sarl $0x2, %edx
movq %r12, %rsi
callq 0x4abdd
movl (%r15), %eax
sarl $0x2, %eax
testl %eax, %eax
jle 0x3fe5d
movl %eax, %eax
incq %rax
xorl $0xf0f0f0f, -0x8(%r12,%rax,4) # imm = 0xF0F0F0F
decq %rax
cmpq $0x1, %rax
jg 0x3fe4b
movl 0x3c7189(%rip), %esi    # 0x406fec
movq %r12, %rdi
movl $0x1, %edx
movq 0x30(%rsp), %rcx
movq %rbp, %r8
callq *0x38(%rsp)
addl %r14d, %r13d
cmpl 0x20(%rsp), %r13d
jne 0x3fe17
movq %r12, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x61c0
cmpl %ebp, %r13d
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r12
je 0x3fee4
leaq 0x13d3d2(%rip), %rsi    # 0x17d284
movslq (%rsi), %rdi
movslq %r13d, %r13
imulq %r13, %rdi
addq %r12, %rdi
movl 0x3c7127(%rip), %esi    # 0x406fec
movl $0x1, %edx
movq %r14, %rcx
movq %rbx, %r8
movq %rax, %r15
callq *%rax
movl 0x18(%rsp), %esi
movq %r15, %rax
addl %esi, %r13d
cmpl %r13d, %ebp
jne 0x3feab
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq