// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/map.c
// Function: grow_town
static void grow_town(int idx) {
    struct town * _town = &(global_map->towns[idx]);
    int dim = global_map->dim;
    size_t pos = 0;
    size_t q_size = (size_t) (5 * (_town->entitiy_count + 1));
    struct Location *queue;
    CALLEXIT(!(queue = calloc(q_size, sizeof *queue)))
    size_t start = 0, end = 0;

    struct Location t_pos = entity_location(_town->t_ent[0]);
    q_append(queue, start, &end, q_size, (struct Location) {.x = t_pos.x + 1, .y =  t_pos.y});
    q_append(queue, start, &end, q_size, (struct Location) {.x = t_pos.x - 1, .y =  t_pos.y});
    q_append(queue, start, &end, q_size, (struct Location) {.x = t_pos.x, .y =  t_pos.y + 1});
    q_append(queue, start, &end, q_size, (struct Location) {.x = t_pos.x, .y =  t_pos.y - 1});
    while (pos < (size_t) (_town->entitiy_count)) {
        struct Location *cur = q_pop(queue, &start, end, q_size);
        int x = cur->x;
        int y = cur->y;
        _town->t_ent[pos] = &(global_map->m_ent[y * dim + x]);
        rand_ent(_town->t_ent[pos]);

        //check von neumann neighborhood
        int app_x = x+1, app_y = y;
        if (is_valid(app_x, app_y, global_map->dim) && !is_obstructed(app_x, app_y) && !entity_overlap(app_x, app_y) &&
            !queue_overlap(queue, start, end, q_size, app_x, app_y)) {
            q_append(queue, start, &end, q_size, (struct Location){.x = app_x, .y = app_y});
        }
        app_x = x-1, app_y = y;
        if (is_valid(app_x, app_y, global_map->dim) && !is_obstructed(app_x, app_y) && !entity_overlap(app_x, app_y) &&
            !queue_overlap(queue, start, end, q_size, app_x, app_y)) {
            q_append(queue, start, &end, q_size, (struct Location){.x = app_x, .y = app_y});
        }
        app_x = x, app_y = y+1;
        if (is_valid(app_x, app_y, global_map->dim) && !is_obstructed(app_x, app_y) && !entity_overlap(app_x, app_y) &&
            !queue_overlap(queue, start, end, q_size, app_x, app_y)) {
            q_append(queue, start, &end, q_size, (struct Location){.x = app_x, .y = app_y});
        }
        app_x = x, app_y = y-1;
        if (is_valid(app_x, app_y, global_map->dim) && !is_obstructed(app_x, app_y) && !entity_overlap(app_x, app_y) &&
            !queue_overlap(queue, start, end, q_size, app_x, app_y)) {
            q_append(queue, start, &end, q_size, (struct Location){.x = app_x, .y = app_y});
        }

        pos++;
    }

    free(queue);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl %edi, -0x4(%rbp)
movq 0x180fb(%rip), %rax     # 0x26290
movq 0x10(%rax), %rax
movslq -0x4(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movq 0x180e1(%rip), %rax     # 0x26290
movl 0x20(%rax), %eax
movl %eax, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
addl $0x1, %eax
imull $0x5, %eax, %eax
cltq
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x8, %esi
callq 0x2110
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0xe1fe
leaq 0x11004(%rip), %rdi     # 0x1f1f3
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rdi
callq 0xdb30
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x50(%rbp), %r8
leaq -0x40(%rbp), %rdx
callq 0xf790
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl -0x48(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x58(%rbp), %r8
leaq -0x40(%rbp), %rdx
callq 0xf790
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl -0x48(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movq -0x60(%rbp), %r8
leaq -0x40(%rbp), %rdx
callq 0xf790
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl -0x48(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x44(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x64(%rbp)
movq -0x68(%rbp), %r8
leaq -0x40(%rbp), %rdx
callq 0xf790
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x28(%rcx), %rcx
cmpq %rcx, %rax
jae 0xe5bb
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq -0x38(%rbp), %rsi
callq 0xf820
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x74(%rbp)
movq -0x70(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x78(%rbp)
movq 0x17f86(%rip), %rax     # 0x26290
movq 0x8(%rax), %rdx
movl -0x78(%rbp), %eax
imull -0x14(%rbp), %eax
addl -0x74(%rbp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rdx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xf8a0
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
movq 0x17f2e(%rip), %rax     # 0x26290
movl 0x20(%rax), %edx
callq 0xf660
cmpl $0x0, %eax
je 0xe3df
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
callq 0xe620
cmpl $0x0, %eax
jne 0xe3df
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
callq 0xf970
cmpl $0x0, %eax
jne 0xe3df
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x7c(%rbp), %r8d
movl -0x80(%rbp), %r9d
callq 0xf9a0
cmpl $0x0, %eax
jne 0xe3df
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl -0x7c(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x88(%rbp), %r8
leaq -0x40(%rbp), %rdx
callq 0xf790
movl -0x74(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x7c(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
movq 0x17e95(%rip), %rax     # 0x26290
movl 0x20(%rax), %edx
callq 0xf660
cmpl $0x0, %eax
je 0xe478
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
callq 0xe620
cmpl $0x0, %eax
jne 0xe478
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
callq 0xf970
cmpl $0x0, %eax
jne 0xe478
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x7c(%rbp), %r8d
movl -0x80(%rbp), %r9d
callq 0xf9a0
cmpl $0x0, %eax
jne 0xe478
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl -0x7c(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x8c(%rbp)
movq -0x90(%rbp), %r8
leaq -0x40(%rbp), %rdx
callq 0xf790
movl -0x74(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
movq 0x17dfc(%rip), %rax     # 0x26290
movl 0x20(%rax), %edx
callq 0xf660
cmpl $0x0, %eax
je 0xe511
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
callq 0xe620
cmpl $0x0, %eax
jne 0xe511
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
callq 0xf970
cmpl $0x0, %eax
jne 0xe511
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x7c(%rbp), %r8d
movl -0x80(%rbp), %r9d
callq 0xf9a0
cmpl $0x0, %eax
jne 0xe511
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl -0x7c(%rbp), %eax
movl %eax, -0x98(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x94(%rbp)
movq -0x98(%rbp), %r8
leaq -0x40(%rbp), %rdx
callq 0xf790
movl -0x74(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x78(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x80(%rbp)
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
movq 0x17d63(%rip), %rax     # 0x26290
movl 0x20(%rax), %edx
callq 0xf660
cmpl $0x0, %eax
je 0xe5aa
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
callq 0xe620
cmpl $0x0, %eax
jne 0xe5aa
movl -0x7c(%rbp), %edi
movl -0x80(%rbp), %esi
callq 0xf970
cmpl $0x0, %eax
jne 0xe5aa
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x7c(%rbp), %r8d
movl -0x80(%rbp), %r9d
callq 0xf9a0
cmpl $0x0, %eax
jne 0xe5aa
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl -0x7c(%rbp), %eax
movl %eax, -0xa0(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq -0xa0(%rbp), %r8
leaq -0x40(%rbp), %rdx
callq 0xf790
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xe2c2
movq -0x30(%rbp), %rdi
callq 0x2240
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)