// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/map.c
// Function: runpath
static float runpath(struct Location ** rop, int x1, int y1, int x2, int y2, int flags) {
    int dim = global_map->dim;
    struct Location *came_from;
    float *cost;

    CALLEXIT(!(came_from = malloc((unsigned int)(dim*dim) * sizeof *came_from)))

    for(int i=0; i<dim*dim; i++) {
        came_from->x = -1;
        came_from->y = -1;
    }

    CALLEXIT(!(cost = malloc((unsigned int)(dim*dim) * sizeof *cost)))

    for(int i = 0; i < dim*dim; i++) {
        cost[i] = -1;
    }

    came_from[x1*dim+x1].x = x1;
    came_from[x1*dim+x1].y = y1;
    cost[y1*dim+x1] = 0;

    PriorityQueue pq = init_priority_queue();
    struct Location * start;
    CALLEXIT(!(start = malloc(sizeof *start)))
    start->x = x1;
    start->y = y1;
    priority_insert(pq, 0, start);

    while (!priority_empty(pq)) {
        struct Location * current = priority_remove_min(pq);
        int x = current->x, y = current->y;
        free(current);

        if (x == x2 && y == y2 && !(flags & ALL_TARGETS)) {
            break;
        }

        int cur_x, cur_y;

        for(int i = 0; i < 8; i++) {
            move_step(&cur_x, &cur_y, x, y, iter_to_dirflag(i));

            if(!is_valid(cur_x, cur_y, dim)) {
                continue;
            }

            float new_cost = cost[y * dim + x] + transfer_cost(x, y, cur_x, cur_y);

            if(cost[cur_y*dim+cur_x] > new_cost || cost[cur_y*dim+cur_x] < 0) {
                cost[cur_y*dim+cur_x] = new_cost;
                came_from[cur_y*dim+cur_x].x = x;
                came_from[cur_y*dim+cur_x].y = y;
                struct Location * nloc;
                //dynamic memory to avoid filling stack space with &((struct Location){.x = x-1, .y = y})
                CALLEXIT(!(nloc = malloc(sizeof *nloc)))
                nloc->x = cur_x;
                nloc->y = cur_y;
                priority_insert(pq, new_cost+manhattan(nloc->x, nloc->y, x2, y2), nloc);
            }
        }
    }

    if (flags & RECONSTRUCT) {
        *rop = came_from;
    } else {
        free(came_from);
    }

    float final_cost = cost[y2*dim+x2];
    free(cost);
    free_priority_queue(pq, 1);
    return final_cost;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movq 0x17b49(%rip), %rax     # 0x26290
movl 0x20(%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
imull -0x20(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x22b0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0xe781
leaq 0x10bec(%rip), %rdi     # 0x1f35e
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x20(%rbp), %ecx
imull -0x20(%rbp), %ecx
cmpl %ecx, %eax
jge 0xe7b6
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xe788
movl -0x20(%rbp), %eax
imull -0x20(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x22b0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0xe7ea
leaq 0x10be8(%rip), %rdi     # 0x1f3c3
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl -0x20(%rbp), %ecx
imull -0x20(%rbp), %ecx
cmpl %ecx, %eax
jge 0xe81f
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movss 0xf84d(%rip), %xmm0     # 0x1e05c
movss %xmm0, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xe7f1
movl -0xc(%rbp), %edx
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
imull -0x20(%rbp), %ecx
addl -0xc(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,8)
movl -0x10(%rbp), %edx
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
imull -0x20(%rbp), %ecx
addl -0xc(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, 0x4(%rax,%rcx,8)
movq -0x30(%rbp), %rax
movl -0x10(%rbp), %ecx
imull -0x20(%rbp), %ecx
addl -0xc(%rbp), %ecx
movslq %ecx, %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
callq 0x18ce0
movq %rax, -0x40(%rbp)
movl $0x8, %edi
callq 0x22b0
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
jne 0xe89a
leaq 0x10b93(%rip), %rdi     # 0x1f41e
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl -0xc(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
movl -0x10(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
xorps %xmm0, %xmm0
callq 0x18e40
movq -0x40(%rbp), %rdi
callq 0x19340
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xe8d7
jmp 0xead5
movq -0x40(%rbp), %rdi
callq 0x18f50
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
callq 0x2240
movl -0x54(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0xe920
movl -0x58(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0xe920
movl -0x1c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0xe920
jmp 0xead5
movl $0x0, -0x64(%rbp)
cmpl $0x8, -0x64(%rbp)
jge 0xead0
movl -0x54(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x64(%rbp), %edi
callq 0xe640
movl -0x7c(%rbp), %edx
movl -0x78(%rbp), %ecx
movl %eax, %r8d
leaq -0x5c(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xfa20
movl -0x5c(%rbp), %edi
movl -0x60(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0xf660
cmpl $0x0, %eax
jne 0xe973
jmp 0xeac2
movq -0x30(%rbp), %rax
movl -0x58(%rbp), %ecx
imull -0x20(%rbp), %ecx
addl -0x54(%rbp), %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x80(%rbp)
movl -0x54(%rbp), %edi
movl -0x58(%rbp), %esi
movl -0x5c(%rbp), %edx
movl -0x60(%rbp), %ecx
callq 0xfab0
movaps %xmm0, %xmm1
movss -0x80(%rbp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x68(%rbp)
movq -0x30(%rbp), %rax
movl -0x60(%rbp), %ecx
imull -0x20(%rbp), %ecx
addl -0x5c(%rbp), %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
ucomiss -0x68(%rbp), %xmm0
ja 0xe9ea
movq -0x30(%rbp), %rax
movl -0x60(%rbp), %ecx
imull -0x20(%rbp), %ecx
addl -0x5c(%rbp), %ecx
movslq %ecx, %rcx
xorps %xmm0, %xmm0
ucomiss (%rax,%rcx,4), %xmm0
jbe 0xeac0
movss -0x68(%rbp), %xmm0
movq -0x30(%rbp), %rax
movl -0x60(%rbp), %ecx
imull -0x20(%rbp), %ecx
addl -0x5c(%rbp), %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x54(%rbp), %edx
movq -0x28(%rbp), %rax
movl -0x60(%rbp), %ecx
imull -0x20(%rbp), %ecx
addl -0x5c(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,8)
movl -0x58(%rbp), %edx
movq -0x28(%rbp), %rax
movl -0x60(%rbp), %ecx
imull -0x20(%rbp), %ecx
addl -0x5c(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl $0x8, %edi
callq 0x22b0
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
jne 0xea5e
leaq 0x10a12(%rip), %rdi     # 0x1f461
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl -0x5c(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movl -0x60(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
movss -0x68(%rbp), %xmm0
movss %xmm0, -0x84(%rbp)
movq -0x70(%rbp), %rax
movl (%rax), %edi
movq -0x70(%rbp), %rax
movl 0x4(%rax), %esi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
callq 0xfb80
movq -0x90(%rbp), %rdi
movaps %xmm0, %xmm1
movss -0x84(%rbp), %xmm0
addss %xmm1, %xmm0
movq -0x70(%rbp), %rsi
callq 0x18e40
jmp 0xeac2
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xe927
jmp 0xe8bd
movl -0x1c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xeaed
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
jmp 0xeaf6
movq -0x28(%rbp), %rdi
callq 0x2240
movq -0x30(%rbp), %rax
movl -0x18(%rbp), %ecx
imull -0x20(%rbp), %ecx
addl -0x14(%rbp), %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x74(%rbp)
movq -0x30(%rbp), %rdi
callq 0x2240
movq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x18d50
movss -0x74(%rbp), %xmm0
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)