// File: /workspace/github_c_makefile_star2_O3/Ziddykins[P]Dawn/src/monsters.c
// Function: slay_monster
void slay_monster(char const *username, int global, int amount) { //username -> MAX_NICK_LENGTH
    char out[MAX_MESSAGE_BUFFER];
    int pindex = get_pindex(username);

    if (global && dawn->global_monster.active) {
        if (amount < 1 || amount >= MAX_SLAY_GOLD) {
            sprintf(out, "PRIVMSG %s :Please enter an amount in between 1 - %d gold\r\n", dawn->active_room,
                    MAX_SLAY_GOLD);
            add_msg(out, strlen(out));
            return;
        }

        if (dawn->players[pindex].gold >= amount) {
            dawn->players[pindex].gold -= amount;
            dawn->global_monster.slay_cost -= amount;
            sprintf(out, "PRIVMSG %s :%s has contributed %d towards the cost of hiring a warrior to slay "
                            "the monster. %d gold still has to be raised!\r\n", dawn->active_room, username, amount,
                    dawn->global_monster.slay_cost);
        } else {
            sprintf(out, "PRIVMSG %s :%s, you do not have that much gold\r\n", dawn->active_room, username);
        }

        add_msg(out, strlen(out));

        if (dawn->global_monster.slay_cost <= 0) {
            sprintf(out, "PRIVMSG %s :The people have raised enough money to rid their town of the horrid monster "
                    "and hire a warrior to come dispose of the entity. In no time, a warrior rides into town "
                            "and slices the monster in half with one precise strike. Well that was easy...\r\n",
                    dawn->active_room);
            dawn->global_monster.active = 0;
            dawn->global_monster.slay_cost = dawn->global_monster.gold;
            dawn->global_monster.hp = dawn->global_monster.mhp;
            dawn->global_monster.type = DEFMON;
            add_msg(out, strlen(out));
        }
    } else {
        pindex = get_pindex(username);
        if (!dawn->players[pindex].personal_monster.active) return;
        if (dawn->players[pindex].gold >= 150) {
            dawn->players[pindex].gold -= 150;
            sprintf(out, "PRIVMSG %s :%s has paid a true warrior to dispose of the monster which "
                    "they couldn't handle. [Gold -150]\r\n", dawn->active_room, username);
            dawn->players[pindex].personal_monster.hp = dawn->players[pindex].personal_monster.mhp;
            dawn->players[pindex].personal_monster.active = 0;
            dawn->players[pindex].personal_monster.type = DEFMON;
        } else {
            sprintf(out, "PRIVMSG %s :%s, you don't have enough gold to pay a true warrior to dispose "
                    "of this monster [cost: 150 gold]\r\n", dawn->active_room, username);
        }
        add_msg(out, strlen(out));
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movl %edx, %r14d
movl %esi, %ebp
movq %rdi, %rbx
callq 0xda6c
testl %ebp, %ebp
je 0xc418
leaq 0x156a7(%rip), %r15     # 0x21a80
movq (%r15), %rdx
cmpl $0x0, 0xf2e64(%rdx)
je 0xc418
movl $0x80000001, %ecx       # imm = 0x80000001
leal (%r14,%rcx), %esi
cmpl %ecx, %esi
ja 0xc4b9
addq $0x100, %rdx            # imm = 0x100
leaq 0xa4a4(%rip), %rsi      # 0x168a8
movq %rsp, %rdi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %eax, %eax
callq 0x2050
jmp 0xc5b3
movq %rbx, %rdi
callq 0xda6c
leaq 0x15659(%rip), %r15     # 0x21a80
movq (%r15), %rdx
cltq
imulq $0x26a8, %rax, %r14     # imm = 0x26A8
cmpl $0x0, 0x12d0(%rdx,%r14)
je 0xc5c9
leaq (%rdx,%r14), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movq 0x2648(%rax), %rcx
cmpq $0x96, %rcx
jl 0xc4ef
addq $-0x96, %rcx
movq %rcx, 0x2648(%rax)
addq $0x100, %rdx            # imm = 0x100
leaq 0xa617(%rip), %rsi      # 0x16a93
movq %rsp, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
movq (%r15), %rax
movl 0x12b0(%rax,%r14), %ecx
movl %ecx, 0x12ac(%rax,%r14)
movl $0x0, 0x12d0(%rax,%r14)
movl $0x5, 0x12dc(%rax,%r14)
jmp 0xc5b3
cltq
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
movq 0x27e8(%rdx,%rax), %rcx
movl %r14d, %esi
subq %rsi, %rcx
jge 0xc50f
addq $0x100, %rdx            # imm = 0x100
leaq 0xa482(%rip), %rsi      # 0x16962
movq %rsp, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
jmp 0xc54a
addq $0x100, %rdx            # imm = 0x100
leaq 0xa601(%rip), %rsi      # 0x16afe
movq %rsp, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
jmp 0xc5b3
addq %rdx, %rax
addq $0x27e8, %rax           # imm = 0x27E8
movq %rcx, (%rax)
movl 0xf2e68(%rdx), %r9d
subl %r14d, %r9d
movl %r9d, 0xf2e68(%rdx)
addq $0x100, %rdx            # imm = 0x100
leaq 0xa3aa(%rip), %rsi      # 0x168e4
movq %rsp, %rdi
movq %rbx, %rcx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x2050
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x20c0
movq %rbx, %rdi
movq %rax, %rsi
callq 0xcefe
movq (%r15), %rdx
cmpl $0x0, 0xf2e68(%rdx)
jg 0xc5c9
addq $0x100, %rdx            # imm = 0x100
leaq 0xa419(%rip), %rsi      # 0x16993
movq %rsp, %rdi
xorl %eax, %eax
callq 0x2050
movq (%r15), %rax
movl $0x0, 0xf2e64(%rax)
movl 0xf2e44(%rax), %ecx
movl 0xf2e58(%rax), %edx
movl %edx, 0xf2e68(%rax)
movl %ecx, 0xf2e40(%rax)
movl $0x5, 0xf2e70(%rax)
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x20c0
movq %rbx, %rdi
movq %rax, %rsi
callq 0xcefe
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r14
popq %r15
popq %rbp
retq