// File: /workspace/github_c_makefile_star2_O3/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 0xda6c
movl %eax, %r12d
movq 0x141b8(%rip), %rax     # 0x1f2a0
movl 0x20(%rax), %ecx
testl %r15d, %r15d
js 0xb1b0
cmpl %r14d, %ecx
jle 0xb1b0
testl %r14d, %r14d
js 0xb1b0
cmpl %r15d, %ecx
jle 0xb1b0
movq (%rax), %rdx
movl %ecx, %esi
imull %r14d, %esi
addl %r15d, %esi
movss 0x1c(%rax), %xmm0
ucomiss (%rdx,%rsi,4), %xmm0
ja 0xb1fc
leaq 0x1694f(%rip), %rax     # 0x21a80
movq (%rax), %rax
movslq %r12d, %rsi
imulq $0x26a8, %rsi, %r13     # imm = 0x26A8
movl 0x278c(%rax,%r13), %edi
movl 0x2790(%rax,%r13), %esi
imull %esi, %ecx
addl %edi, %ecx
movslq %ecx, %rax
ucomiss (%rdx,%rax,4), %xmm0
ja 0xb226
movl %edi, 0xc(%rsp)
movl %esi, 0x8(%rsp)
movl %r15d, %edx
movl %r14d, %ecx
callq 0xabdc
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0xb24a
leaq 0xc0(%rbx), %rcx
subq $0x8, %rsp
leaq 0xacdd(%rip), %rdx      # 0x15e6e
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 0xb1d2
addq $0xc0, %rbx
decl %ecx
leaq 0xac37(%rip), %rsi      # 0x15df7
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 0xcefe
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0xc0, %rbx
leaq 0xac1f(%rip), %rdx      # 0x15e29
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rcx
movl %r15d, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x2390
jmp 0xb1d2
addq $0xc0, %rbx
leaq 0xac1c(%rip), %rdx      # 0x15e50
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2390
jmp 0xb1d2
cvttss2si %xmm0, %r10
testl %r10d, %r10d
js 0xb2cd
testl %ebp, %ebp
je 0xb308
mulss 0x9de0(%rip), %xmm0     # 0x15044
cvttss2si %xmm0, %edx
leaq 0x16811(%rip), %rax     # 0x21a80
movq (%rax), %rcx
movl 0x2820(%rcx,%r13), %eax
subl %edx, %eax
jle 0xb380
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 0xac31(%rip), %rdx      # 0x15ee5
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %r8
movl %r15d, %r9d
xorl %eax, %eax
pushq %r10
jmp 0xb1a3
leaq 0xc0(%rbx), %rcx
movss 0x9d70(%rip), %xmm1     # 0x1504c
divss %xmm1, %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0xabae(%rip), %rdx      # 0x15e9d
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %r8
movb $0x1, %al
callq 0x2390
jmp 0xb1d2
movl $0x3, %edi
movl %r12d, %esi
movl %r10d, %edx
movl $0x1, %ecx
movq %r10, %r12
callq 0xf887
leaq 0x16759(%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 0xac26(%rip), %rsi      # 0x15f7e
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 0xb1d2
addq $0x100, %rcx            # imm = 0x100
cvttss2si %xmm0, %r9
leaq 0xab9d(%rip), %rdx      # 0x15f30
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %r8
xorl %eax, %eax
pushq %r14
pushq %r15
jmp 0xb1a5