// File: /workspace/github_c_makefile_star2_O1/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 0xd89c
testl %ebp, %ebp
je 0xc24c
leaq 0x15873(%rip), %r15     # 0x21a80
movq (%r15), %rdx
cmpl $0x0, 0xf2e64(%rdx)
je 0xc24c
movl $0x80000001, %ecx       # imm = 0x80000001
leal (%r14,%rcx), %esi
cmpl %ecx, %esi
ja 0xc2ed
addq $0x100, %rdx            # imm = 0x100
leaq 0xa610(%rip), %rsi      # 0x16848
movq %rsp, %rdi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %eax, %eax
callq 0x2050
jmp 0xc3e7
movq %rbx, %rdi
callq 0xd89c
leaq 0x15825(%rip), %r15     # 0x21a80
movq (%r15), %rdx
cltq
imulq $0x26a8, %rax, %r14     # imm = 0x26A8
cmpl $0x0, 0x12d0(%rdx,%r14)
je 0xc3fd
leaq (%rdx,%r14), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movq 0x2648(%rax), %rcx
cmpq $0x96, %rcx
jl 0xc323
addq $-0x96, %rcx
movq %rcx, 0x2648(%rax)
addq $0x100, %rdx            # imm = 0x100
leaq 0xa783(%rip), %rsi      # 0x16a33
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 0xc3e7
cltq
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
movq 0x27e8(%rdx,%rax), %rcx
movl %r14d, %esi
subq %rsi, %rcx
jge 0xc343
addq $0x100, %rdx            # imm = 0x100
leaq 0xa5ee(%rip), %rsi      # 0x16902
movq %rsp, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
jmp 0xc37e
addq $0x100, %rdx            # imm = 0x100
leaq 0xa76d(%rip), %rsi      # 0x16a9e
movq %rsp, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
jmp 0xc3e7
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 0xa516(%rip), %rsi      # 0x16884
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 0xcd1c
movq (%r15), %rdx
cmpl $0x0, 0xf2e68(%rdx)
jg 0xc3fd
addq $0x100, %rdx            # imm = 0x100
leaq 0xa585(%rip), %rsi      # 0x16933
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 0xcd1c
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r14
popq %r15
popq %rbp
retq