// File: /workspace/github_cpp_makefile_star2_O1/khedoros[P]khednes/compositor.cpp
// Function: compositor::resize(int, int, bool)
bool compositor::resize(int x,int y, bool maintain_aspect/*=true*/) {
    if(!screen) return true;
    if(!maintain_aspect) {
        SDL_FreeSurface(buffer);
        buffer = SDL_CreateRGBSurface(0,x,y,8,0,0,0,0);
        SDL_SetSurfacePalette(buffer, palstruct);
        SDL_SetColorKey(buffer, SDL_TRUE, NES_TRANSPARENT);

        SDL_FreeSurface(overlay);
        overlay = SDL_CreateRGBSurface(0,x,y,8,0,0,0,0);
        SDL_SetSurfacePalette(overlay, palstruct);
        SDL_SetColorKey(overlay, SDL_TRUE, NES_TRANSPARENT);

        cur_x_res=x;
        cur_y_res=y;

        SDL_SetWindowSize(screen, x, y);
        return true;
    }
    else {
        float aspect = float(base_x_res)/float(base_y_res);
        float aspect2 = float(x)/float(y);
        float aspect3 = aspect2 - aspect;
        if(aspect3 < 0) aspect3 *= -1.0;
        //if(aspect3 < 0.05 ) return false;
        int wx,wy;
        SDL_GetWindowSize(screen,&wx,&wy);
        int nx,ny;
        if(aspect < aspect2) {
            nx = int(float(y)*aspect);
            ny = y;
        }
        else {
            nx = x;
            ny = int(float(x)/aspect);
        }
        //cout<<"C-aspect: "<<aspect<<" new aspect: "<<aspect2<<" diff: "<<aspect3<<endl;
        //cout<<"Old size: ("<<wx<<", "<<wy<<"), new size: ("<<nx<<", "<<ny<<")"<<endl;
        if((nx != wx || ny != wy ) && aspect3 > 0.1) {
            SDL_SetWindowSize(screen, nx, ny);
        }
    }

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
movq (%rdi), %rdi
testq %rdi, %rdi
je 0x126fd
movl %edx, %ebp
movl %esi, %r14d
testb %cl, %cl
je 0x12644
movd 0x180(%rbx), %xmm0
movd %r14d, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2ps %xmm1, %xmm2
movaps %xmm2, 0x40(%rsp)
movd 0x184(%rbx), %xmm0
movd %ebp, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2ps %xmm1, %xmm0
movaps %xmm0, 0x30(%rsp)
divps %xmm0, %xmm2
movaps %xmm2, 0x20(%rsp)
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movaps %xmm2, 0x10(%rsp)
leaq 0xc(%rsp), %r15
leaq 0x8(%rsp), %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0x4160
movaps 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
ucomiss %xmm0, %xmm1
movaps 0x30(%rsp), %xmm2
mulss %xmm0, %xmm2
cvttss2si %xmm2, %esi
movaps 0x40(%rsp), %xmm2
divss %xmm0, %xmm2
cvttss2si %xmm2, %edx
cmovbel %r14d, %esi
cmoval %ebp, %edx
movl (%r15), %eax
xorl %esi, %eax
movl (%r12), %ecx
xorl %edx, %ecx
orl %eax, %ecx
je 0x126fd
subss %xmm0, %xmm1
movaps 0x22fd(%rip), %xmm0     # 0x14920
xorps %xmm1, %xmm0
maxss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd 0x3aea(%rip), %xmm0     # 0x16120
jbe 0x126fd
movq (%rbx), %rdi
jmp 0x126f8
movq 0x10(%rbx), %rdi
callq 0x4360
xorl %r15d, %r15d
xorl %edi, %edi
movl %r14d, %esi
movl %ebp, %edx
movl $0x8, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r15
pushq %r15
callq 0x44e0
addq $0x10, %rsp
movq %rax, 0x10(%rbx)
movq 0x170(%rbx), %rsi
movq %rax, %rdi
callq 0x41e0
movq 0x10(%rbx), %rdi
movl $0x1, %esi
movl $0x4a, %edx
callq 0x4460
movq 0x20(%rbx), %rdi
callq 0x4360
xorl %edi, %edi
movl %r14d, %esi
movl %ebp, %edx
movl $0x8, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r15
pushq %r15
callq 0x44e0
addq $0x10, %rsp
movq %rax, 0x20(%rbx)
movq 0x170(%rbx), %rsi
movq %rax, %rdi
callq 0x41e0
movq 0x20(%rbx), %rdi
movl $0x1, %esi
movl $0x4a, %edx
callq 0x4460
movl %r14d, 0x178(%rbx)
movl %ebp, 0x17c(%rbx)
movq (%rbx), %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x45b0
movb $0x1, %al
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq