// File: /workspace/github_c_makefile_star2_O0/k0n10pl4tr[P]minimal_crafter/rendering.c
// Function: generateChunkModel
void
generateChunkModel(unsigned int x, unsigned int y, unsigned int z)
{
	wChunk = getWorldChunk(x, y, z);
	if(wChunk->numBlocks == 0) {
		return;
	}
	unsigned int chunkId = chunkCachedStackSize % NUM_CHUNK_CACHED;
	for(unsigned int i = 0; i < NUM_CHUNK_CACHED; i++) {
		if(chunkCached[i].canDraw && 
				chunkCached[i].xOffset == x &&
				chunkCached[i].yOffset == y &&
				chunkCached[i].zOffset == z) {
			return;
		}
	}
	
	chunkCached[chunkId].faces = 0;
	chunkCached[chunkId].xOffset = x;
	chunkCached[chunkId].yOffset = y;
	chunkCached[chunkId].zOffset = z;
	
	glBindBuffer(GL_ARRAY_BUFFER, chunkCached[chunkId].vbo);
	float* bufferData = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
	float* vertexData = &bufferData[0];
	float* texcoordData = &bufferData[WORLD_CHUNK_NBLOCKS * 18 * 6];
	
	for(int i = 0; i < WORLD_CHUNK_NBLOCKS; i++) { 
		int xb = (i  % WORLD_CHUNK_SIZE);
		int yb = (i  / WORLD_CHUNK_SIZE) % WORLD_CHUNK_SIZE;
		int zb = (i / (WORLD_CHUNK_SIZE * WORLD_CHUNK_SIZE));

		int xp = xb + (int)x * WORLD_CHUNK_SIZE;
		int yp = yb + (int)y * WORLD_CHUNK_SIZE;
		int zp = zb + (int)z * WORLD_CHUNK_SIZE;
		
		#define GET_BLOCK(X, Y, Z) wChunk->blocks[X][Y][Z]
		currentBlock = GET_BLOCK(xb, yb, zb);
		if(currentBlock == 0)
			continue;
		if(xb == 0 || GET_BLOCK(xb - 1, yb, zb) == 0) {
			generateFace(BLOCK_LEFT, currentBlock, vertexData, texcoordData, xp, yp, zp);
			
			vertexData += 18;
			texcoordData += 12;
			chunkCached[chunkId].faces++;
		}

		if(yb == 0 || GET_BLOCK(xb, yb - 1, zb) == 0) {
			generateFace(BLOCK_BOTTOM, currentBlock, vertexData, texcoordData, xp, yp, zp);

			vertexData += 18;
			texcoordData += 12;
			chunkCached[chunkId].faces++;
		}
		if(xb == WORLD_CHUNK_SIZE - 1 || GET_BLOCK(xb + 1, yb, zb) == 0) {
			generateFace(BLOCK_RIGHT, currentBlock, vertexData, texcoordData, xp, yp, zp);

			vertexData += 18;
			texcoordData += 12;
			chunkCached[chunkId].faces++;
		}

		if(yb == WORLD_CHUNK_SIZE - 1 || GET_BLOCK(xb, yb + 1, zb) == 0) {
			generateFace(BLOCK_TOP, currentBlock, vertexData, texcoordData, xp, yp, zp);

			vertexData += 18;
			texcoordData += 12;
			chunkCached[chunkId].faces++;
		}

		if(zb == WORLD_CHUNK_SIZE - 1 || !GET_BLOCK(xb, yb, zb + 1)) {
			generateFace(BLOCK_FRONT, currentBlock, vertexData, texcoordData, xp, yp, zp);

			vertexData += 18;
			texcoordData += 12;
			chunkCached[chunkId].faces++;
		}

		if(zb == 0 || !GET_BLOCK(xb, yb, zb - 1)) {
			generateFace(BLOCK_BACK, currentBlock, vertexData, texcoordData, xp, yp, zp);

			vertexData += 18;
			texcoordData += 12;
			chunkCached[chunkId].faces++;
		}
	}
	glUnmapBuffer(GL_ARRAY_BUFFER);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	chunkCached[chunkId].canDraw = 1;
	chunkCachedStackSize ++;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
movl -0xc(%rbp), %edx
callq 0x8af0
movq %rax, 0xa4ca(%rip)      # 0x10440
movq 0xa4c3(%rip), %rax      # 0x10440
cmpl $0x0, 0x400c(%rax)
jne 0x5f8b
jmp 0x6545
movl 0xa4b7(%rip), %eax      # 0x10448
andl $0xff, %eax
movl %eax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x100, -0x14(%rbp)     # imm = 0x100
jae 0x602f
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq 0x8887(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movzbl 0x18(%rax), %eax
cmpl $0x0, %eax
je 0x601f
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq 0x886b(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
cmpl -0x4(%rbp), %eax
jne 0x601f
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq 0x8850(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
cmpl -0x8(%rbp), %eax
jne 0x601f
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq 0x8835(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x601f
jmp 0x6545
jmp 0x6021
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5fa0
movl -0x10(%rbp), %eax
movl %eax, %ecx
leaq 0x8805(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x8(%rax)
movl -0x4(%rbp), %ecx
movl -0x10(%rbp), %eax
movl %eax, %edx
leaq 0x87e8(%rip), %rax      # 0xe840
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl -0x8(%rbp), %ecx
movl -0x10(%rbp), %eax
movl %eax, %edx
leaq 0x87cf(%rip), %rax      # 0xe840
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movl -0xc(%rbp), %ecx
movl -0x10(%rbp), %eax
movl %eax, %edx
leaq 0x87b6(%rip), %rax      # 0xe840
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
leaq 0x7afd(%rip), %rax      # 0xdb98
movq (%rax), %rax
movl -0x10(%rbp), %ecx
movl %ecx, %edx
leaq 0x8796(%rip), %rcx      # 0xe840
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movl $0x8892, %edi           # imm = 0x8892
movl $0x88b9, %esi           # imm = 0x88B9
leaq 0x8084(%rip), %rax      # 0xe150
callq *(%rax)
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
addq $0x1b0000, %rax         # imm = 0x1B0000
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x1000, -0x34(%rbp)    # imm = 0x1000
jge 0x6501
movl -0x34(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x38(%rbp)
movl -0x34(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x3c(%rbp)
movl -0x34(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %eax, -0x40(%rbp)
movl -0x38(%rbp), %eax
movl -0x4(%rbp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %eax
movl -0x8(%rbp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
movl %eax, -0x48(%rbp)
movl -0x40(%rbp), %eax
movl -0xc(%rbp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
movl %eax, -0x4c(%rbp)
movq 0xa2e1(%rip), %rax      # 0x10440
addq $0xc, %rax
movslq -0x38(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x3c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0xa2c6(%rip)      # 0x1044c
cmpl $0x0, 0xa2bf(%rip)      # 0x1044c
jne 0x6194
jmp 0x64f3
cmpl $0x0, -0x38(%rbp)
je 0x61ca
movq 0xa29f(%rip), %rax      # 0x10440
addq $0xc, %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x3c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x6224
movl 0xa27c(%rip), %esi      # 0x1044c
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl -0x44(%rbp), %r8d
movl -0x48(%rbp), %r9d
movl -0x4c(%rbp), %eax
movl $0x2, %edi
movl %eax, (%rsp)
callq 0x6550
movq -0x28(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x30(%rbp)
movl -0x10(%rbp), %eax
movl %eax, %ecx
leaq 0x862c(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
cmpl $0x0, -0x3c(%rbp)
je 0x625a
movq 0xa20f(%rip), %rax      # 0x10440
addq $0xc, %rax
movslq -0x38(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x62b4
movl 0xa1ec(%rip), %esi      # 0x1044c
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl -0x44(%rbp), %r8d
movl -0x48(%rbp), %r9d
movl -0x4c(%rbp), %eax
movl $0x1, %edi
movl %eax, (%rsp)
callq 0x6550
movq -0x28(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x30(%rbp)
movl -0x10(%rbp), %eax
movl %eax, %ecx
leaq 0x859c(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
cmpl $0xf, -0x38(%rbp)
je 0x62ea
movq 0xa17f(%rip), %rax      # 0x10440
addq $0xc, %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x3c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x6344
movl 0xa15c(%rip), %esi      # 0x1044c
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl -0x44(%rbp), %r8d
movl -0x48(%rbp), %r9d
movl -0x4c(%rbp), %eax
movl $0x3, %edi
movl %eax, (%rsp)
callq 0x6550
movq -0x28(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x30(%rbp)
movl -0x10(%rbp), %eax
movl %eax, %ecx
leaq 0x850c(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
cmpl $0xf, -0x3c(%rbp)
je 0x637a
movq 0xa0ef(%rip), %rax      # 0x10440
addq $0xc, %rax
movslq -0x38(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movl -0x3c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x63d1
movl 0xa0cc(%rip), %esi      # 0x1044c
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl -0x44(%rbp), %r8d
movl -0x48(%rbp), %r9d
movl -0x4c(%rbp), %eax
xorl %edi, %edi
movl %eax, (%rsp)
callq 0x6550
movq -0x28(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x30(%rbp)
movl -0x10(%rbp), %eax
movl %eax, %ecx
leaq 0x847f(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
cmpl $0xf, -0x40(%rbp)
je 0x6407
movq 0xa062(%rip), %rax      # 0x10440
addq $0xc, %rax
movslq -0x38(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x3c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x6461
movl 0xa03f(%rip), %esi      # 0x1044c
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl -0x44(%rbp), %r8d
movl -0x48(%rbp), %r9d
movl -0x4c(%rbp), %eax
movl $0x4, %edi
movl %eax, (%rsp)
callq 0x6550
movq -0x28(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x30(%rbp)
movl -0x10(%rbp), %eax
movl %eax, %ecx
leaq 0x83ef(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
cmpl $0x0, -0x40(%rbp)
je 0x6497
movq 0x9fd2(%rip), %rax      # 0x10440
addq $0xc, %rax
movslq -0x38(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x3c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x64f1
movl 0x9faf(%rip), %esi      # 0x1044c
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl -0x44(%rbp), %r8d
movl -0x48(%rbp), %r9d
movl -0x4c(%rbp), %eax
movl $0x5, %edi
movl %eax, (%rsp)
callq 0x6550
movq -0x28(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x30(%rbp)
movl -0x10(%rbp), %eax
movl %eax, %ecx
leaq 0x835f(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x64f3
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x60ef
movl $0x8892, %edi           # imm = 0x8892
leaq 0x7f9b(%rip), %rax      # 0xe4a8
callq *(%rax)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
leaq 0x767b(%rip), %rax      # 0xdb98
callq *(%rax)
movl -0x10(%rbp), %eax
movl %eax, %ecx
leaq 0x8315(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movb $0x1, 0x18(%rax)
movl 0x9f0c(%rip), %eax      # 0x10448
addl $0x1, %eax
movl %eax, 0x9f03(%rip)      # 0x10448
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)