// File: /workspace/github_c_makefile_star2_O1/Ziddykins[P]Dawn/src/map.c
// Function: move_player
void move_player(struct Message *message, int x, int y, int teleport) {
    char out[MAX_MESSAGE_BUFFER];
    int pindex = get_pindex(message->sender_nick);
    float travel_time;

    if (x < 0 || x >= global_map->dim || y < 0 || y >= global_map->dim) {
        sprintf(out, "PRIVMSG %s :Invalid location, this map is %dx%d\r\n", message->receiver, global_map->dim-1, global_map->dim-1);
        add_msg(out, strlen(out));
        return;
    }

    if (is_obstructed(x, y)) {
        snprintf(out, MAX_MESSAGE_BUFFER,"PRIVMSG %s :(%d,%d) is obstructed :(\r\n", message->receiver, x, y);
        add_msg(out, strlen(out));
        return;
    }

    int cx = dawn->players[pindex].pos_x;
    int cy = dawn->players[pindex].pos_y;

    if (is_obstructed(cx, cy)) {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :You're stuck :(\r\n", message->receiver);
        add_msg(out, strlen(out));
        return;
    }

    travel_time = pathlen(cx, cy, x, y)*TRAVEL_TIME_MULT;

    if (travel_time < 0) {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s, (%d,%d) cannot be reached :(\r\n", message->receiver, message->sender_nick, x, y);
        add_msg(out, strlen(out));
        return;
    }

    if ((unsigned int)travel_time >= (unsigned int)((((unsigned int)1<<(sizeof(unsigned int) * 8 - 1))-1)/TRAVEL_TIME_MULT)) {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s, you cannot travel that far! It would take %.2f hours!\r\n", message->receiver, message->sender_nick, travel_time/60/60);
        add_msg(out, strlen(out));
        return;
    }

    if (teleport) {
        int teleport_cost = (int)(travel_time / 2.0f);

        if (dawn->players[pindex].mana > teleport_cost) {
            dawn->players[pindex].mana -= teleport_cost;
            dawn->players[pindex].pos_x = x;
            dawn->players[pindex].pos_y = y;
            snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s, you have teleported to %d,%d, saving you %u travel time!\r\n",
                    message->receiver, message->sender_nick, x, y, (unsigned int)travel_time);
            add_msg(out, strlen(out));

            return;
        } else {
            snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s, you do not have the required %u mana to teleport to %d, %d!\r\n",
                    dawn->active_room, message->sender_nick, (unsigned int)(travel_time / 2.0f), x, y);
            add_msg(out, strlen(out));

            return;
        }
    }

    add_event(TRAVEL, pindex, (unsigned int)travel_time, UNIQUE);

    dawn->players[pindex].travel_timer.pos.x = x;
    dawn->players[pindex].travel_timer.pos.y = y;
    dawn->players[pindex].travel_timer.active = 1;

    sprintf(out, "PRIVMSG %s :%s, you are traveling from (%d,%d) to (%d,%d). This will take %u seconds.\r\n",
            message->receiver, message->sender_nick, cx, cy, x, y, (unsigned int)travel_time);
    add_msg(out, strlen(out));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movl %ecx, %ebp
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %rbx
callq 0xd89c
testl %r15d, %r15d
js 0xb091
movl %eax, %r12d
movq 0x142d0(%rip), %rdx     # 0x1f2a0
movl 0x20(%rdx), %eax
cmpl %r14d, %eax
jle 0xb091
testl %r14d, %r14d
js 0xb091
cmpl %r15d, %eax
jle 0xb091
movq (%rdx), %rcx
movl %eax, %esi
imull %r14d, %esi
addl %r15d, %esi
movslq %esi, %rsi
movss 0x1c(%rdx), %xmm0
ucomiss (%rcx,%rsi,4), %xmm0
ja 0xb0e7
leaq 0x16a6d(%rip), %rdx     # 0x21a80
movq (%rdx), %rdx
movslq %r12d, %rsi
imulq $0x26a8, %rsi, %r13     # imm = 0x26A8
movl 0x278c(%rdx,%r13), %edi
movl 0x2790(%rdx,%r13), %esi
imull %esi, %eax
addl %edi, %eax
cltq
ucomiss (%rcx,%rax,4), %xmm0
ja 0xb111
movl %edi, 0xc(%rsp)
movl %esi, 0x8(%rsp)
movl %r15d, %edx
movl %r14d, %ecx
callq 0xabbc
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0xb135
leaq 0xc0(%rbx), %rcx
subq $0x8, %rsp
leaq 0xadac(%rip), %rdx      # 0x15e1e
leaq 0x18(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %r8
movl %r15d, %r9d
xorl %eax, %eax
pushq %r14
callq 0x2390
addq $0x10, %rsp
jmp 0xb0bd
addq $0xc0, %rbx
movq 0x14201(%rip), %rax     # 0x1f2a0
movl 0x20(%rax), %ecx
decl %ecx
leaq 0xacfc(%rip), %rsi      # 0x15da7
leaq 0x10(%rsp), %rdi
movq %rbx, %rdx
movl %ecx, %r8d
xorl %eax, %eax
callq 0x2050
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x20c0
movq %rbx, %rdi
movq %rax, %rsi
callq 0xcd1c
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0xc0, %rbx
leaq 0xace4(%rip), %rdx      # 0x15dd9
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rcx
movl %r15d, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x2390
jmp 0xb0bd
addq $0xc0, %rbx
leaq 0xace1(%rip), %rdx      # 0x15e00
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2390
jmp 0xb0bd
cvttss2si %xmm0, %r10
testl %r10d, %r10d
js 0xb1b8
testl %ebp, %ebp
je 0xb1f3
mulss 0x9ec5(%rip), %xmm0     # 0x15014
cvttss2si %xmm0, %edx
leaq 0x16926(%rip), %rax     # 0x21a80
movq (%rax), %rcx
movl 0x2820(%rcx,%r13), %eax
subl %edx, %eax
jle 0xb26b
leaq (%rcx,%r13), %rdx
addq $0x2820, %rdx           # imm = 0x2820
addq $0x1a0, %rcx            # imm = 0x1A0
movl %eax, (%rdx)
movl %r15d, 0x25ec(%rcx,%r13)
movl %r14d, 0x25f0(%rcx,%r13)
leaq 0xc0(%rbx), %rcx
leaq 0xacf6(%rip), %rdx      # 0x15e95
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %r8
movl %r15d, %r9d
xorl %eax, %eax
pushq %r10
jmp 0xb084
leaq 0xc0(%rbx), %rcx
movss 0x9e55(%rip), %xmm1     # 0x1501c
divss %xmm1, %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0xac73(%rip), %rdx      # 0x15e4d
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %r8
movb $0x1, %al
callq 0x2390
jmp 0xb0bd
movl $0x3, %edi
movl %r12d, %esi
movl %r10d, %edx
movl $0x1, %ecx
movq %r10, %r12
callq 0xf5b7
leaq 0x1686e(%rip), %rax     # 0x21a80
movq (%rax), %rax
movl %r15d, 0x12e4(%rax,%r13)
movl %r14d, 0x12e8(%rax,%r13)
movl $0x1, 0x12ec(%rax,%r13)
leaq 0xc0(%rbx), %rdx
subq $0x8, %rsp
leaq 0xaceb(%rip), %rsi      # 0x15f2e
leaq 0x18(%rsp), %rdi
movq %rbx, %rcx
movl 0x14(%rsp), %r8d
movl 0x10(%rsp), %r9d
xorl %eax, %eax
pushq %r12
pushq %r14
pushq %r15
callq 0x2050
addq $0x20, %rsp
jmp 0xb0bd
addq $0x100, %rcx            # imm = 0x100
cvttss2si %xmm0, %r9
leaq 0xac62(%rip), %rdx      # 0x15ee0
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %r8
xorl %eax, %eax
pushq %r14
pushq %r15
jmp 0xb086