// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/map.c
// Function: place_town
static inline void place_town(int idx) {
    int dim = global_map->dim;
    struct town * _town = &(global_map->towns[idx]);

    _town->entitiy_count = (int)(10 + gaussrand() * 5);
    CALLEXIT(!(_town->t_ent = calloc((size_t) (_town->entitiy_count), sizeof *_town->t_ent)))
    int x = 0, y = 0, counter = 0;
    do {
        x = (int) (randd() * dim);
        y = (int) (randd() * dim);
        counter++;
    } while ((!is_valid(x, y, dim) || is_obstructed(x, y) ||
              too_close_to_town(x, y)) && counter < GENERATION_TRIALS);
    if (counter >= GENERATION_TRIALS) {
        PRINTERR("Map dimensions too small. Retry or increase map size.")
        exit(1);
    }
    _town->t_ent[0] = &global_map->m_ent[y * dim + x];
    _town->t_ent[0]->type = ENT_TOWN;
    for (int i = 0; i < MAT_COUNT; i++) {
        _town->matdistr[i] = noise(x * PERLIN_SCALE, y * PERLIN_SCALE, i * PERLIN_V_SCALE);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movq 0x182ee(%rip), %rax     # 0x26290
movl 0x20(%rax), %eax
movl %eax, -0x8(%rbp)
movq 0x182e1(%rip), %rax     # 0x26290
movq 0x10(%rax), %rax
movslq -0x4(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
callq 0x181e0
movsd 0x100b9(%rip), %xmm1    # 0x1e088
mulsd %xmm1, %xmm0
movsd 0x1009d(%rip), %xmm1    # 0x1e078
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
movslq 0x28(%rax), %rdi
movl $0x8, %esi
callq 0x2110
movq -0x10(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0xe020
leaq 0x11118(%rip), %rdi     # 0x1f129
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
callq 0x181c0
cvtsi2sdl -0x8(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x14(%rbp)
callq 0x181c0
cvtsi2sdl -0x8(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %edi
movl -0x18(%rbp), %esi
movl -0x8(%rbp), %edx
callq 0xf660
cmpl $0x0, %eax
je 0xe0a2
movl -0x14(%rbp), %edi
movl -0x18(%rbp), %esi
callq 0xe620
cmpl $0x0, %eax
jne 0xe0a2
movl -0x14(%rbp), %edi
movl -0x18(%rbp), %esi
callq 0xf6b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x21(%rbp)
je 0xe0af
cmpl $0x2710, -0x1c(%rbp)    # imm = 0x2710
setl %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0xe035
cmpl $0x2710, -0x1c(%rbp)    # imm = 0x2710
jl 0xe0d9
leaq 0x110d1(%rip), %rdi     # 0x1f19b
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq 0x181b0(%rip), %rax     # 0x26290
movq 0x8(%rax), %rcx
movl -0x18(%rbp), %eax
imull -0x8(%rbp), %eax
addl -0x14(%rbp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rax
movl $0x1, (%rax)
movl $0x0, -0x20(%rbp)
cmpl $0x8, -0x20(%rbp)
jge 0xe170
cvtsi2ssl -0x14(%rbp), %xmm0
movss 0xff2b(%rip), %xmm1     # 0x1e058
mulss %xmm1, %xmm0
cvtsi2ssl -0x18(%rbp), %xmm1
movss 0xff1a(%rip), %xmm2     # 0x1e058
mulss %xmm2, %xmm1
cvtsi2ssl -0x20(%rbp), %xmm2
movss 0xff05(%rip), %xmm3     # 0x1e054
mulss %xmm3, %xmm2
callq 0x18700
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xe11a
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)