// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq (%rdi), %rdi
testq %rdi, %rdi
je 0x10470
movl %edx, %ebp
movl %esi, %r14d
testb %cl, %cl
je 0x103b8
movd 0x180(%rbx), %xmm0
movd %r14d, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2ps %xmm1, %xmm2
movaps %xmm2, 0x50(%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, 0x40(%rsp)
divps %xmm0, %xmm2
movaps %xmm2, 0x30(%rsp)
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movaps %xmm2, 0x20(%rsp)
leaq 0x1c(%rsp), %r15
leaq 0x18(%rsp), %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0x4140
movaps 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
ucomiss %xmm0, %xmm1
movaps 0x40(%rsp), %xmm2
mulss %xmm0, %xmm2
cvttss2si %xmm2, %esi
movaps 0x50(%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 0x10470
subss %xmm0, %xmm1
movaps 0x3d19(%rip), %xmm0     # 0x140b0
xorps %xmm1, %xmm0
maxss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd 0x3d36(%rip), %xmm0     # 0x140e0
jbe 0x10470
movq (%rbx), %rdi
jmp 0x1046b
movq 0x10(%rbx), %rdi
callq 0x4350
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0x8
popq %r15
xorl %edi, %edi
movl %r14d, %esi
movl %ebp, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x44d0
movq %rax, 0x10(%rbx)
movq 0x170(%rbx), %rsi
movq %rax, %rdi
callq 0x41d0
movq 0x10(%rbx), %rdi
pushq $0x1
popq %r12
pushq $0x4a
popq %r13
movl %r12d, %esi
movl %r13d, %edx
callq 0x4430
movq 0x20(%rbx), %rdi
callq 0x4350
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
xorl %edi, %edi
movl %r14d, %esi
movl %ebp, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x44d0
movq %rax, 0x20(%rbx)
movq 0x170(%rbx), %rsi
movq %rax, %rdi
callq 0x41d0
movq 0x20(%rbx), %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x4430
movl %r14d, 0x178(%rbx)
movl %ebp, 0x17c(%rbx)
movq (%rbx), %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x45f0
movb $0x1, %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop