// File: /workspace/github_c_makefile_star2_O0/Hazematman[P]BSP-Renderer/game.c
// Function: run
void run(){
	bool running = true;
	SDL_Event e;

	GLint projViewLoc = getUniformLoc(&prg, "projView");
	GLint modelLoc = getUniformLoc(&prg, "model");
	GLint texLoc = getUniformLoc(&prg, "tex");
	
	while(running){
		while(SDL_PollEvent(&e)){
			if(e.type == SDL_QUIT){
				running = false;
			}else if(e.type == SDL_KEYDOWN){
				switch(e.key.keysym.sym){
					case SDLK_w:
						pos.z -= speed;
						break;
					case SDLK_s:
						pos.z += speed;
						break;
					case SDLK_a:
						pos.x -= speed;
						break;
					case SDLK_d:
						pos.x += speed;
						break;
					case SDLK_e:
						pos.y += speed;
						break;
					case SDLK_q:
						pos.y -= speed;
						break;
					case SDLK_LEFT:
						angle += 0.1;
						break;
					case SDLK_RIGHT:
						angle -= 0.1;
						break;
				}
			}
		}

		mat4 projView;
		mat4 model;
		identity(&projView);
		identity(&model);
		perspective(&projView, 45.0f * (PI/180.0f), WINDOW_WIDTH/WINDOW_HEIGHT, 0.1f, 10000.0f);
		rotateY(&projView, -angle);
		translate(&projView, -pos.x, -pos.y, -pos.z);
		//printf("%f %f %f %f\n",angle, pos.x, pos.y, pos.z);

		glUseProgram(prg.prgID);
		glUniformMatrix4fv(projViewLoc, 1, GL_FALSE, &projView.m[0]);
		glUniformMatrix4fv(modelLoc, 1, GL_FALSE, &model.m[0]);
		glUniform1i(texLoc, 0);

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		renderAllBspFaces(bsp);
		SDL_GL_SwapWindow(screen);
	}

	SDL_Quit();

	freeBsp(bsp);
	freePalette(plt);
	freePak(pf);
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movb $0x1, -0x1(%rbp)
leaq 0x5762(%rip), %rdi      # 0xcc68
leaq 0x24ab(%rip), %rsi      # 0x99b8
callq 0x4ca0
movl %eax, -0x44(%rbp)
leaq 0x574c(%rip), %rdi      # 0xcc68
leaq 0x249e(%rip), %rsi      # 0x99c1
callq 0x4ca0
movl %eax, -0x48(%rbp)
leaq 0x5736(%rip), %rdi      # 0xcc68
leaq 0x1f39(%rip), %rsi      # 0x9472
callq 0x4ca0
movl %eax, -0x4c(%rbp)
testb $0x1, -0x1(%rbp)
je 0x7847
jmp 0x754d
leaq -0x40(%rbp), %rdi
callq 0x1090
cmpl $0x0, %eax
je 0x770f
cmpl $0x100, -0x40(%rbp)     # imm = 0x100
jne 0x7571
movb $0x0, -0x1(%rbp)
jmp 0x770a
cmpl $0x300, -0x40(%rbp)     # imm = 0x300
jne 0x7708
movl -0x2c(%rbp), %eax
movl %eax, -0xd0(%rbp)
subl $0x61, %eax
je 0x7646
jmp 0x7592
movl -0xd0(%rbp), %eax
subl $0x64, %eax
je 0x7667
jmp 0x75a3
movl -0xd0(%rbp), %eax
subl $0x65, %eax
je 0x7684
jmp 0x75b4
movl -0xd0(%rbp), %eax
subl $0x71, %eax
je 0x769e
jmp 0x75c5
movl -0xd0(%rbp), %eax
subl $0x73, %eax
je 0x7629
jmp 0x75d2
movl -0xd0(%rbp), %eax
subl $0x77, %eax
je 0x7608
jmp 0x75df
movl -0xd0(%rbp), %eax
subl $0x4000004f, %eax       # imm = 0x4000004F
je 0x76e2
jmp 0x75f2
movl -0xd0(%rbp), %eax
subl $0x40000050, %eax       # imm = 0x40000050
je 0x76bc
jmp 0x7706
movss 0x4b70(%rip), %xmm1     # 0xc180
movss 0x5664(%rip), %xmm0     # 0xcc7c
subss %xmm1, %xmm0
movss %xmm0, 0x5658(%rip)     # 0xcc7c
jmp 0x7706
movss 0x4b4f(%rip), %xmm0     # 0xc180
addss 0x5643(%rip), %xmm0     # 0xcc7c
movss %xmm0, 0x563b(%rip)     # 0xcc7c
jmp 0x7706
movss 0x4b32(%rip), %xmm1     # 0xc180
movss 0x561e(%rip), %xmm0     # 0xcc74
subss %xmm1, %xmm0
movss %xmm0, 0x5612(%rip)     # 0xcc74
jmp 0x7706
movss 0x4b11(%rip), %xmm0     # 0xc180
addss 0x55fd(%rip), %xmm0     # 0xcc74
movss %xmm0, 0x55f5(%rip)     # 0xcc74
jmp 0x7706
movss 0x4af4(%rip), %xmm0     # 0xc180
addss 0x55e4(%rip), %xmm0     # 0xcc78
movss %xmm0, 0x55dc(%rip)     # 0xcc78
jmp 0x7706
movss 0x4ada(%rip), %xmm1     # 0xc180
movss 0x55ca(%rip), %xmm0     # 0xcc78
subss %xmm1, %xmm0
movss %xmm0, 0x55be(%rip)     # 0xcc78
jmp 0x7706
movss 0x55bc(%rip), %xmm0     # 0xcc80
cvtss2sd %xmm0, %xmm0
movsd 0x2290(%rip), %xmm1     # 0x9960
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x55a0(%rip)     # 0xcc80
jmp 0x7706
movss 0x5596(%rip), %xmm0     # 0xcc80
cvtss2sd %xmm0, %xmm0
movsd 0x226a(%rip), %xmm1     # 0x9960
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x557a(%rip)     # 0xcc80
jmp 0x7708
jmp 0x770a
jmp 0x754d
leaq -0x8c(%rbp), %rdi
callq 0x4d30
leaq -0xcc(%rbp), %rdi
callq 0x4d30
leaq -0x8c(%rbp), %rdi
movss 0x221a(%rip), %xmm0     # 0x9950
movss 0x213e(%rip), %xmm1     # 0x987c
movss 0x220e(%rip), %xmm2     # 0x9954
movss 0x220a(%rip), %xmm3     # 0x9958
callq 0x51b0
movss 0x5525(%rip), %xmm0     # 0xcc80
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
leaq -0x8c(%rbp), %rdi
callq 0x54a0
movss 0x54f8(%rip), %xmm0     # 0xcc74
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss 0x54e7(%rip), %xmm1     # 0xcc78
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
movss 0x54d6(%rip), %xmm2     # 0xcc7c
movd %xmm2, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm2
leaq -0x8c(%rbp), %rdi
callq 0x5380
leaq 0x4e9a(%rip), %rax      # 0xc660
movq (%rax), %rax
movl 0x5499(%rip), %edi      # 0xcc68
callq *%rax
leaq 0x4e80(%rip), %rax      # 0xc658
movq (%rax), %rax
movl -0x44(%rbp), %edi
leaq -0x8c(%rbp), %rcx
movl $0x1, %esi
xorl %edx, %edx
callq *%rax
leaq 0x4e63(%rip), %rax      # 0xc658
movq (%rax), %rax
movl -0x48(%rbp), %edi
leaq -0xcc(%rbp), %rcx
movl $0x1, %esi
xorl %edx, %edx
callq *%rax
leaq 0x4dc6(%rip), %rax      # 0xc5d8
movq (%rax), %rax
movl -0x4c(%rbp), %edi
xorl %esi, %esi
callq *%rax
movl $0x4100, %edi           # imm = 0x4100
leaq 0x4970(%rip), %rax      # 0xc198
callq *(%rax)
movq 0x5457(%rip), %rdi      # 0xcc88
callq 0x6ca0
movq 0x541b(%rip), %rdi      # 0xcc58
callq 0x1190
jmp 0x7541
callq 0x1060
movq 0x5435(%rip), %rdi      # 0xcc88
callq 0x6db0
movq 0x5431(%rip), %rdi      # 0xcc90
callq 0x5ba0
movq 0x542d(%rip), %rdi      # 0xcc98
callq 0x5a90
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)