// File: /workspace/github_c_makefile_star2_O2/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, %r12d
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %rbx
callq 0xc860
movl %eax, %ebp
movq 0x1321d(%rip), %rax     # 0x1d2a0
movl 0x20(%rax), %ecx
testl %r15d, %r15d
js 0xa0d3
cmpl %r14d, %ecx
jle 0xa0d3
testl %r14d, %r14d
js 0xa0d3
cmpl %r15d, %ecx
jle 0xa0d3
movl %r15d, %edi
movl %r14d, %esi
callq 0x9c4a
testl %eax, %eax
je 0xa11f
addq $0xc0, %rbx
leaq 0xad1a(%rip), %rdx      # 0x14dd1
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rcx
movl %r15d, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x23a0
jmp 0xa0f5
addq $0xc0, %rbx
decl %ecx
leaq 0xacbc(%rip), %rsi      # 0x14d9f
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 0xbd04
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1595a(%rip), %rax     # 0x1fa80
movq (%rax), %rax
movslq %ebp, %rcx
imulq $0x26a8, %rcx, %r13     # imm = 0x26A8
movl 0x278c(%rax,%r13), %edi
movl 0x2790(%rax,%r13), %esi
movl %edi, (%rsp)
movl %esi, 0x4(%rsp)
callq 0x9c4a
testl %eax, %eax
je 0xa17a
addq $0xc0, %rbx
leaq 0xac97(%rip), %rdx      # 0x14df8
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %rcx
xorl %eax, %eax
callq 0x23a0
jmp 0xa0f5
movq %r13, 0x8(%rsp)
movl (%rsp), %edi
movl 0x4(%rsp), %r13d
movl %r13d, %esi
movl %r15d, %edx
movl %r14d, %ecx
callq 0x9c98
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0xa1cf
leaq 0xc0(%rbx), %rcx
subq $0x8, %rsp
leaq 0xac67(%rip), %rdx      # 0x14e16
leaq 0x18(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %r8
movl %r15d, %r9d
xorl %eax, %eax
pushq %r14
callq 0x23a0
popq %rcx
popq %rdx
jmp 0xa0f5
cvttss2si %xmm0, %r10
testl %r10d, %r10d
js 0xa257
testl %r12d, %r12d
je 0xa292
mulss 0x9e26(%rip), %xmm0     # 0x14010
cvttss2si %xmm0, %edx
leaq 0x1588b(%rip), %rax     # 0x1fa80
movq (%rax), %rcx
movq 0x8(%rsp), %rsi
movl 0x2820(%rcx,%rsi), %eax
subl %edx, %eax
jle 0xa307
leaq (%rcx,%rsi), %rdx
addq $0x2820, %rdx           # imm = 0x2820
addq $0x1a0, %rcx            # imm = 0x1A0
movl %eax, (%rdx)
movl %r15d, 0x25ec(%rcx,%rsi)
movl %r14d, 0x25f0(%rcx,%rsi)
leaq 0xc0(%rbx), %rcx
leaq 0xac4f(%rip), %rdx      # 0x14e8d
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %r8
movl %r15d, %r9d
xorl %eax, %eax
pushq %r10
jmp 0xa1c1
leaq 0xc0(%rbx), %rcx
movss 0x9db6(%rip), %xmm1     # 0x1401c
divss %xmm1, %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0xabcc(%rip), %rdx      # 0x14e45
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %r8
movb $0x1, %al
callq 0x23a0
jmp 0xa0f5
pushq $0x3
popq %rdi
pushq $0x1
popq %rcx
movl %ebp, %esi
movl %r10d, %edx
movq %r10, %r12
callq 0xe5c7
leaq 0x157d4(%rip), %rax     # 0x1fa80
movq (%rax), %rax
movq 0x8(%rsp), %rcx
movl %r15d, 0x12e4(%rax,%rcx)
movl %r14d, 0x12e8(%rax,%rcx)
movl $0x1, 0x12ec(%rax,%rcx)
leaq 0xc0(%rbx), %rdx
subq $0x8, %rsp
leaq 0xac45(%rip), %rsi      # 0x14f26
leaq 0x18(%rsp), %rdi
movq %rbx, %rcx
movl 0x8(%rsp), %r8d
movl %r13d, %r9d
xorl %eax, %eax
pushq %r12
pushq %r14
pushq %r15
callq 0x2050
addq $0x20, %rsp
jmp 0xa0f5
addq $0x100, %rcx            # imm = 0x100
cvttss2si %xmm0, %r9
leaq 0xabbe(%rip), %rdx      # 0x14ed8
leaq 0x10(%rsp), %rdi
movl $0x190, %esi            # imm = 0x190
movq %rbx, %r8
xorl %eax, %eax
pushq %r14
pushq %r15
jmp 0xa1c3