// File: /workspace/github_c_makefile_star2_O0/FredTheDino[P]Fog/src/engine/renderer/camera.cpp
// Function: Renderer::camera_fit_inplace(Renderer::Camera*, unsigned int, Vec2*, float)
void camera_fit_inplace(Camera *camera, u32 num_points, Vec2 *points, f32 border) {
    ASSERT(num_points, "No points given for camera to fit!");
    Vec2 min = *points;
    Vec2 max = *points;

    for (u32 i = 0; i < num_points; i++) {
        min.x = MIN(min.x, points[i].x);
        min.y = MIN(min.y, points[i].y);
        max.x = MAX(max.x, points[i].x);
        max.y = MAX(max.y, points[i].y);
    }
    camera->position = -(min + max) / 2.0;
    Vec2 radie = max + camera->position + V2(border, border);
    if (radie.x == 0.0 && radie.y == 0.0) {
        camera->zoom = 1.0;
    } else {
        f32 x = radie.x;
        f32 y = radie.y * camera->aspect_ratio;
        camera->zoom = 1.0 / MAX(x, y);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
cmpl $0x0, -0xc(%rbp)
setne %al
andb $0x1, %al
leaq 0x16628(%rip), %rdi     # 0x46503
movl $0x37, %esi
leaq 0x1665c(%rip), %rdx     # 0x46543
movzbl %al, %ecx
callq 0xb210
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x30028
movss -0x24(%rbp), %xmm1
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
movss (%rax,%rcx,8), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2ff3a
movss -0x24(%rbp), %xmm0
movss %xmm0, -0x7c(%rbp)
jmp 0x2ff4b
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
movss (%rax,%rcx,8), %xmm0
movss %xmm0, -0x7c(%rbp)
movss -0x7c(%rbp), %xmm0
movss %xmm0, -0x24(%rbp)
movss -0x20(%rbp), %xmm1
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
movss 0x4(%rax,%rcx,8), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2ff78
movss -0x20(%rbp), %xmm0
movss %xmm0, -0x80(%rbp)
jmp 0x2ff8a
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
movss 0x4(%rax,%rcx,8), %xmm0
movss %xmm0, -0x80(%rbp)
movss -0x80(%rbp), %xmm0
movss %xmm0, -0x20(%rbp)
movss -0x2c(%rbp), %xmm0
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
ucomiss (%rax,%rcx,8), %xmm0
jbe 0x2ffb5
movss -0x2c(%rbp), %xmm0
movss %xmm0, -0x84(%rbp)
jmp 0x2ffc9
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
movss (%rax,%rcx,8), %xmm0
movss %xmm0, -0x84(%rbp)
movss -0x84(%rbp), %xmm0
movss %xmm0, -0x2c(%rbp)
movss -0x28(%rbp), %xmm0
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
ucomiss 0x4(%rax,%rcx,8), %xmm0
jbe 0x2fff8
movss -0x28(%rbp), %xmm0
movss %xmm0, -0x88(%rbp)
jmp 0x3000d
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
movss 0x4(%rax,%rcx,8), %xmm0
movss %xmm0, -0x88(%rbp)
movss -0x88(%rbp), %xmm0
movss %xmm0, -0x28(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2ff0c
movq -0x2c(%rbp), %rax
movq %rax, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
leaq -0x24(%rbp), %rdi
callq 0x40dc0
movlpd %xmm0, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x40d80
movlpd %xmm0, -0x40(%rbp)
leaq -0x40(%rbp), %rdi
movss 0x1519b(%rip), %xmm0    # 0x451f8
callq 0x5c00
movlpd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
leaq -0x2c(%rbp), %rdi
callq 0x40dc0
movlpd %xmm0, -0x60(%rbp)
movss -0x1c(%rbp), %xmm1
movaps %xmm1, %xmm0
callq 0xbc10
movlpd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
leaq -0x60(%rbp), %rdi
callq 0x40dc0
movlpd %xmm0, -0x58(%rbp)
movss -0x58(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x300f0
jp 0x300f0
movss -0x54(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x300f0
jp 0x300f0
movq -0x8(%rbp), %rax
movss 0x14f1f(%rip), %xmm0    # 0x45008
movss %xmm0, 0x10(%rax)
jmp 0x30159
movss -0x58(%rbp), %xmm0
movss %xmm0, -0x74(%rbp)
movss -0x54(%rbp), %xmm0
movq -0x8(%rbp), %rax
mulss 0x14(%rax), %xmm0
movss %xmm0, -0x78(%rbp)
movss -0x74(%rbp), %xmm0
ucomiss -0x78(%rbp), %xmm0
jbe 0x30127
movss -0x74(%rbp), %xmm0
movss %xmm0, -0x8c(%rbp)
jmp 0x30134
movss -0x78(%rbp), %xmm0
movss %xmm0, -0x8c(%rbp)
movss -0x8c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x14f18(%rip), %xmm0    # 0x45060
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x10(%rax)
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)