// File: /workspace/github_c_makefile_star2_O2/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
movss %xmm0, 0x4(%rsp)
movq %rdi, 0x38(%rsp)
movslq %esi, %rax
leaq (,%rax,4), %rcx
movq %rcx, 0x58(%rsp)
leaq 0x4(,%rax,4), %rcx
movq %rcx, 0x80(%rsp)
movq %rax, 0x40(%rsp)
leal 0x1(,%rax,2), %eax
movl %eax, 0x54(%rsp)
movl %esi, 0x24(%rsp)
testl %edx, %edx
jle 0x9c38
movl %edx, %eax
shrl %eax
movl %edx, %r13d
movl %edx, %ecx
subl %eax, %ecx
imull %esi, %ecx
addl %edx, %ecx
movq %rax, 0x60(%rsp)
subl %eax, %ecx
movq %rdx, 0x18(%rsp)
imull %edx, %esi
movl %esi, 0x10(%rsp)
leaq (,%r13,4), %rax
movq %rax, 0x30(%rsp)
movq 0x58(%rsp), %rax
imulq %r13, %rax
movq %rax, 0x48(%rsp)
movq 0x80(%rsp), %rbp
imulq %r13, %rbp
movq 0x38(%rsp), %r15
movq %r13, %r14
movq %r15, 0x28(%rsp)
movl %ecx, 0xc(%rsp)
movl %ecx, %r12d
movq %r13, %rbx
cmpq 0x40(%rsp), %r14
jl 0x9a08
jmp 0x9a29
movss (%r15), %xmm0
movq 0x48(%rsp), %rax
addss (%r15,%rax), %xmm0
addss (%r15,%r13,4), %xmm0
addss (%r15,%rbp), %xmm0
mulss 0xa642(%rip), %xmm0     # 0x14014
movss %xmm0, 0x8(%rsp)
callq 0xed40
cvtsd2ss %xmm0, %xmm0
mulss 0x4(%rsp), %xmm0
addss 0x8(%rsp), %xmm0
movslq %r12d, %r12
movq 0x38(%rsp), %rax
movss %xmm0, (%rax,%r12,4)
addq %r13, %rbx
addl 0x18(%rsp), %r12d
addq 0x30(%rsp), %r15
cmpq 0x40(%rsp), %rbx
jl 0x99ae
addq %r13, %r14
movl 0xc(%rsp), %ecx
addl 0x10(%rsp), %ecx
movq 0x28(%rsp), %r15
addq 0x48(%rsp), %r15
jmp 0x9996
movq 0x18(%rsp), %r14
leal (%r14,%r14), %ecx
movq 0x60(%rsp), %rdi
leal (%rdi,%r14), %eax
movslq %ecx, %r8
movl %r8d, %ecx
subl %edi, %ecx
imull 0x24(%rsp), %ecx
addl %r14d, %ecx
subl %edi, %ecx
movq %rcx, 0x28(%rsp)
movl 0x10(%rsp), %ecx
movq %rcx, 0x88(%rsp)
imull 0x54(%rsp), %r14d
movq %r14, 0x18(%rsp)
movq %r8, %rcx
subq %r13, %rcx
movq 0x58(%rsp), %rsi
imulq %rsi, %rcx
leaq (%rcx,%r8,4), %r12
movq 0x38(%rsp), %rdx
leaq (%rdx,%r12), %rcx
movq %rcx, 0x10(%rsp)
movq %r12, %rcx
movq 0x30(%rsp), %r10
subq %r10, %rcx
addq %rdx, %rcx
movq %rcx, 0x78(%rsp)
movq %r8, %rcx
subq %rdi, %rcx
imulq %rsi, %rcx
leaq (%rcx,%r8,4), %r9
movq %r9, %rcx
subq %r10, %rcx
addq %rdx, %rcx
movq %rcx, 0x68(%rsp)
movq %r8, %rcx
subq %rax, %rcx
leaq (,%rdi,4), %rax
subq %rax, %r9
addq %rdx, %r9
movq %r9, 0x70(%rsp)
subq %rax, %r12
addq %rdx, %r12
imulq %rsi, %rcx
leaq (%rcx,%r8,4), %rbx
subq %rax, %rbx
addq %rdx, %rbx
movq %r8, %r15
cmpq 0x40(%rsp), %r8
jge 0x9c16
movq %r8, 0x90(%rsp)
xorl %ebp, %ebp
leaq (%r15,%rbp), %rax
cmpq 0x40(%rsp), %rax
jge 0x9bd5
movq 0x78(%rsp), %rax
movss (%rax,%rbp,4), %xmm1
movq 0x18(%rsp), %rax
addl %ebp, %eax
movq 0x70(%rsp), %rcx
movss (%rcx,%rbp,4), %xmm0
movss %xmm0, 0x30(%rsp)
movq 0x10(%rsp), %rcx
movss (%rcx,%rbp,4), %xmm2
addss %xmm1, %xmm2
addss %xmm0, %xmm2
addss (%rbx,%rbp,4), %xmm2
cltq
movss 0xa4c5(%rip), %xmm0     # 0x14014
mulss %xmm0, %xmm2
movss %xmm2, 0xc(%rsp)
movq 0x38(%rsp), %r14
addss (%r14,%rax,4), %xmm1
movss %xmm1, 0x8(%rsp)
callq 0xed40
cvtsd2ss %xmm0, %xmm0
mulss 0x4(%rsp), %xmm0
addss 0xc(%rsp), %xmm0
movss %xmm0, (%r12,%rbp,4)
movss 0x8(%rsp), %xmm0
addss 0x30(%rsp), %xmm0
movq 0x28(%rsp), %rax
addl %ebp, %eax
cltq
addss (%r14,%rax,4), %xmm0
mulss 0xa46c(%rip), %xmm0     # 0x14014
movss %xmm0, 0x8(%rsp)
callq 0xed40
cvtsd2ss %xmm0, %xmm0
mulss 0x4(%rsp), %xmm0
addss 0x8(%rsp), %xmm0
movq 0x68(%rsp), %rax
movss %xmm0, (%rax,%rbp,4)
addq %r13, %rbp
jmp 0x9afe
movq 0x90(%rsp), %r8
addq %r13, %r8
movq 0x88(%rsp), %rax
addq %rax, 0x28(%rsp)
addq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rax
addq %rax, 0x10(%rsp)
addq %rax, 0x78(%rsp)
addq %rax, 0x68(%rsp)
addq %rax, 0x70(%rsp)
addq %rax, %r12
addq %rax, %rbx
jmp 0x9ae9
movss 0x4(%rsp), %xmm0
mulss 0xa3ec(%rip), %xmm0     # 0x14010
movss %xmm0, 0x4(%rsp)
movq 0x60(%rsp), %rdx
movl 0x24(%rsp), %esi
jmp 0x993c
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq