// File: /workspace/github_c_makefile_star2_O0/k0n10pl4tr[P]minimal_crafter/world.c
// Function: generateChunk
void
generateChunk(WorldChunk *chunk, unsigned int xc, unsigned int yc, unsigned int zc, unsigned int seed)
{
	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));

		float height = stb_perlin_noise3_seed((float)(xb + xc * WORLD_CHUNK_SIZE) / WORLD_CHUNK_SIZE, 
				0, 
				(float)(zb + zc * WORLD_CHUNK_SIZE) / WORLD_CHUNK_SIZE,
				0, 0, 0, seed) * 4.0 + 16;

		int heightInt = floor(height * height) / 16;

		if(yb + yc * WORLD_CHUNK_SIZE == heightInt) 
			chunk->blocks[xb][yb][zb] = 1;
		else if(yb + yc * WORLD_CHUNK_SIZE > heightInt - 4 && yb + yc * WORLD_CHUNK_SIZE < heightInt)
			chunk->blocks[xb][yb][zb] = 2;
		else if(yb + yc * WORLD_CHUNK_SIZE <= heightInt - 4)
			chunk->blocks[xb][yb][zb] = 3;
		else
			chunk->blocks[xb][yb][zb] = 0;

		if (yb + yc * WORLD_CHUNK_SIZE <= heightInt) {
			chunk->numBlocks++;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x1000, -0x1c(%rbp)    # imm = 0x1000
jge 0x8ae0
movl -0x1c(%rbp), %eax
movl %eax, %edx
addl $0xf, %edx
testl %eax, %eax
movl %eax, %ecx
cmovsl %edx, %ecx
andl $-0x10, %ecx
subl %ecx, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, %ecx
addl $0xf, %ecx
testl %eax, %eax
cmovsl %ecx, %eax
sarl $0x4, %eax
movl %eax, %edx
addl $0xf, %edx
testl %eax, %eax
movl %eax, %ecx
cmovsl %edx, %ecx
andl $-0x10, %ecx
subl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, %ecx
addl $0xff, %ecx
testl %eax, %eax
cmovsl %ecx, %eax
sarl $0x8, %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
movl -0xc(%rbp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
cvtsi2ss %rax, %xmm0
movss 0x272e(%rip), %xmm1     # 0xb064
mulss %xmm1, %xmm0
movl -0x28(%rbp), %eax
movl -0x14(%rbp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
cvtsi2ss %rax, %xmm2
movss 0x270e(%rip), %xmm1     # 0xb060
divss %xmm1, %xmm2
movl -0x18(%rbp), %ecx
xorps %xmm1, %xmm1
xorl %edx, %edx
movl %edx, %edi
movl %edx, %esi
callq 0x7de0
cvtss2sd %xmm0, %xmm0
movsd 0x2715(%rip), %xmm1     # 0xb088
mulsd %xmm1, %xmm0
movsd 0x2701(%rip), %xmm1     # 0xb080
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
movss -0x2c(%rbp), %xmm0
mulss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x2280
movsd 0x26d9(%rip), %xmm1     # 0xb080
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
movl -0x10(%rbp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
cmpl -0x30(%rbp), %eax
jne 0x89f0
movq -0x8(%rbp), %rax
addq $0xc, %rax
movslq -0x20(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x24(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0x8aad
movl -0x24(%rbp), %eax
movl -0x10(%rbp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
movl -0x30(%rbp), %ecx
subl $0x4, %ecx
cmpl %ecx, %eax
jbe 0x8a40
movl -0x24(%rbp), %eax
movl -0x10(%rbp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
cmpl -0x30(%rbp), %eax
jae 0x8a40
movq -0x8(%rbp), %rax
addq $0xc, %rax
movslq -0x20(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x24(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl $0x2, (%rax,%rcx,4)
jmp 0x8aab
movl -0x24(%rbp), %eax
movl -0x10(%rbp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
movl -0x30(%rbp), %ecx
subl $0x4, %ecx
cmpl %ecx, %eax
ja 0x8a80
movq -0x8(%rbp), %rax
addq $0xc, %rax
movslq -0x20(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x24(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl $0x3, (%rax,%rcx,4)
jmp 0x8aa9
movq -0x8(%rbp), %rax
addq $0xc, %rax
movslq -0x20(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x24(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
jmp 0x8aab
jmp 0x8aad
movl -0x24(%rbp), %eax
movl -0x10(%rbp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
cmpl -0x30(%rbp), %eax
ja 0x8ad0
movq -0x8(%rbp), %rax
movl 0x400c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x400c(%rax)
jmp 0x8ad2
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x88c0
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)