// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
leaq 0x8390(%rip), %r14      # 0xa178
leaq 0x4319(%rip), %rsi      # 0x6108
movq %r14, %rdi
callq 0x4813
movl %eax, 0xc(%rsp)
leaq 0x430f(%rip), %rsi      # 0x6111
movq %r14, %rdi
callq 0x4813
movl %eax, 0x8(%rsp)
leaq 0x57b6(%rip), %rsi      # 0x75cb
movq %r14, %rdi
callq 0x4813
movl %eax, %r14d
movb $0x1, %bl
leaq 0x10(%rsp), %r15
leaq 0x88(%rsp), %r12
leaq 0x48(%rsp), %r13
leaq 0x883d(%rip), %rbp      # 0xa678
movq %r15, %rdi
callq 0x1090
testl %eax, %eax
je 0x1f1e
movl 0x10(%rsp), %eax
cmpl $0x100, %eax            # imm = 0x100
je 0x1e93
cmpl $0x300, %eax            # imm = 0x300
jne 0x1e3b
movl 0x24(%rsp), %eax
cmpl $0x72, %eax
jg 0x1e97
cmpl $0x64, %eax
jg 0x1ec9
cmpl $0x61, %eax
je 0x2013
cmpl $0x64, %eax
jne 0x1e3b
movss 0x8303(%rip), %xmm0     # 0xa184
addss 0x420b(%rip), %xmm0     # 0x6094
movss %xmm0, 0x82f3(%rip)     # 0xa184
jmp 0x1e3b
xorl %ebx, %ebx
jmp 0x1e3b
cmpl $0x4000004e, %eax       # imm = 0x4000004E
jg 0x1ef0
cmpl $0x73, %eax
je 0x2030
cmpl $0x77, %eax
jne 0x1e3b
movss 0x82d8(%rip), %xmm0     # 0xa18c
addss 0x41d4(%rip), %xmm0     # 0x6090
movss %xmm0, 0x82c8(%rip)     # 0xa18c
jmp 0x1e3b
cmpl $0x65, %eax
je 0x204d
cmpl $0x71, %eax
jne 0x1e3b
movss 0x82a5(%rip), %xmm0     # 0xa188
addss 0x41a5(%rip), %xmm0     # 0x6090
jmp 0x205d
cmpl $0x4000004f, %eax       # imm = 0x4000004F
je 0x206a
cmpl $0x40000050, %eax       # imm = 0x40000050
jne 0x1e3b
xorps %xmm0, %xmm0
cvtss2sd 0x827f(%rip), %xmm0     # 0xa190
addsd 0x4197(%rip), %xmm0     # 0x60b0
jmp 0x207d
movq %r12, %rdi
callq 0x4858
movq %r13, %rdi
callq 0x4858
movq %r12, %rdi
movss 0x415f(%rip), %xmm0     # 0x6098
movss 0x411b(%rip), %xmm1     # 0x605c
movss 0x4153(%rip), %xmm2     # 0x609c
movss 0x414f(%rip), %xmm3     # 0x60a0
callq 0x49f7
movss 0x8232(%rip), %xmm0     # 0xa190
movaps 0x40ab(%rip), %xmm1     # 0x6010
xorps %xmm1, %xmm0
movq %r12, %rdi
callq 0x4b09
movss 0x820c(%rip), %xmm0     # 0xa184
movaps 0x4091(%rip), %xmm2     # 0x6010
xorps %xmm2, %xmm0
movss 0x81fe(%rip), %xmm1     # 0xa188
xorps %xmm2, %xmm1
movaps %xmm2, %xmm3
movss 0x81f4(%rip), %xmm2     # 0xa18c
xorps %xmm3, %xmm2
movq %r12, %rdi
callq 0x4ab4
movl 0x81cf(%rip), %edi      # 0xa178
leaq 0x86d0(%rip), %rax      # 0xa680
callq *(%rax)
movl 0xc(%rsp), %edi
movl $0x1, %esi
xorl %edx, %edx
movq %r12, %rcx
callq *(%rbp)
movl 0x8(%rsp), %edi
movl $0x1, %esi
xorl %edx, %edx
movq %r13, %rcx
callq *(%rbp)
movl %r14d, %edi
xorl %esi, %esi
leaq 0x8618(%rip), %rax      # 0xa5f8
callq *(%rax)
movl $0x4100, %edi           # imm = 0x4100
leaq 0x81ca(%rip), %rax      # 0xa1b8
callq *(%rax)
movq 0x81a1(%rip), %rdi      # 0xa198
callq 0x1871
movq 0x8165(%rip), %rdi      # 0xa168
callq 0x1180
testb $0x1, %bl
jne 0x1e3b
jmp 0x208e
movss 0x8169(%rip), %xmm0     # 0xa184
addss 0x406d(%rip), %xmm0     # 0x6090
movss %xmm0, 0x8159(%rip)     # 0xa184
jmp 0x1e3b
movss 0x8154(%rip), %xmm0     # 0xa18c
addss 0x4054(%rip), %xmm0     # 0x6094
movss %xmm0, 0x8144(%rip)     # 0xa18c
jmp 0x1e3b
movss 0x8133(%rip), %xmm0     # 0xa188
addss 0x4037(%rip), %xmm0     # 0x6094
movss %xmm0, 0x8123(%rip)     # 0xa188
jmp 0x1e3b
xorps %xmm0, %xmm0
cvtss2sd 0x811b(%rip), %xmm0     # 0xa190
addsd 0x402b(%rip), %xmm0     # 0x60a8
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x8107(%rip)     # 0xa190
jmp 0x1e3b
callq 0x1060
movq 0x80fe(%rip), %rdi      # 0xa198
callq 0x1939
movq 0x80fa(%rip), %rdi      # 0xa1a0
callq 0x4eec
movq 0x80f6(%rip), %rdi      # 0xa1a8
callq 0x4e64
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)