// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/src/sdlayer2.c
// Function: showframe
void showframe(void)
{
#if USE_OPENGL
	if (!glunavailable) {
		if (bpp == 8) {
			glbuild_update_8bit_frame(&gl8bit, frame, bytesperline, yres);
			glbuild_draw_8bit_frame(&gl8bit);
		}

		SDL_GL_SwapWindow(sdl_window);
		return;
	}
#endif

	unsigned char *pixels, *in;
	int pitch, y, x;
	int rendx, rendy, rendaspect, frameaspect;
	SDL_Rect destrect;
	SDL_Surface *winsurface = NULL;

	if (usesdlrenderer) {
		if (SDL_LockTexture(sdl_texture, NULL, (void**)&pixels, &pitch)) {
			debugprintf("Could not lock texture: %s\n", SDL_GetError());
			return;
		}
	} else {
		if (SDL_LockSurface(sdl_surface)) {
			debugprintf("Could not lock surface: %s\n", SDL_GetError());
			return;
		}
		pixels = (unsigned char *)sdl_surface->pixels;
		pitch = sdl_surface->pitch;
	}

	in = frame;
	for (y = yres - 1; y >= 0; y--) {
		for (x = xres - 1; x >= 0; x--) {
			memcpy(&pixels[x<<2], &curpalettefaded[in[x]], 4);
		}
		pixels += pitch;
		in += bytesperline;
	}

	if (usesdlrenderer) {
		SDL_UnlockTexture(sdl_texture);
	} else {
		SDL_UnlockSurface(sdl_surface);
	}

	if (usesdlrenderer) {
		SDL_GetRendererOutputSize(sdl_renderer, &rendx, &rendy);
	} else {
		winsurface = SDL_GetWindowSurface(sdl_window);
		if (!winsurface) {
			debugprintf("Could not get window surface: %s\n", SDL_GetError());
			return;
		}
		rendx = winsurface->w;
		rendy = winsurface->h;
	}

	rendaspect = divscale16(rendx, rendy);
	frameaspect = divscale16(xres, yres);
	if (rendaspect >= frameaspect) {
		// Renderer is at least as wide as the frame. We maximise frame height and centre on width.
		destrect.y = 0;
		destrect.h = rendy;
		destrect.w = mulscale16(rendy, frameaspect);
		destrect.x = (rendx - destrect.w) >> 1;
	} else {
		// Renderer is narrower than the frame. We maximise frame width and centre on height.
		destrect.x = 0;
		destrect.w = rendx;
		destrect.h = divscale16(rendx, frameaspect);
		destrect.y = (rendy - destrect.h) >> 1;
	}

	if (usesdlrenderer) {
		SDL_RenderClear(sdl_renderer);
		if (SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, &destrect)) {
			debugprintf("Could not copy render texture: %s\n", SDL_GetError());
		}
		SDL_RenderPresent(sdl_renderer);
	} else {
		SDL_FillRect(winsurface, NULL, SDL_MapRGB(winsurface->format, 0, 0, 0));
		if (SDL_BlitScaled(sdl_surface, NULL, winsurface, &destrect) < 0) {
			debugprintf("Could not blit surface: %s\n", SDL_GetError());
			return;
		}
		SDL_UpdateWindowSurface(sdl_window);
	}
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
leaq 0x10feda(%rip), %rax    # 0x17d0e8
cmpl $0x0, (%rax)
je 0x6d246
cmpb $0x1, 0x65f1c6(%rip)    # 0x6cc3e0
jne 0x6d295
movq 0x660dfd(%rip), %rdi    # 0x6ce020
leaq 0x20(%rsp), %rdx
leaq 0xc(%rsp), %rcx
xorl %esi, %esi
callq 0x6b70
testl %eax, %eax
je 0x6d2c8
callq 0x6b40
jmp 0x6d4c2
leaq 0x10fe57(%rip), %rax    # 0x17d0a4
cmpl $0x8, (%rax)
jne 0x6d282
movq 0x660e1f(%rip), %rsi    # 0x6ce078
leaq 0x110024(%rip), %rax    # 0x17d284
movl (%rax), %edx
leaq 0x35dcb(%rip), %rax     # 0xa3034
movl (%rax), %ecx
leaq 0x660dc6(%rip), %rbx    # 0x6ce038
movq %rbx, %rdi
callq 0x4d5b9
movq %rbx, %rdi
callq 0x4d616
movq 0x65f047(%rip), %rdi    # 0x6cc2d0
addq $0x28, %rsp
popq %rbx
popq %r14
jmp 0x6340
movq 0x660d8c(%rip), %rdi    # 0x6ce028
callq 0x6560
testl %eax, %eax
je 0x6d2b1
addq $0x28, %rsp
popq %rbx
popq %r14
jmp 0x6b40
movq 0x660d70(%rip), %rax    # 0x6ce028
movq 0x20(%rax), %rcx
movq %rcx, 0x20(%rsp)
movl 0x18(%rax), %eax
movl %eax, 0xc(%rsp)
leaq 0x35d65(%rip), %r14     # 0xa3034
movl (%r14), %eax
testl %eax, %eax
jle 0x6d347
movq 0x660d9b(%rip), %rcx    # 0x6ce078
leaq 0x35d4c(%rip), %rdx     # 0xa3030
leaq 0x3c8ac5(%rip), %rsi    # 0x435db0
leaq 0x10ff92(%rip), %rdi    # 0x17d284
movslq (%rdx), %r9
testq %r9, %r9
jle 0x6d32b
movq %r9, %r8
incq %r8
leal -0x4(,%r9,4), %r9d
movq 0x20(%rsp), %r10
movslq %r9d, %r9
movzbl -0x2(%rcx,%r8), %r11d
movl (%rsi,%r11,4), %r11d
movl %r11d, (%r10,%r9)
decq %r8
addl $-0x4, %r9d
cmpq $0x1, %r8
jg 0x6d308
leal -0x1(%rax), %r8d
movslq 0xc(%rsp), %r9
addq %r9, 0x20(%rsp)
movslq (%rdi), %r9
addq %r9, %rcx
cmpl $0x1, %eax
movl %r8d, %eax
jg 0x6d2f2
cmpb $0x1, 0x65f092(%rip)    # 0x6cc3e0
jne 0x6d35e
movq 0x660cc9(%rip), %rdi    # 0x6ce020
callq 0x6300
jmp 0x6d36a
movq 0x660cc3(%rip), %rdi    # 0x6ce028
callq 0x6a20
cmpb $0x1, 0x65f06f(%rip)    # 0x6cc3e0
jne 0x6d38d
movq 0x660c9e(%rip), %rdi    # 0x6ce018
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0x6990
xorl %ebx, %ebx
jmp 0x6d3b3
movq 0x65ef3c(%rip), %rdi    # 0x6cc2d0
callq 0x64e0
testq %rax, %rax
je 0x6d23c
movq %rax, %rbx
movl 0x10(%rax), %eax
movl %eax, 0x8(%rsp)
movl 0x14(%rbx), %eax
movl %eax, 0x4(%rsp)
movslq 0x8(%rsp), %rdi
movl 0x4(%rsp), %r8d
movq %rdi, %rcx
shlq $0x10, %rcx
movslq %r8d, %r9
movq %rcx, %rax
cqto
idivq %r9
movq %rax, %rsi
leaq 0x35c57(%rip), %rax     # 0xa3030
movslq (%rax), %rax
movslq (%r14), %r10
shlq $0x10, %rax
cqto
idivq %r10
cmpl %eax, %esi
jge 0x6d414
movl $0x0, 0x10(%rsp)
movl %edi, 0x18(%rsp)
movslq %eax, %rsi
movq %rcx, %rax
cqto
idivq %rsi
movl %eax, 0x1c(%rsp)
subl %eax, %r8d
sarl %r8d
movl %r8d, 0x14(%rsp)
jmp 0x6d437
movl $0x0, 0x14(%rsp)
movl %r9d, 0x1c(%rsp)
cltq
imulq %r9, %rax
shrq $0x10, %rax
movl %eax, 0x18(%rsp)
subl %eax, %edi
sarl %edi
movl %edi, 0x10(%rsp)
cmpb $0x1, 0x65efa2(%rip)    # 0x6cc3e0
jne 0x6d47d
movq 0x660bd1(%rip), %rdi    # 0x6ce018
callq 0x6750
movq 0x660bc5(%rip), %rdi    # 0x6ce018
movq 0x660bc6(%rip), %rsi    # 0x6ce020
leaq 0x10(%rsp), %rcx
xorl %edx, %edx
callq 0x6100
testl %eax, %eax
je 0x6d46f
callq 0x6b40
movq 0x660ba2(%rip), %rdi    # 0x6ce018
callq 0x6b10
jmp 0x6d4c2
movq 0x8(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x6470
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
callq 0x6240
movq 0x660b89(%rip), %rdi    # 0x6ce028
leaq 0x10(%rsp), %rcx
xorl %esi, %esi
movq %rbx, %rdx
callq 0x6700
testl %eax, %eax
js 0x6d23c
movq 0x65ee13(%rip), %rdi    # 0x6cc2d0
callq 0x6c00
addq $0x28, %rsp
popq %rbx
popq %r14
retq