// File: /workspace/github_c_makefile_star2_O2/Ziddykins[P]Dawn/src/combat.c
// Function: check_alive
int check_alive(struct Message *message) {
    int pindex = get_pindex(message->sender_nick);
    char out[MAX_MESSAGE_BUFFER];

    if (dawn->players[pindex].health <= 0 || dawn->players[pindex].fullness <= 0) {
        if (dawn->players[pindex].alive) {
            char reason[32];
            float newexp = (float) dawn->players[pindex].experience * 0.90f;
            strcpy(reason, dawn->players[pindex].health <= 0 ? "been killed" : "died from starvation");
            sprintf(out, "PRIVMSG %s :%s has %s! 10%% experience has been lost\r\n",
                    message->receiver, message->sender_nick, reason);
            add_msg(out, strlen(out));
            dawn->players[pindex].deaths++;
            dawn->players[pindex].alive = 0;
            dawn->players[pindex].experience = (unsigned long long) newexp;
            if (dawn->players[pindex].fullness <= 0)
                dawn->players[pindex].fullness = 100;
            return 0;
        }
    }

    if (dawn->global_monster.hp <= 0 && dawn->global_monster.active) {
        sprintf(out, "PRIVMSG %s :The %s has been killed!\r\n", message->receiver, dawn->global_monster.name);
        add_msg(out, strlen(out));
        for (int i = 0; i < dawn->player_count; i++) {
            if (dawn->players[i].contribution > 0) {
                int drop_chance = rand()%100;
                double percent = ((float) dawn->players[i].contribution / (float) dawn->global_monster.mhp);
                double expgain = percent * dawn->global_monster.exp;
                double goldgain = percent * dawn->global_monster.gold;

                //Need to change the sender_nick so the proper drops are awarded as well as level checking
                strncpy(message->sender_nick, dawn->players[i].username, MAX_NICK_LENGTH);
                dawn->players[i].experience += (unsigned long long) expgain;
                dawn->players[i].gold += (int) goldgain;
                sprintf(out, "PRIVMSG %s :%s has helped defeat the foe and receives %d experience and %d gold"
                                " for their efforts!\r\n", message->receiver, dawn->players[i].username, (int) expgain,
                        (int) goldgain);
                dawn->global_monster.active = 0;
                dawn->players[i].kills++;
                check_levelup(message);
                check_bounty(message);

                if (drop_chance < 85) {
                    generate_drop(message);
                }

                if (dawn->global_monster.alignment == EVIL) {
                    dawn->players[pindex].alignment++;
                    if (dawn->players[pindex].alignment == 26) {
                        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s is enveloped by a glowing aura!\r\n", 
                                dawn->active_room, dawn->players[i].username);
                    }
                } else if (dawn->global_monster.alignment == GOOD) {
                    dawn->players[pindex].alignment--;
                    if (dawn->players[pindex].alignment == 26) {
                        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s has grown horns and the town grows worrisome\r\n", 
                                dawn->active_room, dawn->players[i].username);
                    }
                }
                add_msg(out, strlen(out));
            }
        }
        return 0;
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rdi, %rbx
callq 0xc860
leaq 0x1c23c(%rip), %r14     # 0x1fa80
movq (%r14), %rcx
cltq
imulq $0x26a8, %rax, %r13     # imm = 0x26A8
leaq (%rcx,%r13), %rdx
addq $0x1a0, %rdx            # imm = 0x1A0
movq 0x2650(%rdx), %rax
testq %rax, %rax
jle 0x3871
cmpw $0x0, 0x26a2(%rdx)
jg 0x389d
leaq 0x1a0(%rcx), %rsi
cmpl $0x0, 0x2660(%rsi,%r13)
je 0x389d
movq 0x2658(%rdx), %rcx
testq %rcx, %rcx
js 0x3aae
cvtsi2ss %rcx, %xmm0
jmp 0x3ac3
pushq $0x1
popq %rax
cmpl $0x0, 0xf2e40(%rcx)
jg 0x3b84
cmpl $0x0, 0xf2e64(%rcx)
je 0x3b84
movq %r13, 0x8(%rsp)
addq $0xf2e00, %rcx          # imm = 0xF2E00
leaq 0xc0(%rbx), %rdx
leaq 0xd26c(%rip), %rsi      # 0x10b40
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %rdx, 0x28(%rsp)
xorl %eax, %eax
callq 0x2050
movq %r15, %rdi
callq 0x20c0
movq %r15, %rdi
movq %rax, %rsi
callq 0xbd04
movq (%r14), %rax
movl $0x1a0, %r15d           # imm = 0x1A0
movl $0x27d8, %r12d          # imm = 0x27D8
xorl %r13d, %r13d
movslq 0x148(%rax), %rcx
cmpq %rcx, %r13
jge 0x3b82
cmpl $0x0, 0x34(%rax,%r12)
jle 0x3a9b
callq 0x2080
cltd
pushq $0x64
popq %rcx
idivl %ecx
movl %edx, %ebp
movq (%r14), %rax
cvtsi2ssl 0x34(%rax,%r12), %xmm0
cvtsi2ssl 0xf2e44(%rax), %xmm1
leaq (%rax,%r15), %rsi
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
cvtsi2sdl 0xf2e5c(%rax), %xmm2
cvtsi2sdl 0xf2e58(%rax), %xmm1
mulsd %xmm0, %xmm2
movapd %xmm2, 0x30(%rsp)
mulsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
leaq 0x198e5(%rip), %rax     # 0x1d264
movl (%rax), %edx
movq %rbx, %rdi
callq 0x20e0
movapd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
cvttsd2si %xmm0, %r8d
subsd 0xd138(%rip), %xmm0     # 0x10ae0
cvttsd2si %xmm0, %rdx
andq %rcx, %rdx
orq %rax, %rdx
movq (%r14), %rcx
addq %rdx, 0x20(%rcx,%r12)
cvttsd2si 0x10(%rsp), %eax
movslq %eax, %r9
addq %r9, 0x10(%rcx,%r12)
addq %r15, %rcx
leaq 0x60(%rsp), %rdi
leaq 0xd18e(%rip), %rsi      # 0x10b66
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
movq (%r14), %rax
andl $0x0, 0xf2e64(%rax)
incq (%rax,%r12)
movq %rbx, %rdi
callq 0xd117
movq %rbx, %rdi
callq 0x2bcb
cmpl $0x54, %ebp
jg 0x3a0f
movq %rbx, %rdi
callq 0x70fc
movq (%r14), %r8
movl 0xf2e74(%r8), %eax
testl %eax, %eax
je 0x3a42
cmpl $0x1, %eax
jne 0x3a80
movq 0x8(%rsp), %rcx
movl 0x2834(%r8,%rcx), %eax
incl %eax
movl %eax, 0x2834(%r8,%rcx)
leaq 0xd18b(%rip), %rdx      # 0x10bcb
jmp 0x3a60
movq 0x8(%rsp), %rcx
movl 0x2834(%r8,%rcx), %eax
decl %eax
movl %eax, 0x2834(%r8,%rcx)
leaq 0xd19c(%rip), %rdx      # 0x10bfc
cmpl $0x1a, %eax
jne 0x3a80
leaq 0x100(%r8), %rcx
addq %r15, %r8
movl $0x190, %esi            # imm = 0x190
leaq 0x60(%rsp), %rdi
xorl %eax, %eax
callq 0x23a0
leaq 0x60(%rsp), %rbp
movq %rbp, %rdi
callq 0x20c0
movq %rbp, %rdi
movq %rax, %rsi
callq 0xbd04
movq (%r14), %rax
incq %r13
movl $0x26a8, %ecx           # imm = 0x26A8
addq %rcx, %r15
addq %rcx, %r12
jmp 0x390d
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
testq %rax, %rax
mulss 0xd00a(%rip), %xmm0     # 0x10ad8
movaps %xmm0, 0x10(%rsp)
leaq 0xd00e(%rip), %rax      # 0x10ae8
leaq 0xd013(%rip), %rsi      # 0x10af4
cmovleq %rax, %rsi
leaq 0x40(%rsp), %r15
movq %r15, %rdi
callq 0x21c0
leaq 0xc0(%rbx), %rdx
leaq 0xd009(%rip), %rsi      # 0x10b09
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x2050
movq %r12, %rdi
callq 0x20c0
movq %r12, %rdi
movq %rax, %rsi
callq 0xbd04
movq (%r14), %rax
incq 0x27e0(%rax,%r13)
andl $0x0, 0x2800(%rax,%r13)
movaps 0x10(%rsp), %xmm0
cvttss2si %xmm0, %rcx
movq %rcx, %rdx
subss 0xcf8b(%rip), %xmm0     # 0x10adc
sarq $0x3f, %rdx
cvttss2si %xmm0, %rsi
andq %rdx, %rsi
orq %rcx, %rsi
movq %rsi, 0x27f8(%rax,%r13)
cmpw $0x0, 0x2842(%rax,%r13)
jg 0x3b82
addq %r13, %rax
addq $0x2842, %rax           # imm = 0x2842
movw $0x64, (%rax)
xorl %eax, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq