// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edi, %r15d
movl %esi, %r14d
movl %edx, %ebx
callq 0x6b07
movq %rax, 0x8cce(%rip)      # 0xdf70
cmpl $0x0, 0x400c(%rax)
je 0x5624
movzbl 0x8cc2(%rip), %ecx      # 0xdf78
movl $0x18, %edx
leaq 0x70ae(%rip), %rax      # 0xc370
cmpb $0x0, (%rdx,%rax)
je 0x52e0
cmpl %r15d, -0xc(%rdx,%rax)
jne 0x52e0
cmpl %r14d, -0x8(%rdx,%rax)
jne 0x52e0
cmpl %ebx, -0x4(%rdx,%rax)
je 0x5624
addq $0x1c, %rdx
cmpq $0x1c18, %rdx           # imm = 0x1C18
jne 0x52c2
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
leaq (%rax,%rdx), %rcx
movq %rcx, -0x40(%rbp)
movl $0x0, 0x8(%rax,%rdx)
movl %r15d, 0xc(%rax,%rdx)
movl %r14d, 0x10(%rax,%rdx)
movl %ebx, 0x14(%rax,%rdx)
leaq 0x63ab(%rip), %rcx      # 0xb6c8
movl 0x4(%rax,%rdx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *(%rcx)
leaq 0x6951(%rip), %rax      # 0xbc80
movl $0x8892, %edi           # imm = 0x8892
movl $0x88b9, %esi           # imm = 0x88B9
callq *(%rax)
movq %rax, %rdx
movq %rax, %r12
addq $0x1b0000, %r12         # imm = 0x1B0000
shll $0x4, %r15d
movl %r15d, -0x4c(%rbp)
shll $0x4, %r14d
movl %r14d, -0x50(%rbp)
shll $0x4, %ebx
movl %ebx, -0x54(%rbp)
xorl %r15d, %r15d
movl %r15d, %ebx
andl $0xf, %ebx
movl %r15d, %r14d
shrl $0x4, %r14d
andl $0xf, %r14d
movl %r15d, %r8d
shrl $0x8, %r8d
movq 0x8bf0(%rip), %rax      # 0xdf70
movl %ebx, %ecx
shll $0xa, %ecx
addq %rax, %rcx
addq $0xc, %rcx
movl %r14d, %esi
shll $0x6, %esi
addq %rcx, %rsi
movl (%rsi,%r8,4), %esi
movl %esi, 0x8bdd(%rip)      # 0xdf7c
testl %esi, %esi
je 0x55e8
movl %ebx, %ecx
orl -0x4c(%rbp), %ecx
movl %ecx, -0x34(%rbp)
movl %r14d, %ecx
orl -0x50(%rbp), %ecx
movl %ecx, -0x30(%rbp)
movl %r8d, %ecx
addl -0x54(%rbp), %ecx
movl %ecx, -0x2c(%rbp)
testq %rbx, %rbx
movq %r8, -0x48(%rbp)
je 0x53ea
addq $0xc, %rax
movl %ebx, %ecx
shll $0xa, %ecx
movl %r14d, %edi
shll $0x6, %edi
addq %rcx, %rdi
addq %rax, %rdi
cmpl $0x0, -0x400(%rdi,%r8,4)
jne 0x541e
movl -0x2c(%rbp), %eax
movl %eax, (%rsp)
movl $0x2, %edi
movq %r12, %rcx
movq %rdx, %r13
movl -0x34(%rbp), %r8d
movl -0x30(%rbp), %r9d
callq 0x5633
movq -0x48(%rbp), %r8
movq %r13, %rdx
addq $0x48, %rdx
addq $0x30, %r12
movq -0x40(%rbp), %rax
incl 0x8(%rax)
testq %r14, %r14
je 0x5440
movl %ebx, %eax
shll $0xa, %eax
addq 0x8b41(%rip), %rax      # 0xdf70
movl %r14d, %ecx
shll $0x6, %ecx
addq %rax, %rcx
cmpl $0x0, -0x34(%rcx,%r8,4)
jne 0x547a
movl 0x8b36(%rip), %esi      # 0xdf7c
movl -0x2c(%rbp), %eax
movl %eax, (%rsp)
movl $0x1, %edi
movq %r12, %rcx
movq %rdx, %r13
movl -0x34(%rbp), %r8d
movl -0x30(%rbp), %r9d
callq 0x5633
movq -0x48(%rbp), %r8
movq %r13, %rdx
addq $0x48, %rdx
addq $0x30, %r12
movq -0x40(%rbp), %rax
incl 0x8(%rax)
cmpl $0xf, %ebx
je 0x549f
movl %ebx, %eax
shll $0xa, %eax
movl %r14d, %ecx
addq 0x8ae2(%rip), %rax      # 0xdf70
shll $0x6, %ecx
addq %rcx, %rax
cmpl $0x0, 0x40c(%rax,%r8,4)
jne 0x54d9
movl 0x8ad7(%rip), %esi      # 0xdf7c
movl -0x2c(%rbp), %eax
movl %eax, (%rsp)
movl $0x3, %edi
movq %r12, %rcx
movq %rdx, %r13
movl -0x34(%rbp), %r8d
movl -0x30(%rbp), %r9d
callq 0x5633
movq -0x48(%rbp), %r8
movq %r13, %rdx
addq $0x48, %rdx
addq $0x30, %r12
movq -0x40(%rbp), %rax
incl 0x8(%rax)
cmpl $0xf, %r14d
je 0x54fc
movl %ebx, %eax
shll $0xa, %eax
addq 0x8a85(%rip), %rax      # 0xdf70
movl %r14d, %ecx
shll $0x6, %ecx
addq %rax, %rcx
cmpl $0x0, 0x4c(%rcx,%r8,4)
jne 0x5533
movl 0x8a7a(%rip), %esi      # 0xdf7c
movl -0x2c(%rbp), %eax
movl %eax, (%rsp)
xorl %edi, %edi
movq %r12, %rcx
movq %rdx, %r13
movl -0x34(%rbp), %r8d
movl -0x30(%rbp), %r9d
callq 0x5633
movq -0x48(%rbp), %r8
movq %r13, %rdx
addq $0x48, %rdx
addq $0x30, %r12
movq -0x40(%rbp), %rax
incl 0x8(%rax)
cmpl $0xf, %r8d
je 0x5556
movl %ebx, %eax
shll $0xa, %eax
addq 0x8a2b(%rip), %rax      # 0xdf70
movl %r14d, %ecx
shll $0x6, %ecx
addq %rax, %rcx
cmpl $0x0, 0x10(%rcx,%r8,4)
jne 0x5590
movl 0x8a20(%rip), %esi      # 0xdf7c
movl -0x2c(%rbp), %eax
movl %eax, (%rsp)
movl $0x4, %edi
movq %r12, %rcx
movq %rdx, %r13
movl -0x34(%rbp), %r8d
movl -0x30(%rbp), %r9d
callq 0x5633
movq -0x48(%rbp), %r8
movq %r13, %rdx
addq $0x48, %rdx
addq $0x30, %r12
movq -0x40(%rbp), %rax
incl 0x8(%rax)
cmpl $0x100, %r15d           # imm = 0x100
jb 0x55b2
shll $0xa, %ebx
addq 0x89cd(%rip), %rbx      # 0xdf70
shll $0x6, %r14d
addq %rbx, %r14
cmpl $0x0, 0x8(%r14,%r8,4)
jne 0x55e8
movl 0x89c4(%rip), %esi      # 0xdf7c
movl -0x2c(%rbp), %eax
movl %eax, (%rsp)
movl $0x5, %edi
movq %r12, %rcx
movq %rdx, %rbx
movl -0x34(%rbp), %r8d
movl -0x30(%rbp), %r9d
callq 0x5633
movq %rbx, %rdx
addq $0x48, %rdx
addq $0x30, %r12
movq -0x40(%rbp), %rax
incl 0x8(%rax)
incl %r15d
cmpl $0x1000, %r15d          # imm = 0x1000
jne 0x5361
leaq 0x69d9(%rip), %rax      # 0xbfd8
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
leaq 0x60b4(%rip), %rax      # 0xb6c8
callq *(%rax)
movq -0x40(%rbp), %rax
movb $0x1, 0x18(%rax)
incl 0x8954(%rip)            # 0xdf78
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq