// File: /workspace/github_c_makefile_star2_O1/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, (%rsp)
callq 0xd89c
leaq 0x1d4fb(%rip), %r14     # 0x21a80
movq (%r14), %rcx
cltq
imulq $0x26a8, %rax, %rsi     # imm = 0x26A8
leaq (%rcx,%rsi), %rax
addq $0x1a0, %rax            # imm = 0x1A0
cmpq $0x0, 0x2650(%rax)
movq %rsi, 0x8(%rsp)
jle 0x45b4
cmpw $0x0, 0x26a2(%rax)
jg 0x45df
leaq 0x1a0(%rcx), %rdx
cmpl $0x0, 0x2660(%rdx,%rsi)
je 0x45df
movq 0x2658(%rax), %rcx
testq %rcx, %rcx
js 0x482f
cvtsi2ss %rcx, %xmm0
jmp 0x4844
movl $0x1, %ebp
cmpl $0x0, 0xf2e40(%rcx)
jg 0x4911
cmpl $0x0, 0xf2e64(%rcx)
je 0x4911
addq $0xf2e00, %rcx          # imm = 0xF2E00
movq (%rsp), %rax
leaq 0xc0(%rax), %rdx
leaq 0xd529(%rip), %rsi      # 0x11b40
xorl %ebp, %ebp
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %rdx, 0x28(%rsp)
xorl %eax, %eax
callq 0x2050
movq %r12, %rdi
callq 0x20c0
movq %r12, %rdi
movq %rax, %rsi
callq 0xcd1c
movq (%r14), %rax
cmpl $0x0, 0x148(%rax)
jle 0x4911
movl $0x1a0, %ebp            # imm = 0x1A0
movl $0x27d8, %r15d          # imm = 0x27D8
xorl %r12d, %r12d
cmpl $0x0, 0x34(%rax,%r15)
jle 0x4807
callq 0x2080
movslq %eax, %r13
imulq $0x51eb851f, %r13, %rax # imm = 0x51EB851F
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x25, %rax
addl %ecx, %eax
imull $0x64, %eax, %eax
subl %eax, %r13d
movq (%r14), %rax
leaq (%rax,%rbp), %rsi
xorps %xmm0, %xmm0
cvtsi2ssl 0x34(%rax,%r15), %xmm0
cvtsi2ssl 0xf2e44(%rax), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xf2e5c(%rax), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
xorps %xmm1, %xmm1
cvtsi2sdl 0xf2e58(%rax), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
leaq 0x1ab86(%rip), %rax     # 0x1f264
movl (%rax), %edx
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x20e0
movapd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
cvttsd2si %xmm0, %r8d
subsd 0xd3d5(%rip), %xmm0     # 0x11ae0
cvttsd2si %xmm0, %rdx
andq %rcx, %rdx
orq %rax, %rdx
movq (%r14), %rcx
addq %rdx, 0x20(%rcx,%r15)
cvttsd2si 0x10(%rsp), %eax
movslq %eax, %r9
addq %r9, 0x10(%rcx,%r15)
addq %rbp, %rcx
leaq 0x60(%rsp), %rdi
leaq 0xd42b(%rip), %rsi      # 0x11b66
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
movq (%r14), %rax
movl $0x0, 0xf2e64(%rax)
incq (%rax,%r15)
movq %rbx, %rdi
callq 0xe0ef
movq %rbx, %rdi
callq 0x3885
cmpl $0x54, %r13d
jg 0x4777
movq (%rsp), %rdi
callq 0x7f50
leaq 0x1d302(%rip), %r14     # 0x21a80
movq (%r14), %r8
movl 0xf2e74(%r8), %eax
testl %eax, %eax
je 0x47b1
cmpl $0x1, %eax
jne 0x47ef
movq 0x8(%rsp), %rcx
movl 0x2834(%r8,%rcx), %eax
incl %eax
movl %eax, 0x2834(%r8,%rcx)
leaq 0xd41c(%rip), %rdx      # 0x11bcb
jmp 0x47cf
movq 0x8(%rsp), %rcx
movl 0x2834(%r8,%rcx), %eax
decl %eax
movl %eax, 0x2834(%r8,%rcx)
leaq 0xd42d(%rip), %rdx      # 0x11bfc
cmpl $0x1a, %eax
jne 0x47ef
leaq 0x100(%r8), %rcx
addq %rbp, %r8
movl $0x190, %esi            # imm = 0x190
leaq 0x60(%rsp), %rdi
xorl %eax, %eax
callq 0x2390
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
callq 0x20c0
movq %rbx, %rdi
movq %rax, %rsi
callq 0xcd1c
incq %r12
movq (%r14), %rax
movslq 0x148(%rax), %rcx
movl $0x26a8, %edx           # imm = 0x26A8
addq %rdx, %rbp
addq %rdx, %r15
cmpq %rcx, %r12
jl 0x465e
xorl %ebp, %ebp
jmp 0x4911
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
mulss 0xd28c(%rip), %xmm0     # 0x11ad8
movaps %xmm0, 0x10(%rsp)
cmpq $0x0, 0x2650(%rax)
leaq 0xd288(%rip), %rax      # 0x11ae8
leaq 0xd28d(%rip), %rsi      # 0x11af4
cmovleq %rax, %rsi
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x21c0
movq (%rsp), %rcx
leaq 0xc0(%rcx), %rdx
leaq 0xd27f(%rip), %rsi      # 0x11b09
xorl %ebp, %ebp
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %r12, %r8
xorl %eax, %eax
callq 0x2050
movq %r15, %rdi
callq 0x20c0
movq %r15, %rdi
movq %rax, %rsi
callq 0xcd1c
movq (%r14), %rax
movq 0x8(%rsp), %rdi
incq 0x27e0(%rax,%rdi)
movaps 0x10(%rsp), %xmm0
cvttss2si %xmm0, %rcx
movl $0x0, 0x2800(%rax,%rdi)
movq %rcx, %rdx
subss 0xd1fb(%rip), %xmm0     # 0x11adc
sarq $0x3f, %rdx
cvttss2si %xmm0, %rsi
andq %rdx, %rsi
orq %rcx, %rsi
movq %rsi, 0x27f8(%rax,%rdi)
cmpw $0x0, 0x2842(%rax,%rdi)
jg 0x4911
addq %rdi, %rax
addq $0x2842, %rax           # imm = 0x2842
movw $0x64, (%rax)
movl %ebp, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq