// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/combat.c
// Function: player_attacks
void player_attacks(struct Message *message, int global) {
    int pindex = get_pindex(message->sender_nick);
    char out[MAX_MESSAGE_BUFFER];
    int player_attack, monster_defense, player_defense, critical;
    int ustats[6] = {dawn->players[pindex].max_health, dawn->players[pindex].max_mana,
                     dawn->players[pindex].strength, dawn->players[pindex].intelligence,
                     dawn->players[pindex].m_def, dawn->players[pindex].defense};

    get_stat(message, ustats);
    player_defense = rand() % dawn->players[pindex].defense;

    //15% chance to critical hit (double) attack
    if ((rand() % 100) < 15) {
        critical = 1;
        player_attack = (rand() % ustats[2]) * 2;
    } else {
        critical = 0;
        player_attack = rand() % ustats[2];
    }

    if (!dawn->players[pindex].alive) {
        sprintf(out, "PRIVMSG %s :%s, you are dead and can't make an attack; revive at a shrine"
                     ", use a potion, or have someone revive you!\r\n", message->receiver, message->sender_nick);
        add_msg(out, strlen(out));
        return;
    }

    if (global && dawn->global_monster.active) {
        if (player_attack == 0) {
            sprintf(out, "PRIVMSG %s :%s trips over his shoelace and misses\r\n", message->receiver,
                         message->sender_nick);
            add_msg(out, strlen(out));
            monster_attacks(message, player_defense, pindex);
        } else {
            //Avoid floating point exceptions
            if (!dawn->global_monster.def == 0) {
                monster_defense = rand() % dawn->global_monster.def;
            } else {
                monster_defense = 0;
            }
            if (player_attack - monster_defense > 0) {
                calc_contribution(pindex, (player_attack - monster_defense), dawn->global_monster.mhp,
                                  dawn->global_monster.hp);
                dawn->global_monster.hp -= (player_attack - monster_defense);
                if (critical) {
                    sprintf(out, "PRIVMSG %s :%s attacks the %s for %d %sCRITICAL%s damage! "
                            "Remaining (%d)\r\n",
                            message->receiver, message->sender_nick, dawn->global_monster.name,
                            player_attack - monster_defense, IRC_RED, IRC_NORMAL, dawn->global_monster.hp);
                } else {
                    sprintf(out, "PRIVMSG %s :%s attacks the %s for %d damage! (Remaining: %d)\r\n",
                            message->receiver, message->sender_nick, dawn->global_monster.name,
                            player_attack - monster_defense, dawn->global_monster.hp);
                }
                add_msg(out, strlen(out));
                if (check_alive(message)) {
                    monster_attacks(message, player_defense, pindex);
                }
            } else {
                sprintf(out, "PRIVMSG %s :The %s has blocked %s's attack!\r\n", message->receiver,
                        dawn->global_monster.name, message->sender_nick);
                monster_attacks(message, player_defense, pindex);
                add_msg(out, strlen(out));
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
callq 0x13ba0
movl %eax, -0x10(%rbp)
leaq 0x23d3b(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x10(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl 0x2670(%rax), %eax
movl %eax, -0x1d0(%rbp)
leaq 0x23d11(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x10(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl 0x2674(%rax), %eax
movl %eax, -0x1cc(%rbp)
leaq 0x23ce7(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x10(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl 0x2684(%rax), %eax
movl %eax, -0x1c8(%rbp)
leaq 0x23cbd(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x10(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl 0x2688(%rax), %eax
movl %eax, -0x1c4(%rbp)
leaq 0x23c93(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x10(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl 0x2690(%rax), %eax
movl %eax, -0x1c0(%rbp)
leaq 0x23c69(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x10(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl 0x268c(%rax), %eax
movl %eax, -0x1bc(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x16700
callq 0x2080
leaq 0x23c2a(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
addq $0x1a0, %rcx            # imm = 0x1A0
movslq -0x10(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rcx
cltd
idivl 0x268c(%rcx)
movl %edx, -0x1ac(%rbp)
callq 0x2080
movl $0x64, %ecx
cltd
idivl %ecx
cmpl $0xf, %edx
jge 0x4e9d
movl $0x1, -0x1b0(%rbp)
callq 0x2080
cltd
idivl -0x1c8(%rbp)
shll %edx
movl %edx, -0x1a4(%rbp)
jmp 0x4eb9
movl $0x0, -0x1b0(%rbp)
callq 0x2080
cltd
idivl -0x1c8(%rbp)
movl %edx, -0x1a4(%rbp)
leaq 0x23bb0(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x10(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
cmpl $0x0, 0x2660(%rax)
jne 0x4f32
leaq -0x1a0(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
movq -0x8(%rbp), %rcx
leaq 0x15d3d(%rip), %rsi     # 0x1ac3a
movb $0x0, %al
callq 0x2050
leaq -0x1a0(%rbp), %rax
movq %rax, -0x1d8(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x20c0
movq -0x1d8(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x5203
cmpl $0x0, -0xc(%rbp)
je 0x5203
leaq 0x23b2d(%rip), %rax     # 0x28a70
movq (%rax), %rax
cmpl $0x0, 0xf2e64(%rax)
je 0x5203
cmpl $0x0, -0x1a4(%rbp)
jne 0x4fc0
leaq -0x1a0(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
movq -0x8(%rbp), %rcx
leaq 0x15d38(%rip), %rsi     # 0x1acb1
movb $0x0, %al
callq 0x2050
leaq -0x1a0(%rbp), %rax
movq %rax, -0x1e0(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x20c0
movq -0x1e0(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
movq -0x8(%rbp), %rdi
movl -0x1ac(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x5210
jmp 0x5201
leaq 0x23aa9(%rip), %rax     # 0x28a70
movq (%rax), %rax
cmpl $0x0, 0xf2e48(%rax)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x4ffe
callq 0x2080
leaq 0x23a84(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
cltd
idivl 0xf2e48(%rcx)
movl %edx, -0x1a8(%rbp)
jmp 0x5008
movl $0x0, -0x1a8(%rbp)
movl -0x1a4(%rbp), %eax
subl -0x1a8(%rbp), %eax
cmpl $0x0, %eax
jle 0x518f
movl -0x10(%rbp), %edi
movl -0x1a4(%rbp), %esi
subl -0x1a8(%rbp), %esi
leaq 0x23a3d(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl 0xf2e44(%rax), %edx
leaq 0x23a2d(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl 0xf2e40(%rax), %ecx
callq 0x53d0
movl -0x1a4(%rbp), %edx
subl -0x1a8(%rbp), %edx
leaq 0x23a0c(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl 0xf2e40(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xf2e40(%rax)
cmpl $0x0, -0x1b0(%rbp)
je 0x50ee
leaq -0x1a0(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
movq -0x8(%rbp), %rcx
leaq 0x239d5(%rip), %rax     # 0x28a70
movq (%rax), %r8
addq $0xf2e00, %r8           # imm = 0xF2E00
movl -0x1a4(%rbp), %r9d
subl -0x1a8(%rbp), %r9d
leaq 0x239b6(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl 0xf2e40(%rax), %eax
leaq 0x15c1b(%rip), %rsi     # 0x1ace5
leaq 0x15c5f(%rip), %r11     # 0x1ad30
leaq 0x1810d(%rip), %r10     # 0x1d1e5
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x2050
jmp 0x5144
leaq -0x1a0(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
movq -0x8(%rbp), %rcx
leaq 0x23965(%rip), %rax     # 0x28a70
movq (%rax), %r8
addq $0xf2e00, %r8           # imm = 0xF2E00
movl -0x1a4(%rbp), %r9d
subl -0x1a8(%rbp), %r9d
leaq 0x23946(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl 0xf2e40(%rax), %eax
leaq 0x15bfa(%rip), %rsi     # 0x1ad34
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2050
leaq -0x1a0(%rbp), %rax
movq %rax, -0x1e8(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x20c0
movq -0x1e8(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
movq -0x8(%rbp), %rdi
callq 0x4590
cmpl $0x0, %eax
je 0x518d
movq -0x8(%rbp), %rdi
movl -0x1ac(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x5210
jmp 0x51ff
leaq -0x1a0(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
leaq 0x238c8(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0xf2e00, %rcx          # imm = 0xF2E00
movq -0x8(%rbp), %r8
leaq 0x15bb6(%rip), %rsi     # 0x1ad73
movb $0x0, %al
callq 0x2050
movq -0x8(%rbp), %rdi
movl -0x1ac(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x5210
leaq -0x1a0(%rbp), %rax
movq %rax, -0x1f0(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x20c0
movq -0x1f0(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x5201
jmp 0x5203
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
nopl (%rax)