#include "screen.cuh"
#include "trace_manager.cuh"

#include <stdio.h>
#include <assert.h>
#include <math.h>

#define PI 3.1415



int main() {
    int width = 1920;
    int height = 1080;

    create_screen(width, height);
    TraceManager trace_manager = TraceManager(width, height);


    int w = 128;
    int h = 128;
    Block* world = new Block[w * h];

    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {

            float r = (x + y) % 3 == 0 ? 1.0 : 0.0;
            float g = (x + y) % 3 == 1 ? 1.0 : 0.0;
            float b = (x + y) % 3 == 2 ? 1.0 : 0.0;

            int r2 = 10000;
            int y2 = r2 - (x - 100) * (x - 100) - (y - 100) * (y - 100);
            
            float py = 10.0;
            if (y2 > 0.0) {
                py = sqrt(y2) + 10.0;
            }
            

            world[x * h + y] = Block(AABB3(Vec3((float)x, py - 10.0, (float)y), Vec3((float)x + 1.0, py, (float)y + 1.0)), Vec3(r, g, b));
            printf("(%f, %f)\n", (float)x, (float)y);
        }
    }

    trace_manager.upload_world(world, w * h);

    Vec3 position = Vec3(5.5, 85.0, -2.0);
    Vec3 f = Vec3(0.0, 0.0, 1.0).normalize();
    Vec3 side = Vec3(1.0, 0.0, 0.0).normalize();
    Vec3 up = Vec3(0.0, 1.0, 0.0).normalize();

    Vec3 rotation_axis = Vec3(0.0, 1.0, 0.0);

    float rotation_x = 0.0;
    float rotation_y = 0.0;

    float t = 1.0;
    int i = 0;
    while (true)
    {
        double mouse_delta_x, mouse_delta_y;
        mouse_delta(&mouse_delta_x, &mouse_delta_y);
        rotation_x += mouse_delta_x / 100.0;
        rotation_y += mouse_delta_y / 100.0;

        Vec3 forward;
        forward = f.rotate(side, rotation_y);
        forward = forward.rotate(up, rotation_x);


        if (key_pressed(KEY::W)) {
            position += Vec3(forward.x, 0.0, forward.z).normalize() * 1.0;
        }

        if (key_pressed(KEY::A)) {
            position += Vec3(-forward.z, 0.0, forward.x).normalize() * 1.0;
        }

        if (key_pressed(KEY::S)) {
            position -= Vec3(forward.x, 0.0, forward.z).normalize() * 1.0;
        }

        if (key_pressed(KEY::D)) {
            position += Vec3(forward.z, 0.0, -forward.x).normalize() * 1.0;
        }

        if (key_pressed(KEY::UP)) {
            rotation_y += 0.016;
        }

        if (key_pressed(KEY::DOWN)) {
            rotation_y -= 0.016;
        }

        // if (key_pressed(KEY::A))
        // Vec3 position = Vec3(cos(t) * 110.0, 3.0, sin(t) * 110.0);
        // Vec3 forward = position - Vec3(0.0, 3.0, 0.0);
        // Vec3 side = Vec3(-cos(t - 0.5 * PI), 0.0, -sin(t - 0.5 * PI));
        // Vec3 up = forward.cross(side);
        // forward = forward.normalize();

        // printf("Forward: %f, %f, %f\n", forward.x, forward.y, forward.z);

        // printf("t: %f\n", t);

        

        Frustrum view = Frustrum(position, forward * t, 1920.0 / 1080.0);

        float* surface = trace_manager.render_frame(view);
        render_frame(surface);
        // printf("frame: %i\n", i);
        i++;
    }

    opengl_exit();
}
	.file	"tmpxft_00314635_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2041:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2041:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.text._ZmlRK4Vec3f,"axG",@progbits,_ZmlRK4Vec3f,comdat
	.weak	_ZmlRK4Vec3f
	.type	_ZmlRK4Vec3f, @function
_ZmlRK4Vec3f:
.LFB2012:
	.cfi_startproc
	endbr64
	subq	$56, %rsp
	.cfi_def_cfa_offset 64
	movss	8(%rdi), %xmm2
	movaps	%xmm0, %xmm1
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	mulss	(%rdi), %xmm0
	leaq	16(%rsp), %rax
	mulss	%xmm1, %xmm2
	mulss	4(%rdi), %xmm1
	movq	%rax, %rdi
	call	_ZN4Vec3C1Efff@PLT
	movl	24(%rsp), %eax
	movq	16(%rsp), %xmm0
	movl	%eax, 36(%rsp)
	movss	36(%rsp), %xmm1
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L3
	call	__stack_chk_fail@PLT
.L3:
	addq	$56, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2012:
	.size	_ZmlRK4Vec3f, .-_ZmlRK4Vec3f
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC4:
	.string	"(%f, %f)\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2038:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA2038
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$1080, %esi
	movl	$1920, %edi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$408, %rsp
	.cfi_def_cfa_offset 464
	movq	%fs:40, %rax
	movq	%rax, 392(%rsp)
	xorl	%eax, %eax
.LEHB0:
	call	_Z13create_screenii@PLT
	movl	$1080, %edx
	movl	$1920, %esi
	leaq	200(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 40(%rsp)
	call	_ZN12TraceManagerC1Eii@PLT
	movl	$589824, %edi
	call	_Znam@PLT
.LEHE0:
	movq	%rax, %rbx
	leaq	589824(%rax), %r12
	movq	%rax, %rbp
.L7:
	movq	%rbp, %rdi
.LEHB1:
	call	_ZN5BlockC1Ev@PLT
.LEHE1:
	addq	$36, %rbp
	cmpq	%r12, %rbp
	jne	.L7
	xorl	%r15d, %r15d
.L8:
	leal	-100(%r15), %eax
	movl	$10000, %edx
	movl	%r15d, %r14d
	movl	%r15d, %r13d
	imull	%eax, %eax
	xorl	%ebp, %ebp
	imulq	$4608, %r15, %r12
	subl	%eax, %edx
	movl	%edx, 60(%rsp)
	addq	%rbx, %r12
.L11:
	leal	0(%rbp,%r14), %eax
	movl	$3, %ecx
	cltd
	idivl	%ecx
	testl	%edx, %edx
	je	.L23
	decl	%edx
	jne	.L24
	xorps	%xmm3, %xmm3
	movss	.LC1(%rip), %xmm1
	movaps	%xmm3, %xmm2
	jmp	.L9
.L23:
	xorps	%xmm1, %xmm1
	movss	.LC1(%rip), %xmm3
	movaps	%xmm1, %xmm2
	jmp	.L9
.L24:
	xorps	%xmm1, %xmm1
	movss	.LC1(%rip), %xmm2
	movaps	%xmm1, %xmm3
.L9:
	leal	-100(%rbp), %eax
	movl	60(%rsp), %edx
	imull	%eax, %eax
	subl	%eax, %edx
	testl	%edx, %edx
	jle	.L25
	cvtsi2sdl	%edx, %xmm0
	movss	%xmm1, 32(%rsp)
	movss	%xmm3, 24(%rsp)
	movss	%xmm2, 16(%rsp)
	call	sqrt@PLT
	addsd	.LC3(%rip), %xmm0
	movss	16(%rsp), %xmm2
	movss	24(%rsp), %xmm3
	movss	32(%rsp), %xmm1
	cvtsd2ss	%xmm0, %xmm5
	movss	%xmm5, 8(%rsp)
	jmp	.L10
.L25:
	movl	$0x41200000, 8(%rsp)
.L10:
	leaq	164(%rsp), %rax
	movaps	%xmm3, %xmm0
	movq	%rax, %rdi
	movq	%rax, 24(%rsp)
.LEHB2:
	call	_ZN4Vec3C1Efff@PLT
	cvtsi2ssl	%ebp, %xmm6
	movss	.LC1(%rip), %xmm0
	movss	.LC1(%rip), %xmm2
	cvtsi2ssl	%r13d, %xmm7
	movss	8(%rsp), %xmm1
	leaq	152(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	addss	%xmm6, %xmm2
	movss	%xmm6, 52(%rsp)
	addss	%xmm7, %xmm0
	movss	%xmm7, 56(%rsp)
	call	_ZN4Vec3C1Efff@PLT
	cvtsi2ssl	%ebp, %xmm2
	incl	%ebp
	movss	8(%rsp), %xmm1
	cvtsi2ssl	%r13d, %xmm0
	subss	.LC2(%rip), %xmm1
	leaq	140(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 32(%rsp)
	call	_ZN4Vec3C1Efff@PLT
	leaq	176(%rsp), %rdi
	movq	152(%rsp), %xmm2
	movss	160(%rsp), %xmm3
	movq	140(%rsp), %xmm0
	movss	148(%rsp), %xmm1
	call	_ZN5AABB3C1E4Vec3S0_@PLT
	leaq	248(%rsp), %rax
	subq	$32, %rsp
	.cfi_def_cfa_offset 496
	movq	%rax, 40(%rsp)
	movups	208(%rsp), %xmm6
	movq	224(%rsp), %rax
	movq	40(%rsp), %rdi
	movq	196(%rsp), %xmm0
	movups	%xmm6, (%rsp)
	movss	204(%rsp), %xmm1
	movq	%rax, 16(%rsp)
	call	_ZN5BlockC1E5AABB34Vec3@PLT
	movq	40(%rsp), %rsi
	movq	%r12, %rdi
	movb	$2, %al
	movl	$9, %ecx
	addq	$32, %rsp
	.cfi_def_cfa_offset 464
	cvtss2sd	56(%rsp), %xmm0
	cvtss2sd	52(%rsp), %xmm1
	rep movsl
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	addq	$36, %r12
	call	__printf_chk@PLT
	cmpl	$128, %ebp
	jne	.L11
	incq	%r15
	cmpq	$128, %r15
	jne	.L8
	movq	40(%rsp), %rdi
	movq	%rbx, %rsi
	movl	$16384, %edx
	xorl	%ebx, %ebx
	xorl	%ebp, %ebp
	call	_ZN12TraceManager12upload_worldEP5Blocki@PLT
	movss	.LC5(%rip), %xmm2
	leaq	80(%rsp), %rdi
	movss	.LC6(%rip), %xmm1
	movss	.LC7(%rip), %xmm0
	call	_ZN4Vec3C1Efff@PLT
	xorps	%xmm1, %xmm1
	movq	8(%rsp), %rdi
	movss	.LC1(%rip), %xmm2
	movaps	%xmm1, %xmm0
	call	_ZN4Vec3C1Efff@PLT
	movq	8(%rsp), %rdi
	call	_ZN4Vec39normalizeEv@PLT
	xorps	%xmm2, %xmm2
	movq	8(%rsp), %rdi
	movq	%xmm0, 92(%rsp)
	movss	.LC1(%rip), %xmm0
	movss	%xmm1, 100(%rsp)
	movaps	%xmm2, %xmm1
	call	_ZN4Vec3C1Efff@PLT
	movq	8(%rsp), %rdi
	call	_ZN4Vec39normalizeEv@PLT
	xorps	%xmm2, %xmm2
	movq	8(%rsp), %rdi
	movss	%xmm1, 112(%rsp)
	movss	.LC1(%rip), %xmm1
	movq	%xmm0, 104(%rsp)
	movaps	%xmm2, %xmm0
	call	_ZN4Vec3C1Efff@PLT
	movq	8(%rsp), %rdi
	call	_ZN4Vec39normalizeEv@PLT
	xorps	%xmm2, %xmm2
	leaq	128(%rsp), %rdi
	movss	%xmm1, 124(%rsp)
	movss	.LC1(%rip), %xmm1
	movq	%xmm0, 116(%rsp)
	movaps	%xmm2, %xmm0
	call	_ZN4Vec3C1Efff@PLT
.L19:
	leaq	72(%rsp), %rsi
	leaq	64(%rsp), %rdi
	call	_Z11mouse_deltaPdS_@PLT
	movd	%ebp, %xmm7
	movsd	64(%rsp), %xmm0
	divsd	.LC8(%rip), %xmm0
	cvtss2sd	%xmm7, %xmm1
	addsd	%xmm1, %xmm0
	movd	%ebx, %xmm5
	movq	32(%rsp), %rdi
	cvtss2sd	%xmm5, %xmm1
	cvtsd2ss	%xmm0, %xmm4
	movsd	72(%rsp), %xmm0
	movd	%xmm4, %ebp
	divsd	.LC8(%rip), %xmm0
	addsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm6
	movd	%xmm6, %ebx
	call	_ZN4Vec3C1Ev@PLT
	movq	104(%rsp), %xmm0
	movss	112(%rsp), %xmm1
	leaq	92(%rsp), %rdi
	movd	%ebx, %xmm2
	call	_ZN4Vec36rotateES_f@PLT
	movq	32(%rsp), %rdi
	movd	%ebp, %xmm2
	movq	%xmm0, 140(%rsp)
	movq	116(%rsp), %xmm0
	movss	%xmm1, 148(%rsp)
	movss	124(%rsp), %xmm1
	call	_ZN4Vec36rotateES_f@PLT
	xorl	%edi, %edi
	movq	%xmm0, 140(%rsp)
	movss	%xmm1, 148(%rsp)
	call	_Z11key_pressed3KEY@PLT
	testb	%al, %al
	je	.L13
	movss	140(%rsp), %xmm0
	movq	16(%rsp), %rdi
	xorps	%xmm1, %xmm1
	movss	148(%rsp), %xmm2
	call	_ZN4Vec3C1Efff@PLT
	movq	16(%rsp), %rdi
	call	_ZN4Vec39normalizeEv@PLT
	movq	24(%rsp), %rdi
	movq	%xmm0, 164(%rsp)
	movss	.LC1(%rip), %xmm0
	movss	%xmm1, 172(%rsp)
	call	_ZmlRK4Vec3f
	movq	%xmm0, 248(%rsp)
	movss	80(%rsp), %xmm0
	addss	248(%rsp), %xmm0
	movss	%xmm1, 256(%rsp)
	addss	88(%rsp), %xmm1
	movss	%xmm0, 80(%rsp)
	movss	84(%rsp), %xmm0
	addss	252(%rsp), %xmm0
	movss	%xmm1, 88(%rsp)
	movss	%xmm0, 84(%rsp)
.L13:
	movl	$1, %edi
	call	_Z11key_pressed3KEY@PLT
	testb	%al, %al
	je	.L14
	movss	140(%rsp), %xmm2
	movq	16(%rsp), %rdi
	xorps	%xmm1, %xmm1
	movss	148(%rsp), %xmm0
	xorps	.LC9(%rip), %xmm0
	call	_ZN4Vec3C1Efff@PLT
	movq	16(%rsp), %rdi
	call	_ZN4Vec39normalizeEv@PLT
	movq	24(%rsp), %rdi
	movq	%xmm0, 164(%rsp)
	movss	.LC1(%rip), %xmm0
	movss	%xmm1, 172(%rsp)
	call	_ZmlRK4Vec3f
	movq	%xmm0, 248(%rsp)
	movss	80(%rsp), %xmm0
	addss	248(%rsp), %xmm0
	movss	%xmm1, 256(%rsp)
	addss	88(%rsp), %xmm1
	movss	%xmm0, 80(%rsp)
	movss	84(%rsp), %xmm0
	addss	252(%rsp), %xmm0
	movss	%xmm1, 88(%rsp)
	movss	%xmm0, 84(%rsp)
.L14:
	movl	$2, %edi
	call	_Z11key_pressed3KEY@PLT
	testb	%al, %al
	je	.L15
	movss	140(%rsp), %xmm0
	movq	16(%rsp), %rdi
	xorps	%xmm1, %xmm1
	movss	148(%rsp), %xmm2
	call	_ZN4Vec3C1Efff@PLT
	movq	16(%rsp), %rdi
	call	_ZN4Vec39normalizeEv@PLT
	movq	24(%rsp), %rdi
	movq	%xmm0, 164(%rsp)
	movss	.LC1(%rip), %xmm0
	movss	%xmm1, 172(%rsp)
	call	_ZmlRK4Vec3f
	movq	%xmm0, 248(%rsp)
	movss	80(%rsp), %xmm0
	subss	248(%rsp), %xmm0
	movss	%xmm1, 256(%rsp)
	movss	%xmm0, 80(%rsp)
	movss	84(%rsp), %xmm0
	subss	252(%rsp), %xmm0
	movss	%xmm0, 84(%rsp)
	movss	88(%rsp), %xmm0
	subss	%xmm1, %xmm0
	movss	%xmm0, 88(%rsp)
.L15:
	movl	$3, %edi
	call	_Z11key_pressed3KEY@PLT
	testb	%al, %al
	je	.L16
	movss	148(%rsp), %xmm0
	movq	16(%rsp), %rdi
	xorps	%xmm1, %xmm1
	movss	140(%rsp), %xmm2
	xorps	.LC9(%rip), %xmm2
	call	_ZN4Vec3C1Efff@PLT
	movq	16(%rsp), %rdi
	call	_ZN4Vec39normalizeEv@PLT
	movq	24(%rsp), %rdi
	movq	%xmm0, 164(%rsp)
	movss	.LC1(%rip), %xmm0
	movss	%xmm1, 172(%rsp)
	call	_ZmlRK4Vec3f
	movq	%xmm0, 248(%rsp)
	movss	80(%rsp), %xmm0
	addss	248(%rsp), %xmm0
	movss	%xmm1, 256(%rsp)
	addss	88(%rsp), %xmm1
	movss	%xmm0, 80(%rsp)
	movss	84(%rsp), %xmm0
	addss	252(%rsp), %xmm0
	movss	%xmm1, 88(%rsp)
	movss	%xmm0, 84(%rsp)
.L16:
	movl	$4, %edi
	call	_Z11key_pressed3KEY@PLT
	testb	%al, %al
	je	.L17
	movd	%ebx, %xmm7
	cvtss2sd	%xmm7, %xmm0
	addsd	.LC10(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm4
	movd	%xmm4, %ebx
.L17:
	movl	$5, %edi
	call	_Z11key_pressed3KEY@PLT
	testb	%al, %al
	je	.L18
	movd	%ebx, %xmm5
	cvtss2sd	%xmm5, %xmm0
	subsd	.LC10(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm6
	movd	%xmm6, %ebx
.L18:
	movq	32(%rsp), %rdi
	movss	.LC1(%rip), %xmm0
	call	_ZmlRK4Vec3f
	movq	8(%rsp), %rdi
	movss	.LC11(%rip), %xmm4
	movq	%xmm0, 176(%rsp)
	movaps	%xmm1, %xmm3
	movaps	%xmm0, %xmm2
	movq	80(%rsp), %xmm0
	movss	%xmm1, 184(%rsp)
	movss	88(%rsp), %xmm1
	call	_ZN8FrustrumC1E4Vec3S0_f@PLT
	subq	$144, %rsp
	.cfi_def_cfa_offset 608
	movl	$36, %ecx
	movq	152(%rsp), %rsi
	movq	%rsp, %rdi
	rep movsl
	movq	184(%rsp), %rdi
	call	_ZN12TraceManager12render_frameE8Frustrum@PLT
	addq	$144, %rsp
	.cfi_def_cfa_offset 464
	movq	%rax, %rdi
	call	_Z12render_framePv@PLT
	jmp	.L19
.L26:
	endbr64
	movq	%rax, %rbp
.L20:
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
	movq	392(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	movq	%rbp, %rdi
	call	_Unwind_Resume@PLT
.LEHE2:
	.cfi_endproc
.LFE2038:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA2038:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE2038-.LLSDACSB2038
.LLSDACSB2038:
	.uleb128 .LEHB0-.LFB2038
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB2038
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L26-.LFB2038
	.uleb128 0
	.uleb128 .LEHB2-.LFB2038
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE2038:
	.section	.text.startup
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2064:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2064:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	1065353216
	.align 4
.LC2:
	.long	1092616192
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC3:
	.long	0
	.long	1076101120
	.section	.rodata.cst4
	.align 4
.LC5:
	.long	-1073741824
	.align 4
.LC6:
	.long	1118437376
	.align 4
.LC7:
	.long	1085276160
	.section	.rodata.cst8
	.align 8
.LC8:
	.long	0
	.long	1079574528
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC9:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC10:
	.long	-755914244
	.long	1066426957
	.section	.rodata.cst4
	.align 4
.LC11:
	.long	1071877689
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include "screen.cuh"
#include "trace_manager.cuh"

#include <stdio.h>
#include <assert.h>
#include <math.h>

#define PI 3.1415



int main() {
    int width = 1920;
    int height = 1080;

    create_screen(width, height);
    TraceManager trace_manager = TraceManager(width, height);


    int w = 128;
    int h = 128;
    Block* world = new Block[w * h];

    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {

            float r = (x + y) % 3 == 0 ? 1.0 : 0.0;
            float g = (x + y) % 3 == 1 ? 1.0 : 0.0;
            float b = (x + y) % 3 == 2 ? 1.0 : 0.0;

            int r2 = 10000;
            int y2 = r2 - (x - 100) * (x - 100) - (y - 100) * (y - 100);
            
            float py = 10.0;
            if (y2 > 0.0) {
                py = sqrt(y2) + 10.0;
            }
            

            world[x * h + y] = Block(AABB3(Vec3((float)x, py - 10.0, (float)y), Vec3((float)x + 1.0, py, (float)y + 1.0)), Vec3(r, g, b));
            printf("(%f, %f)\n", (float)x, (float)y);
        }
    }

    trace_manager.upload_world(world, w * h);

    Vec3 position = Vec3(5.5, 85.0, -2.0);
    Vec3 f = Vec3(0.0, 0.0, 1.0).normalize();
    Vec3 side = Vec3(1.0, 0.0, 0.0).normalize();
    Vec3 up = Vec3(0.0, 1.0, 0.0).normalize();

    Vec3 rotation_axis = Vec3(0.0, 1.0, 0.0);

    float rotation_x = 0.0;
    float rotation_y = 0.0;

    float t = 1.0;
    int i = 0;
    while (true)
    {
        double mouse_delta_x, mouse_delta_y;
        mouse_delta(&mouse_delta_x, &mouse_delta_y);
        rotation_x += mouse_delta_x / 100.0;
        rotation_y += mouse_delta_y / 100.0;

        Vec3 forward;
        forward = f.rotate(side, rotation_y);
        forward = forward.rotate(up, rotation_x);


        if (key_pressed(KEY::W)) {
            position += Vec3(forward.x, 0.0, forward.z).normalize() * 1.0;
        }

        if (key_pressed(KEY::A)) {
            position += Vec3(-forward.z, 0.0, forward.x).normalize() * 1.0;
        }

        if (key_pressed(KEY::S)) {
            position -= Vec3(forward.x, 0.0, forward.z).normalize() * 1.0;
        }

        if (key_pressed(KEY::D)) {
            position += Vec3(forward.z, 0.0, -forward.x).normalize() * 1.0;
        }

        if (key_pressed(KEY::UP)) {
            rotation_y += 0.016;
        }

        if (key_pressed(KEY::DOWN)) {
            rotation_y -= 0.016;
        }

        // if (key_pressed(KEY::A))
        // Vec3 position = Vec3(cos(t) * 110.0, 3.0, sin(t) * 110.0);
        // Vec3 forward = position - Vec3(0.0, 3.0, 0.0);
        // Vec3 side = Vec3(-cos(t - 0.5 * PI), 0.0, -sin(t - 0.5 * PI));
        // Vec3 up = forward.cross(side);
        // forward = forward.normalize();

        // printf("Forward: %f, %f, %f\n", forward.x, forward.y, forward.z);

        // printf("t: %f\n", t);

        

        Frustrum view = Frustrum(position, forward * t, 1920.0 / 1080.0);

        float* surface = trace_manager.render_frame(view);
        render_frame(surface);
        // printf("frame: %i\n", i);
        i++;
    }

    opengl_exit();
}
	.text
	.file	"main.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI0_0:
	.quad	0x3ff0000000000000              # double 1
.LCPI0_3:
	.quad	0x4024000000000000              # double 10
.LCPI0_8:
	.quad	0x4059000000000000              # double 100
.LCPI0_10:
	.quad	0x3f90624dd2f1a9fc              # double 0.016
.LCPI0_11:
	.quad	0xbf90624dd2f1a9fc              # double -0.016
.LCPI0_13:
	.quad	0x0000000000000000              # double 0
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI0_1:
	.long	0x3f800000                      # float 1
.LCPI0_2:
	.long	0x41200000                      # float 10
.LCPI0_4:
	.long	0xc1200000                      # float -10
.LCPI0_5:
	.long	0x40b00000                      # float 5.5
.LCPI0_6:
	.long	0x42aa0000                      # float 85
.LCPI0_7:
	.long	0xc0000000                      # float -2
.LCPI0_12:
	.long	0x3fe38e39                      # float 1.77777779
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI0_9:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$600, %rsp                      # imm = 0x258
	.cfi_def_cfa_offset 656
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$1920, %edi                     # imm = 0x780
	movl	$1080, %esi                     # imm = 0x438
	callq	_Z13create_screenii
	leaq	552(%rsp), %rdi
	movl	$1920, %esi                     # imm = 0x780
	movl	$1080, %edx                     # imm = 0x438
	callq	_ZN12TraceManagerC1Eii
	movl	$589824, %edi                   # imm = 0x90000
	callq	_Znam
	movq	%rax, %r12
	xorl	%ebx, %ebx
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	leaq	(%r12,%rbx), %rdi
.Ltmp0:
	callq	_ZN5BlockC1Ev
.Ltmp1:
# %bb.2:                                #   in Loop: Header=BB0_1 Depth=1
	addq	$36, %rbx
	cmpq	$589824, %rbx                   # imm = 0x90000
	jne	.LBB0_1
# %bb.3:                                # %.preheader174
	xorl	%ebx, %ebx
	movss	.LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	leaq	368(%rsp), %rbp
	movq	%r12, 256(%rsp)                 # 8-byte Spill
	xorl	%eax, %eax
.LBB0_4:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_5 Depth 2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, 196(%rsp)                # 4-byte Spill
	leaq	-100(%rax), %r14
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	%xmm0, 208(%rsp)                # 8-byte Spill
	addsd	.LCPI0_0(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 192(%rsp)                # 4-byte Spill
	imulq	%r14, %r14
	movq	%rax, 264(%rsp)                 # 8-byte Spill
	movl	%eax, %r15d
	movq	%r12, 272(%rsp)                 # 8-byte Spill
	xorl	%r13d, %r13d
.LBB0_5:                                #   Parent Loop BB0_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r15d, %eax
	movl	$2863311531, %ecx               # imm = 0xAAAAAAAB
	imulq	%rcx, %rax
	shrq	$33, %rax
	leal	(%rax,%rax,2), %eax
	leal	(%rbx,%rax), %ecx
	movaps	%xmm1, %xmm0
	cmpl	%r13d, %ecx
	je	.LBB0_7
# %bb.6:                                #   in Loop: Header=BB0_5 Depth=2
	xorps	%xmm0, %xmm0
.LBB0_7:                                #   in Loop: Header=BB0_5 Depth=2
	leal	(%rbx,%rax), %ecx
	incl	%ecx
	movaps	%xmm1, %xmm2
	cmpl	%r13d, %ecx
	je	.LBB0_9
# %bb.8:                                #   in Loop: Header=BB0_5 Depth=2
	xorps	%xmm2, %xmm2
.LBB0_9:                                #   in Loop: Header=BB0_5 Depth=2
	movss	%xmm0, 156(%rsp)                # 4-byte Spill
	addl	%ebx, %eax
	addl	$2, %eax
	cmpl	%r13d, %eax
	je	.LBB0_11
# %bb.10:                               #   in Loop: Header=BB0_5 Depth=2
	xorps	%xmm1, %xmm1
.LBB0_11:                               #   in Loop: Header=BB0_5 Depth=2
	movss	%xmm1, 240(%rsp)                # 4-byte Spill
	movss	%xmm2, 172(%rsp)                # 4-byte Spill
	leaq	-100(%r13), %rax
	imulq	%rax, %rax
	addq	%r14, %rax
	movss	.LCPI0_2(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	cmpl	$9999, %eax                     # imm = 0x270F
	ja	.LBB0_32
# %bb.12:                               #   in Loop: Header=BB0_5 Depth=2
	movl	$10000, %ecx                    # imm = 0x2710
	subl	%eax, %ecx
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ecx, %xmm0
	ucomisd	.LCPI0_13(%rip), %xmm0
	jb	.LBB0_30
# %bb.13:                               #   in Loop: Header=BB0_5 Depth=2
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB0_31
.LBB0_30:                               # %call.sqrt
                                        #   in Loop: Header=BB0_5 Depth=2
	callq	sqrt
.LBB0_31:                               # %.split
                                        #   in Loop: Header=BB0_5 Depth=2
	addsd	.LCPI0_3(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
.LBB0_32:                               #   in Loop: Header=BB0_5 Depth=2
	movaps	%xmm0, %xmm1
	movss	%xmm0, 224(%rsp)                # 4-byte Spill
	addss	.LCPI0_4(%rip), %xmm1
	xorps	%xmm2, %xmm2
	cvtsi2ss	%r13d, %xmm2
	leaq	328(%rsp), %rdi
	movss	196(%rsp), %xmm0                # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	callq	_ZN4Vec3C1Efff
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r13d, %xmm0
	movsd	%xmm0, 200(%rsp)                # 8-byte Spill
	addsd	.LCPI0_0(%rip), %xmm0
	xorps	%xmm2, %xmm2
	cvtsd2ss	%xmm0, %xmm2
	leaq	312(%rsp), %rdi
	movss	192(%rsp), %xmm0                # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	movss	224(%rsp), %xmm1                # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	callq	_ZN4Vec3C1Efff
	movsd	328(%rsp), %xmm0                # xmm0 = mem[0],zero
	movss	336(%rsp), %xmm1                # xmm1 = mem[0],zero,zero,zero
	movsd	312(%rsp), %xmm2                # xmm2 = mem[0],zero
	movss	320(%rsp), %xmm3                # xmm3 = mem[0],zero,zero,zero
	leaq	344(%rsp), %rdi
	callq	_ZN5AABB3C1E4Vec3S0_
	leaq	296(%rsp), %rdi
	movss	156(%rsp), %xmm0                # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	movss	172(%rsp), %xmm1                # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movss	240(%rsp), %xmm2                # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	callq	_ZN4Vec3C1Efff
	movsd	296(%rsp), %xmm0                # xmm0 = mem[0],zero
	movss	304(%rsp), %xmm1                # xmm1 = mem[0],zero,zero,zero
	movq	360(%rsp), %rax
	movq	%rax, 16(%rsp)
	movups	344(%rsp), %xmm2
	movups	%xmm2, (%rsp)
	movq	%rbp, %rdi
	callq	_ZN5BlockC1E5AABB34Vec3
	movl	400(%rsp), %eax
	movl	%eax, 32(%r12)
	movups	368(%rsp), %xmm0
	movups	384(%rsp), %xmm1
	movups	%xmm1, 16(%r12)
	movups	%xmm0, (%r12)
	movl	$.L.str, %edi
	movsd	208(%rsp), %xmm0                # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movsd	200(%rsp), %xmm1                # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movb	$2, %al
	callq	printf
	incq	%r13
	addq	$36, %r12
	incl	%r15d
	cmpq	$128, %r13
	movss	.LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	jne	.LBB0_5
# %bb.15:                               #   in Loop: Header=BB0_4 Depth=1
	movq	264(%rsp), %rax                 # 8-byte Reload
	incq	%rax
	movq	272(%rsp), %r12                 # 8-byte Reload
	addq	$4608, %r12                     # imm = 0x1200
	decl	%ebx
	cmpq	$128, %rax
	jne	.LBB0_4
# %bb.16:
	leaq	552(%rsp), %rdi
	movq	256(%rsp), %rsi                 # 8-byte Reload
	movl	$16384, %edx                    # imm = 0x4000
	callq	_ZN12TraceManager12upload_worldEP5Blocki
	leaq	160(%rsp), %rdi
	movss	.LCPI0_5(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI0_6(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movss	.LCPI0_7(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	callq	_ZN4Vec3C1Efff
	leaq	368(%rsp), %r14
	xorps	%xmm0, %xmm0
	movss	%xmm0, 156(%rsp)                # 4-byte Spill
	movss	.LCPI0_1(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	xorps	%xmm1, %xmm1
	movq	%r14, %rdi
	callq	_ZN4Vec3C1Efff
	movq	%r14, %rdi
	callq	_ZN4Vec39normalizeEv
	leaq	512(%rsp), %r15
	movlps	%xmm0, (%r15)
	movss	%xmm1, 8(%r15)
	leaq	368(%rsp), %rbx
	xorps	%xmm1, %xmm1
	xorps	%xmm2, %xmm2
	movq	%rbx, %rdi
	movss	.LCPI0_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	callq	_ZN4Vec3C1Efff
	movq	%rbx, %rdi
	callq	_ZN4Vec39normalizeEv
	movaps	%xmm0, 224(%rsp)                # 16-byte Spill
	movss	%xmm1, 196(%rsp)                # 4-byte Spill
	leaq	368(%rsp), %rbx
	xorps	%xmm0, %xmm0
	xorps	%xmm2, %xmm2
	movq	%rbx, %rdi
	movss	.LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	callq	_ZN4Vec3C1Efff
	movq	%rbx, %rdi
	callq	_ZN4Vec39normalizeEv
	movaps	%xmm0, 208(%rsp)                # 16-byte Spill
	movss	%xmm1, 192(%rsp)                # 4-byte Spill
	leaq	540(%rsp), %rdi
	xorps	%xmm0, %xmm0
	xorps	%xmm2, %xmm2
	movss	.LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	callq	_ZN4Vec3C1Efff
	leaq	288(%rsp), %r12
	leaq	280(%rsp), %r13
	leaq	176(%rsp), %rbp
	leaq	528(%rsp), %rbx
	xorps	%xmm0, %xmm0
	movss	%xmm0, 172(%rsp)                # 4-byte Spill
.LBB0_17:                               # =>This Inner Loop Header: Depth=1
	movq	%r12, %rdi
	movq	%r13, %rsi
	callq	_Z11mouse_deltaPdS_
	movsd	288(%rsp), %xmm0                # xmm0 = mem[0],zero
	movsd	.LCPI0_8(%rip), %xmm2           # xmm2 = mem[0],zero
	divsd	%xmm2, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	172(%rsp), %xmm1                # 4-byte Folded Reload
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, 172(%rsp)                # 4-byte Spill
	movsd	280(%rsp), %xmm0                # xmm0 = mem[0],zero
	divsd	%xmm2, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	156(%rsp), %xmm1                # 4-byte Folded Reload
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, 156(%rsp)                # 4-byte Spill
	movq	%rbp, %rdi
	callq	_ZN4Vec3C1Ev
	movq	%r15, %rdi
	movaps	224(%rsp), %xmm0                # 16-byte Reload
	movss	196(%rsp), %xmm1                # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movss	156(%rsp), %xmm2                # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	callq	_ZN4Vec36rotateES_f
	movlps	%xmm0, 176(%rsp)
	movss	%xmm1, 184(%rsp)
	movq	%rbp, %rdi
	movaps	208(%rsp), %xmm0                # 16-byte Reload
	movss	192(%rsp), %xmm1                # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movss	172(%rsp), %xmm2                # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	callq	_ZN4Vec36rotateES_f
	movlps	%xmm0, 176(%rsp)
	movss	%xmm1, 184(%rsp)
	xorl	%edi, %edi
	callq	_Z11key_pressed3KEY
	testb	%al, %al
	je	.LBB0_19
# %bb.18:                               #   in Loop: Header=BB0_17 Depth=1
	movss	176(%rsp), %xmm0                # xmm0 = mem[0],zero,zero,zero
	movss	184(%rsp), %xmm2                # xmm2 = mem[0],zero,zero,zero
	xorps	%xmm1, %xmm1
	movq	%rbx, %rdi
	callq	_ZN4Vec3C1Efff
	movq	%rbx, %rdi
	callq	_ZN4Vec39normalizeEv
	movaps	%xmm1, %xmm2
	movaps	%xmm0, %xmm1
	shufps	$85, %xmm0, %xmm1               # xmm1 = xmm1[1,1],xmm0[1,1]
	movq	%r14, %rdi
	callq	_ZN4Vec3C1Efff
	movsd	368(%rsp), %xmm0                # xmm0 = mem[0],zero
	movss	376(%rsp), %xmm1                # xmm1 = mem[0],zero,zero,zero
	movss	160(%rsp), %xmm2                # xmm2 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm2
	movss	%xmm2, 160(%rsp)
	shufps	$85, %xmm0, %xmm0               # xmm0 = xmm0[1,1,1,1]
	addss	164(%rsp), %xmm0
	movss	%xmm0, 164(%rsp)
	addss	168(%rsp), %xmm1
	movss	%xmm1, 168(%rsp)
.LBB0_19:                               #   in Loop: Header=BB0_17 Depth=1
	movl	$1, %edi
	callq	_Z11key_pressed3KEY
	testb	%al, %al
	je	.LBB0_21
# %bb.20:                               #   in Loop: Header=BB0_17 Depth=1
	movss	184(%rsp), %xmm0                # xmm0 = mem[0],zero,zero,zero
	xorps	.LCPI0_9(%rip), %xmm0
	movss	176(%rsp), %xmm2                # xmm2 = mem[0],zero,zero,zero
	xorps	%xmm1, %xmm1
	movq	%rbx, %rdi
	callq	_ZN4Vec3C1Efff
	movq	%rbx, %rdi
	callq	_ZN4Vec39normalizeEv
	movaps	%xmm1, %xmm2
	movaps	%xmm0, %xmm1
	shufps	$85, %xmm0, %xmm1               # xmm1 = xmm1[1,1],xmm0[1,1]
	movq	%r14, %rdi
	callq	_ZN4Vec3C1Efff
	movsd	368(%rsp), %xmm0                # xmm0 = mem[0],zero
	movss	376(%rsp), %xmm1                # xmm1 = mem[0],zero,zero,zero
	movss	160(%rsp), %xmm2                # xmm2 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm2
	movss	%xmm2, 160(%rsp)
	shufps	$85, %xmm0, %xmm0               # xmm0 = xmm0[1,1,1,1]
	addss	164(%rsp), %xmm0
	movss	%xmm0, 164(%rsp)
	addss	168(%rsp), %xmm1
	movss	%xmm1, 168(%rsp)
.LBB0_21:                               #   in Loop: Header=BB0_17 Depth=1
	movl	$2, %edi
	callq	_Z11key_pressed3KEY
	testb	%al, %al
	je	.LBB0_23
# %bb.22:                               #   in Loop: Header=BB0_17 Depth=1
	movss	176(%rsp), %xmm0                # xmm0 = mem[0],zero,zero,zero
	movss	184(%rsp), %xmm2                # xmm2 = mem[0],zero,zero,zero
	xorps	%xmm1, %xmm1
	movq	%rbx, %rdi
	callq	_ZN4Vec3C1Efff
	movq	%rbx, %rdi
	callq	_ZN4Vec39normalizeEv
	movaps	%xmm1, %xmm2
	movaps	%xmm0, %xmm1
	shufps	$85, %xmm0, %xmm1               # xmm1 = xmm1[1,1],xmm0[1,1]
	movq	%r14, %rdi
	callq	_ZN4Vec3C1Efff
	movsd	368(%rsp), %xmm0                # xmm0 = mem[0],zero
	movss	168(%rsp), %xmm1                # xmm1 = mem[0],zero,zero,zero
	subss	376(%rsp), %xmm1
	movss	160(%rsp), %xmm2                # xmm2 = mem[0],zero,zero,zero
	movss	164(%rsp), %xmm3                # xmm3 = mem[0],zero,zero,zero
	subss	%xmm0, %xmm2
	movss	%xmm2, 160(%rsp)
	shufps	$85, %xmm0, %xmm0               # xmm0 = xmm0[1,1,1,1]
	subss	%xmm0, %xmm3
	movss	%xmm3, 164(%rsp)
	movss	%xmm1, 168(%rsp)
.LBB0_23:                               #   in Loop: Header=BB0_17 Depth=1
	movl	$3, %edi
	callq	_Z11key_pressed3KEY
	testb	%al, %al
	je	.LBB0_25
# %bb.24:                               #   in Loop: Header=BB0_17 Depth=1
	movss	184(%rsp), %xmm0                # xmm0 = mem[0],zero,zero,zero
	movss	176(%rsp), %xmm2                # xmm2 = mem[0],zero,zero,zero
	xorps	.LCPI0_9(%rip), %xmm2
	xorps	%xmm1, %xmm1
	movq	%rbx, %rdi
	callq	_ZN4Vec3C1Efff
	movq	%rbx, %rdi
	callq	_ZN4Vec39normalizeEv
	movaps	%xmm1, %xmm2
	movaps	%xmm0, %xmm1
	shufps	$85, %xmm0, %xmm1               # xmm1 = xmm1[1,1],xmm0[1,1]
	movq	%r14, %rdi
	callq	_ZN4Vec3C1Efff
	movsd	368(%rsp), %xmm0                # xmm0 = mem[0],zero
	movss	376(%rsp), %xmm1                # xmm1 = mem[0],zero,zero,zero
	movss	160(%rsp), %xmm2                # xmm2 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm2
	movss	%xmm2, 160(%rsp)
	shufps	$85, %xmm0, %xmm0               # xmm0 = xmm0[1,1,1,1]
	addss	164(%rsp), %xmm0
	movss	%xmm0, 164(%rsp)
	addss	168(%rsp), %xmm1
	movss	%xmm1, 168(%rsp)
.LBB0_25:                               #   in Loop: Header=BB0_17 Depth=1
	movl	$4, %edi
	callq	_Z11key_pressed3KEY
	movss	156(%rsp), %xmm1                # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	addsd	.LCPI0_10(%rip), %xmm0
	testb	%al, %al
	je	.LBB0_27
# %bb.26:                               #   in Loop: Header=BB0_17 Depth=1
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 156(%rsp)                # 4-byte Spill
.LBB0_27:                               #   in Loop: Header=BB0_17 Depth=1
	movl	$5, %edi
	callq	_Z11key_pressed3KEY
	movss	156(%rsp), %xmm0                # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	cvtss2sd	%xmm0, %xmm0
	addsd	.LCPI0_11(%rip), %xmm0
	testb	%al, %al
	je	.LBB0_29
# %bb.28:                               #   in Loop: Header=BB0_17 Depth=1
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 156(%rsp)                # 4-byte Spill
.LBB0_29:                               #   in Loop: Header=BB0_17 Depth=1
	movsd	160(%rsp), %xmm0                # xmm0 = mem[0],zero
	movaps	%xmm0, 240(%rsp)                # 16-byte Spill
	movss	168(%rsp), %xmm0                # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, 200(%rsp)                # 4-byte Spill
	movss	176(%rsp), %xmm0                # xmm0 = mem[0],zero,zero,zero
	movss	180(%rsp), %xmm1                # xmm1 = mem[0],zero,zero,zero
	movss	184(%rsp), %xmm2                # xmm2 = mem[0],zero,zero,zero
	movq	%r14, %rdi
	callq	_ZN4Vec3C1Efff
	movsd	368(%rsp), %xmm2                # xmm2 = mem[0],zero
	movss	376(%rsp), %xmm3                # xmm3 = mem[0],zero,zero,zero
	movq	%r14, %rdi
	movaps	240(%rsp), %xmm0                # 16-byte Reload
	movss	200(%rsp), %xmm1                # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movss	.LCPI0_12(%rip), %xmm4          # xmm4 = mem[0],zero,zero,zero
	callq	_ZN8FrustrumC1E4Vec3S0_f
	movl	$18, %ecx
	movq	%rsp, %rdi
	movq	%r14, %rsi
	rep;movsq (%rsi), %es:(%rdi)
	leaq	552(%rsp), %rdi
	callq	_ZN12TraceManager12render_frameE8Frustrum
	movq	%rax, %rdi
	callq	_Z12render_framePv
	jmp	.LBB0_17
.LBB0_14:
.Ltmp2:
	movq	%rax, %r14
	movq	%r12, %rdi
	callq	_ZdaPv
	movq	%r14, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table0:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp1-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Lfunc_end0-.Ltmp1             #   Call between .Ltmp1 and .Lfunc_end0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"(%f, %f)\n"
	.size	.L.str, 10

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym _Unwind_Resume
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
