// File: /workspace/github_c_makefile_star2_O1/Ziddykins[P]Dawn/src/map.c
// Function: diamond_square
void diamond_square(float *heightmap, int dim, float sigma, int level) {
    if (level < 1) return;

    // diamonds
    for (int i = level; i < dim; i += level) {
        for (int j = level; j < dim; j += level) {
            float a = heightmap[(i-level)*dim + j-level];
            float b = heightmap[i*dim + j-level];
            float c = heightmap[(i-level)*dim + j];
            float d = heightmap[i*dim+j];
            heightmap[(i-level/2)*dim + j-level/2] = (a + b + c + d) / 4 + (float)gaussrand() * sigma;
        }
    }
    // squares
    for (int i = 2 * level; i < dim; i += level) {
        for (int j = 2 * level; j < dim; j += level) {
            float a = heightmap[(i-level)*dim + j-level];
            float b = heightmap[i*dim + j-level];
            float c = heightmap[(i-level)*dim + j];
            float e = heightmap[(i-level/2)*dim + j-level/2];

            heightmap[(i-level)*dim + (j-level/2)] = (a + c + e + heightmap[(i-3*level/2)*dim + (j-level/2)]) / 4 + (float)gaussrand() * sigma;
            heightmap[(i-level/2)*dim + j-level] = (a + b + e + heightmap[(i-level/2)*dim + (j-3*level/2)]) / 4 + (float)gaussrand() * sigma;
        }
    }
    diamond_square(heightmap, dim, sigma / 2, level / 2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %esi, 0x8(%rsp)
movslq %esi, %rax
movq %rax, 0x50(%rsp)
leaq 0x4(,%rax,4), %rcx
movq %rcx, 0x60(%rsp)
leaq (,%rax,4), %rcx
movq %rcx, 0x40(%rsp)
leal 0x1(,%rax,2), %eax
movl %eax, 0x3c(%rsp)
movss 0xa821(%rip), %xmm1     # 0x15010
movq %rdi, 0x20(%rsp)
testl %edx, %edx
jle 0xab4e
movss %xmm0, 0xc(%rsp)
movl %edx, %r9d
movq %rdx, 0x10(%rsp)
cmpl 0x8(%rsp), %edx
movq %r9, 0x58(%rsp)
jge 0xa907
movq 0x10(%rsp), %rcx
movl %ecx, %eax
shrl %eax
movq 0x60(%rsp), %r13
imulq %r9, %r13
movq 0x20(%rsp), %rbx
addq %rbx, %r13
movq 0x40(%rsp), %rdx
imulq %r9, %rdx
movq %rdx, 0x28(%rsp)
leaq (%rbx,%rdx), %rbp
leaq (%rbx,%r9,4), %r15
movl %ecx, %r10d
subl %eax, %r10d
movl 0x8(%rsp), %edx
imull %edx, %r10d
addl %ecx, %r10d
subl %eax, %r10d
movl %edx, %eax
imull %ecx, %eax
movq %rax, 0x18(%rsp)
movq %r9, %r11
movq %r11, 0x30(%rsp)
xorl %r12d, %r12d
movss (%rbx,%r12,4), %xmm0
addss (%rbp,%r12,4), %xmm0
addss (%r15,%r12,4), %xmm0
addss (%r13,%r12,4), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, 0x4(%rsp)
movq %r10, %r14
callq 0xfd3c
movq %r14, %r10
movq 0x58(%rsp), %r9
movss 0xa762(%rip), %xmm1     # 0x15010
movq 0x50(%rsp), %rcx
cvtsd2ss %xmm0, %xmm0
mulss 0xc(%rsp), %xmm0
addss 0x4(%rsp), %xmm0
leal (%r14,%r12), %eax
cltq
movq 0x20(%rsp), %r11
movss %xmm0, (%r11,%rax,4)
addq %r9, %r12
leaq (%r9,%r12), %rax
cmpq %rcx, %rax
jl 0xa872
movq 0x30(%rsp), %r11
addq %r9, %r11
movq 0x28(%rsp), %rax
addq %rax, %r13
addq %rax, %rbp
addq %rax, %r15
addq %rax, %rbx
addq 0x18(%rsp), %r10
cmpq %rcx, %r11
jl 0xa86a
movq 0x10(%rsp), %rax
leal (%rax,%rax), %r11d
cmpl 0x8(%rsp), %r11d
jge 0xab34
movq 0x10(%rsp), %r10
movl %r10d, %eax
shrl %eax
leal (%rax,%r10), %ecx
movl %r11d, %ebx
movq %rbx, %rdx
subq %r9, %rdx
movq 0x40(%rsp), %r8
imulq %r8, %rdx
leaq (%rdx,%rbx,4), %r15
leaq (,%rax,4), %rdx
movq %r15, %r14
subq %rdx, %r14
movq 0x20(%rsp), %rdi
addq %rdi, %r14
movq %r8, %rsi
imulq %r9, %rsi
movq %rsi, 0x70(%rsp)
movq %rbx, %rsi
subq %rcx, %rsi
imulq %r8, %rsi
leaq (%rsi,%rbx,4), %rcx
movq %rbx, %rsi
movq %rcx, %rbx
subq %rdx, %rbx
addq %rdi, %rbx
movq %rsi, %rcx
subq %rax, %rcx
imulq %r8, %rcx
leaq (%rcx,%rsi,4), %r13
leaq (,%r9,4), %rcx
movq %r13, %r9
subq %rcx, %r9
addq %rdi, %r9
subq %rdx, %r13
addq %rdi, %r13
leaq (%rdi,%r15), %rbp
subq %rcx, %r15
addq %rdi, %r15
movl 0x3c(%rsp), %ecx
movl %ecx, %edi
imull %r10d, %edi
movl 0x8(%rsp), %ecx
movl %ecx, %edx
imull %r10d, %edx
movq %rdx, 0x68(%rsp)
subl %eax, %r11d
imull %ecx, %r11d
addl %r10d, %r11d
subl %eax, %r11d
movq %rsi, %rdx
movq %rsi, 0x80(%rsp)
movq %r11, 0x48(%rsp)
movq %r14, 0x18(%rsp)
movq %rdx, 0x78(%rsp)
xorl %r14d, %r14d
movq %rbx, 0x90(%rsp)
movq %r15, 0x88(%rsp)
movss (%r15,%r14,4), %xmm0
leal (%rdi,%r14), %eax
movss (%r13,%r14,4), %xmm2
movss %xmm2, 0x30(%rsp)
movss (%rbp,%r14,4), %xmm3
addss %xmm0, %xmm3
addss %xmm2, %xmm3
addss (%rbx,%r14,4), %xmm3
cltq
mulss %xmm1, %xmm3
movss %xmm3, 0x28(%rsp)
movq 0x20(%rsp), %r15
addss (%r15,%rax,4), %xmm0
movss %xmm0, 0x4(%rsp)
movq %r9, %r12
movq %rdi, %rbx
callq 0xfd3c
cvtsd2ss %xmm0, %xmm0
mulss 0xc(%rsp), %xmm0
addss 0x28(%rsp), %xmm0
movq 0x18(%rsp), %rax
movss %xmm0, (%rax,%r14,4)
movss 0x4(%rsp), %xmm0
addss 0x30(%rsp), %xmm0
movq 0x48(%rsp), %rax
addl %r14d, %eax
cltq
addss (%r15,%rax,4), %xmm0
mulss 0xa580(%rip), %xmm0     # 0x15010
movss %xmm0, 0x4(%rsp)
callq 0xfd3c
movq %rbx, %rdi
movq %r12, %r9
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %r15
movq 0x90(%rsp), %rbx
movq 0x58(%rsp), %rdx
movss 0xa54a(%rip), %xmm1     # 0x15010
movq 0x50(%rsp), %rcx
cvtsd2ss %xmm0, %xmm0
mulss 0xc(%rsp), %xmm0
addss 0x4(%rsp), %xmm0
movss %xmm0, (%r12,%r14,4)
addq %rdx, %r14
leaq (%rsi,%r14), %rax
cmpq %rcx, %rax
jl 0xa9fd
movq 0x78(%rsp), %rax
addq %rdx, %rax
movq %rax, %rdx
movq 0x70(%rsp), %rax
movq 0x18(%rsp), %r10
addq %rax, %r10
addq %rax, %rbx
addq %rax, %r9
addq %rax, %r13
addq %rax, %rbp
addq %rax, %r15
movq 0x68(%rsp), %rax
addq %rax, %rdi
movq 0x48(%rsp), %r11
addq %rax, %r11
cmpq %rcx, %rdx
movq %r10, %r14
jl 0xa9db
movss 0xc(%rsp), %xmm0
mulss 0xa4d2(%rip), %xmm0     # 0x15014
movq 0x10(%rsp), %rdx
shrl %edx
jmp 0xa7f4
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq