// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/map.c
// Function: generate_map
void generate_map() {
    int dim = global_map->dim;
    unsigned int seed;
    FILE *urandom;
    float *copy;


    CALLEXIT(!(urandom = fopen("/dev/urandom", "r")))
    CALLEXIT(!(fread(&seed, sizeof(seed), 1, urandom)))
    srand(seed);
    fclose(urandom);

    global_map->dim = 1 << 10;
    CALLEXIT(!(global_map->heightmap = calloc(sizeof *global_map->heightmap, (size_t) (global_map->dim * global_map->dim))))
    diamond_square(global_map->heightmap, global_map->dim, 4000.0, global_map->dim);
    global_map->flags |= MAP_PRESENT;
    CALLEXIT(!(copy = malloc((size_t)(dim*dim) * sizeof *copy)))

    for(int i = 0; i < dim*dim; i++) {
        copy[i] = global_map->heightmap[i];
    }

    qsort(copy, (size_t) (dim*dim), sizeof *copy, &compare_float_asc);
    global_map->water_level = copy[(int)(1.0/6.0*dim*dim)];
    free(copy);

    int town_count = (int) (10 + gaussrand() * 3);
    global_map->town_count = 0;
    CALLEXIT(!(global_map->towns = calloc((size_t) (town_count), sizeof *global_map->towns)))
    CALLEXIT(!(global_map->m_ent = calloc((size_t) (dim * dim), sizeof *global_map->m_ent)))
    perlin_init();

    for (int i = 0; i < town_count; i++) {
        place_town(i);
        global_map->town_count++;
    }

    assert(town_count == global_map->town_count);

    for (int i = 0; i < town_count; i++) {
        grow_town(i);
    }

    perlin_cleanup();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq 0x18e01(%rip), %rax     # 0x26290
movl 0x20(%rax), %eax
movl %eax, -0x4(%rbp)
leaq 0x10462(%rip), %rdi     # 0x1d8fe
leaq 0xff0c(%rip), %rsi      # 0x1d3af
callq 0x2230
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
jne 0xd4c8
leaq 0x11708(%rip), %rdi     # 0x1ebc1
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq -0x10(%rbp), %rcx
leaq -0x8(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x2320
cmpq $0x0, %rax
jne 0xd4fb
leaq 0x1171f(%rip), %rdi     # 0x1ec0b
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl -0x8(%rbp), %edi
callq 0x21d0
movq -0x10(%rbp), %rdi
callq 0x21f0
movq 0x18d7d(%rip), %rax     # 0x26290
movl $0x400, 0x20(%rax)      # imm = 0x400
movq 0x18d6f(%rip), %rax     # 0x26290
movl 0x20(%rax), %eax
movq 0x18d65(%rip), %rcx     # 0x26290
imull 0x20(%rcx), %eax
movslq %eax, %rsi
movl $0x4, %edi
callq 0x2110
movq 0x18d4d(%rip), %rcx     # 0x26290
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0xd562
leaq 0x11704(%rip), %rdi     # 0x1ec57
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq 0x18d27(%rip), %rax     # 0x26290
movq (%rax), %rdi
movq 0x18d1d(%rip), %rax     # 0x26290
movl 0x20(%rax), %esi
movq 0x18d13(%rip), %rax     # 0x26290
movl 0x20(%rax), %edx
movss 0x10ac0(%rip), %xmm0    # 0x1e048
callq 0xdba0
movq 0x18cfc(%rip), %rax     # 0x26290
movl 0x24(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x24(%rax)
movl -0x4(%rbp), %eax
imull -0x4(%rbp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x22b0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0xd5d0
leaq 0x11727(%rip), %rdi     # 0x1ece8
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x4(%rbp), %ecx
imull -0x4(%rbp), %ecx
cmpl %ecx, %eax
jge 0xd610
movq 0x18ca4(%rip), %rax     # 0x26290
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd5d7
movq -0x18(%rbp), %rdi
movl -0x4(%rbp), %eax
imull -0x4(%rbp), %eax
movslq %eax, %rsi
movl $0x4, %edx
leaq 0xaea6(%rip), %rcx      # 0x184d0
callq 0x2440
movq -0x18(%rbp), %rax
cvtsi2sdl -0x4(%rbp), %xmm1
movsd 0x10a40(%rip), %xmm0    # 0x1e080
mulsd %xmm1, %xmm0
cvtsi2sdl -0x4(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movq 0x18c30(%rip), %rax     # 0x26290
movss %xmm0, 0x1c(%rax)
movq -0x18(%rbp), %rdi
callq 0x2240
callq 0x181e0
movsd 0x109f5(%rip), %xmm1    # 0x1e070
mulsd %xmm1, %xmm0
movsd 0x109f1(%rip), %xmm1    # 0x1e078
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x20(%rbp)
movq 0x18bf7(%rip), %rax     # 0x26290
movl $0x0, 0x18(%rax)
movslq -0x20(%rbp), %rdi
movl $0x30, %esi
callq 0x2110
movq 0x18bdb(%rip), %rcx     # 0x26290
movq %rax, 0x10(%rcx)
cmpq $0x0, %rax
jne 0xd6d5
leaq 0x11677(%rip), %rdi     # 0x1ed3d
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl -0x4(%rbp), %eax
imull -0x4(%rbp), %eax
movslq %eax, %rdi
movl $0x8, %esi
callq 0x2110
movq 0x18ba0(%rip), %rcx     # 0x26290
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0xd710
leaq 0x116ae(%rip), %rdi     # 0x1edaf
callq 0x2190
movl $0x1, %edi
callq 0x2260
callq 0x18520
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xd747
movl -0x24(%rbp), %edi
callq 0xdf90
movq 0x18b5d(%rip), %rax     # 0x26290
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xd71c
movl -0x20(%rbp), %eax
movq 0x18b3f(%rip), %rcx     # 0x26290
cmpl 0x18(%rcx), %eax
jne 0xd758
jmp 0xd777
leaq 0x116c1(%rip), %rdi     # 0x1ee20
leaq 0x10ff5(%rip), %rsi     # 0x1e75b
movl $0x16e, %edx            # imm = 0x16E
leaq 0x116d3(%rip), %rcx     # 0x1ee45
callq 0x2100
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xd799
movl -0x28(%rbp), %edi
callq 0xe180
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xd77e
callq 0x186d0
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)