// File: /workspace/github_c_makefile_star2_O2/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 0xc860
testl %ebp, %ebp
je 0xb1e6
leaq 0x148d9(%rip), %r15     # 0x1fa80
movq (%r15), %rdx
cmpl $0x0, 0xf2e64(%rdx)
je 0xb1e6
movl $0x80000001, %ecx       # imm = 0x80000001
leal (%r14,%rcx), %esi
cmpl %ecx, %esi
ja 0xb284
addq $0x100, %rdx            # imm = 0x100
leaq 0xa686(%rip), %rsi      # 0x15858
movq %rsp, %rdi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %eax, %eax
callq 0x2050
jmp 0xb37b
movq %rbx, %rdi
callq 0xc860
leaq 0x1488b(%rip), %r15     # 0x1fa80
movq (%r15), %rdx
cltq
imulq $0x26a8, %rax, %r14     # imm = 0x26A8
cmpl $0x0, 0x12d0(%rdx,%r14)
je 0xb391
leaq (%rdx,%r14), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movq 0x2648(%rax), %rcx
cmpq $0x96, %rcx
jl 0xb2ba
addq $-0x96, %rcx
movq %rcx, 0x2648(%rax)
addq $0x100, %rdx            # imm = 0x100
leaq 0xa7f9(%rip), %rsi      # 0x15a43
movq %rsp, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
movq (%r15), %rax
movl 0x12b0(%rax,%r14), %ecx
movl %ecx, 0x12ac(%rax,%r14)
andl $0x0, 0x12d0(%rax,%r14)
movl $0x5, 0x12dc(%rax,%r14)
jmp 0xb37b
cltq
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
movq 0x27e8(%rdx,%rax), %rcx
movl %r14d, %esi
subq %rsi, %rcx
jge 0xb2da
addq $0x100, %rdx            # imm = 0x100
leaq 0xa667(%rip), %rsi      # 0x15912
movq %rsp, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
jmp 0xb315
addq $0x100, %rdx            # imm = 0x100
leaq 0xa7e6(%rip), %rsi      # 0x15aae
movq %rsp, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
jmp 0xb37b
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 0xa58f(%rip), %rsi      # 0x15894
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 0xbd04
movq (%r15), %rdx
cmpl $0x0, 0xf2e68(%rdx)
jg 0xb391
addq $0x100, %rdx            # imm = 0x100
leaq 0xa5fe(%rip), %rsi      # 0x15943
movq %rsp, %rdi
xorl %eax, %eax
callq 0x2050
movq (%r15), %rax
andl $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 0xbd04
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r14
popq %r15
popq %rbp
retq