// File: /workspace/github_c_makefile_star2_O1/Ziddykins[P]Dawn/src/monsters.c
// Function: call_monster
void call_monster(char const *username, int global) { //username -> MAX_NICK_LENGTH
    char out[MAX_MESSAGE_BUFFER];
    char monspecial[100];
    char pstring[64];
    int i, pindex, chance, alignchance;
    i = pindex = 0;

    //There will be a 15% chance of encountering a special monster
    //There will be a 10% chance a monster has a special alignment (good vs evil)
    alignchance = rand() % 100;
    chance      = rand() % 100;


    if (global) {
        if (dawn->global_monster.active) {
            sprintf(out, "PRIVMSG %s :The %s got bored and left town. Unfortunately his friend wandered in...\r\n",
                    dawn->active_room, dawn->global_monster.name);
            add_msg(out, strlen(out));
            dawn->global_monster.slay_cost = dawn->global_monster.gold;
            dawn->global_monster.hp = dawn->global_monster.mhp;
        }

        dawn->global_monster = dawn->monsters[rand() % MAX_MONSTERS];
        dawn->global_monster.active = 1;

        for (i = 0; i < dawn->player_count; i++) {
            dawn->players[i].contribution = 0;
        }

        strcpy(pstring, ":");
    } else {
        pindex = get_pindex(username);
        if (dawn->players[pindex].personal_monster.active) return;
        dawn->players[pindex].personal_monster = dawn->monsters[rand() % MAX_MONSTERS];
        dawn->players[pindex].personal_monster.active = 1;
        sprintf(pstring, " and attacks %s:", username);
    }

    struct Monsters tmp = global ? dawn->global_monster : dawn->players[pindex].personal_monster;

    //Buff the current monster and construct a string, depending on which random
    //special type of monster is picked and assign the buffed stats to the tmp monster
    //for display purposes
    if (chance < 15) {
        enum MonsterType type = (enum MonsterType)(rand() % MAX_SPECIAL_MONSTERS);
        global ? (dawn->global_monster.type = type) : (dawn->players[pindex].personal_monster.type = type);
        monster_buff(type, pindex, global);
        global ? (tmp = dawn->global_monster) : (tmp = dawn->players[pindex].personal_monster);
    }
    char align[15] = "\0";

    if (alignchance < 90) {
        enum Alignment good_evil = rand() % 3;
        if (good_evil == GOOD) {
            global ? (dawn->global_monster.alignment = GOOD) : (dawn->players[pindex].personal_monster.alignment = GOOD);
            sprintf(align, "%sGOOD%s", IRC_YELLOW, IRC_NORMAL);
        } else if (good_evil == EVIL) {
            global ? (dawn->global_monster.alignment = EVIL) : (dawn->players[pindex].personal_monster.alignment = EVIL);
            sprintf(align, "%sEVIL%s", IRC_RED, IRC_NORMAL);
        } else {
            global ? (dawn->global_monster.alignment = NEUTRAL) : (dawn->players[pindex].personal_monster.alignment = NEUTRAL);
        }
    }

    //Construct the final output string and send to server
    sprintf(out, "PRIVMSG %s :Monster spawned in room%s [%s] [%d/%d %sHP%s] - [%d STR] - [%d DEF] - [%d INT] -"
                 " [%d MDEF] %s %s\r\n",
            dawn->active_room, pstring, tmp.name, tmp.hp, tmp.mhp, IRC_RED, IRC_NORMAL, tmp.str, tmp.def,
                 tmp.intel, tmp.mdef, get_monstring(tmp.type, monspecial), align);
    add_msg(out, strlen(out));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f8, %rsp            # imm = 0x2F8
movl %esi, %ebx
movq %rdi, %r15
callq 0x2080
movl %eax, %ebp
callq 0x2080
movl %eax, %r14d
testl %ebx, %ebx
je 0xbbd0
leaq 0x15ff8(%rip), %r12     # 0x21a80
movq (%r12), %rdx
cmpl $0x0, 0xf2e64(%rdx)
je 0xbaeb
leaq 0xf2e00(%rdx), %rcx
addq $0x100, %rdx            # imm = 0x100
leaq 0xacb2(%rip), %rsi      # 0x1675c
leaq 0x160(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x2050
movq %r15, %rdi
callq 0x20c0
movq %r15, %rdi
movq %rax, %rsi
callq 0xcd1c
movq (%r12), %rax
movl 0xf2e44(%rax), %ecx
movl 0xf2e58(%rax), %edx
movl %edx, 0xf2e68(%rax)
movl %ecx, 0xf2e40(%rax)
movq (%r12), %r13
leaq 0xf2e00(%r13), %r15
callq 0x2080
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x24, %rcx
addl %edx, %ecx
shll $0x3, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
cltq
imulq $0x78, %rax, %rax
leaq (%rax,%r13), %rsi
addq $0xf1b40, %rsi          # imm = 0xF1B40
movl $0xf, %ecx
movq %r15, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq (%r12), %rax
movl $0x1, 0xf2e64(%rax)
movslq 0x148(%rax), %rcx
testq %rcx, %rcx
jle 0xbb6f
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
xorl %edx, %edx
movl $0x0, 0x280c(%rax,%rdx)
addq $0x26a8, %rdx           # imm = 0x26A8
cmpq %rdx, %rcx
jne 0xbb58
movw $0x3a, 0x120(%rsp)
xorl %r15d, %r15d
movslq %ebp, %rax
imulq $0x51eb851f, %rax, %rax # imm = 0x51EB851F
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x25, %rax
addl %ecx, %eax
imull $0x64, %eax, %eax
movslq %r14d, %rdx
imulq $0x51eb851f, %rdx, %rcx # imm = 0x51EB851F
movq %rcx, %rsi
shrq $0x3f, %rsi
sarq $0x25, %rcx
addl %esi, %ecx
imull $0x64, %ecx, %ecx
subl %ecx, %edx
leaq 0x15ec7(%rip), %r14     # 0x21a80
movq (%r14), %rsi
testl %ebx, %ebx
je 0xbc89
addq $0xf2e00, %rsi          # imm = 0xF2E00
jmp 0xbc9a
movl %ebp, 0x10(%rsp)
movq %r15, %rdi
callq 0xd89c
leaq 0x15e9d(%rip), %rcx     # 0x21a80
movq (%rcx), %r13
movslq %eax, %rbp
imulq $0x26a8, %rbp, %r12     # imm = 0x26A8
cmpl $0x0, 0x12d0(%r13,%r12)
jne 0xc1c9
leaq (%r12,%r13), %rax
addq $0x126c, %rax           # imm = 0x126C
movq %rax, 0x8(%rsp)
callq 0x2080
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x24, %rcx
addl %edx, %ecx
shll $0x3, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
cltq
imulq $0x78, %rax, %rax
leaq (%rax,%r13), %rsi
addq $0xf1b40, %rsi          # imm = 0xF1B40
movl $0x1e, %ecx
movq 0x8(%rsp), %rdi
rep  movsl (%rsi), %es:(%rdi)
leaq 0x15e2b(%rip), %rax     # 0x21a80
movq (%rax), %rax
movl $0x1, 0x12d0(%rax,%r12)
leaq 0xab47(%rip), %rsi      # 0x167b2
leaq 0x120(%rsp), %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
movq %rbp, %r15
movl 0x10(%rsp), %ebp
jmp 0xbb7c
imulq $0x26a8, %r15, %rcx     # imm = 0x26A8
addq %rcx, %rsi
addq $0x126c, %rsi           # imm = 0x126C
leaq 0x38(%rsp), %rdi
movl $0x1e, %ecx
rep  movsl (%rsi), %es:(%rdi)
subl %eax, %ebp
cmpl $0xe, %edx
jg 0xbf81
callq 0x2080
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
movq (%r14), %rcx
testl %ebx, %ebx
je 0xbce0
movl %eax, 0xf2e70(%rcx)
jmp 0xbcee
imulq $0x26a8, %r15, %rdx     # imm = 0x26A8
movl %eax, 0x12dc(%rcx,%rdx)
cmpl $0x4, %eax
ja 0xbf54
movl %eax, %eax
leaq 0xaa30(%rip), %rcx      # 0x16730
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rax
testl %ebx, %ebx
je 0xbec9
shll 0xf2e40(%rax)
jmp 0xbed7
movq (%r14), %rax
testl %ebx, %ebx
je 0xbd8e
movl 0xf2e40(%rax), %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
movl %ecx, 0xf2e40(%rax)
jmp 0xbda8
movq (%r14), %rax
testl %ebx, %ebx
je 0xbea1
shll $0x2, 0xf2e48(%rax)
jmp 0xbf54
movq (%r14), %rax
testl %ebx, %ebx
je 0xbeb5
movl 0xf2e58(%rax), %ecx
leal (%rcx,%rcx,4), %ecx
movl %ecx, 0xf2e58(%rax)
jmp 0xbf54
movq (%r14), %rax
testl %ebx, %ebx
je 0xbf07
movl 0xf2e5c(%rax), %ecx
leal (%rcx,%rcx,2), %ecx
movl %ecx, 0xf2e5c(%rax)
jmp 0xbf54
imulq $0x26a8, %r15, %rcx     # imm = 0x26A8
movl 0x12ac(%rax,%rcx), %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
movl %edx, 0x12ac(%rax,%rcx)
movq (%r14), %rcx
imulq $0x26a8, %r15, %rax     # imm = 0x26A8
leaq 0xf2e4c(%rcx), %rdx
testl %ebx, %ebx
leaq 0x12b8(%rcx,%rax), %rcx
cmovneq %rdx, %rcx
movl (%rcx), %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
movl %edx, (%rcx)
movq (%r14), %rcx
testl %ebx, %ebx
je 0xbdea
movl 0xf2e48(%rcx), %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
movl %edx, 0xf2e48(%rcx)
jmp 0xbdfd
movl 0x12b4(%rcx,%rax), %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
movl %edx, 0x12b4(%rcx,%rax)
movq (%r14), %rcx
testl %ebx, %ebx
je 0xbe17
movl 0xf2e50(%rcx), %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
movl %edx, 0xf2e50(%rcx)
jmp 0xbe2a
movl 0x12bc(%rcx,%rax), %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
movl %edx, 0x12bc(%rcx,%rax)
movq (%r14), %rcx
leaq 0xf2e54(%rcx), %rdx
testl %ebx, %ebx
leaq 0x12c0(%rcx,%rax), %rcx
cmovneq %rdx, %rcx
movl (%rcx), %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
movl %edx, (%rcx)
movq (%r14), %rcx
leaq 0xf2e5c(%rcx), %rdx
testl %ebx, %ebx
leaq 0x12c8(%rcx,%rax), %rcx
cmovneq %rdx, %rcx
movl (%rcx), %edx
addl %edx, %edx
leal (%rdx,%rdx,2), %edx
movl %edx, (%rcx)
movq (%r14), %rcx
testl %ebx, %ebx
je 0xbe89
movl 0xf2e58(%rcx), %eax
addl %eax, %eax
leal (%rax,%rax,2), %eax
movl %eax, 0xf2e58(%rcx)
jmp 0xbf54
movl 0x12c4(%rcx,%rax), %edx
addl %edx, %edx
leal (%rdx,%rdx,2), %edx
movl %edx, 0x12c4(%rcx,%rax)
jmp 0xbf54
imulq $0x26a8, %r15, %rcx     # imm = 0x26A8
shll $0x2, 0x12b4(%rax,%rcx)
jmp 0xbf54
imulq $0x26a8, %r15, %rcx     # imm = 0x26A8
shll $0x2, 0x12c4(%rax,%rcx)
jmp 0xbf54
imulq $0x26a8, %r15, %rcx     # imm = 0x26A8
shll 0x12ac(%rax,%rcx)
movq (%r14), %rcx
imulq $0x26a8, %r15, %rax     # imm = 0x26A8
leaq 0xf2e4c(%rcx), %rdx
testl %ebx, %ebx
leaq 0x12b8(%rcx,%rax), %rcx
cmovneq %rdx, %rcx
shll (%rcx)
movq (%r14), %rcx
testl %ebx, %ebx
je 0xbf21
shll 0xf2e48(%rcx)
jmp 0xbf28
imulq $0x26a8, %r15, %rcx     # imm = 0x26A8
movl 0x12c8(%rax,%rcx), %edx
leal (%rdx,%rdx,2), %edx
movl %edx, 0x12c8(%rax,%rcx)
jmp 0xbf54
shll 0x12b4(%rcx,%rax)
movq (%r14), %rcx
testl %ebx, %ebx
je 0xbf37
shll 0xf2e50(%rcx)
jmp 0xbf3e
shll 0x12bc(%rcx,%rax)
movq (%r14), %rcx
testl %ebx, %ebx
je 0xbf4d
shll 0xf2e54(%rcx)
jmp 0xbf54
shll 0x12c0(%rcx,%rax)
movq (%r14), %rsi
testl %ebx, %ebx
je 0xbf64
addq $0xf2e00, %rsi          # imm = 0xF2E00
jmp 0xbf75
imulq $0x26a8, %r15, %rax     # imm = 0x26A8
addq %rax, %rsi
addq $0x126c, %rsi           # imm = 0x126C
leaq 0x38(%rsp), %rdi
movl $0x1e, %ecx
rep  movsl (%rsi), %es:(%rdi)
xorl %eax, %eax
movq %rax, 0x1f(%rsp)
movq %rax, 0x18(%rsp)
cmpl $0x59, %ebp
jg 0xc05c
callq 0x2080
movslq %eax, %rcx
imulq $0x55555556, %rcx, %rax # imm = 0x55555556
movq %rax, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rax
addl %edx, %eax
leal (%rax,%rax,2), %eax
subl %eax, %ecx
movq (%r14), %rax
cmpl $0x1, %ecx
je 0xbff5
testl %ecx, %ecx
jne 0xc03a
imulq $0x26a8, %r15, %rcx     # imm = 0x26A8
leaq 0xf2e74(%rax), %rdx
testl %ebx, %ebx
leaq 0x12e0(%rax,%rcx), %rax
cmovneq %rdx, %rax
movl $0x0, (%rax)
leaq 0xa7d7(%rip), %rsi      # 0x167c3
leaq 0xa7d9(%rip), %rdx      # 0x167cc
jmp 0xc025
imulq $0x26a8, %r15, %rcx     # imm = 0x26A8
leaq 0xf2e74(%rax), %rdx
testl %ebx, %ebx
leaq 0x12e0(%rax,%rcx), %rax
cmovneq %rdx, %rax
movl $0x1, (%rax)
leaq 0xa7b2(%rip), %rsi      # 0x167d0
leaq 0x5d0b(%rip), %rdx      # 0x11d30
leaq 0x81b1(%rip), %rcx      # 0x141dd
leaq 0x18(%rsp), %rdi
xorl %eax, %eax
callq 0x2050
jmp 0xc05c
testl %ebx, %ebx
je 0xc04a
movl $0x2, 0xf2e74(%rax)
jmp 0xc05c
imulq $0x26a8, %r15, %rcx     # imm = 0x26A8
movl $0x2, 0x12e0(%rax,%rcx)
movl $0x100, %ebx            # imm = 0x100
addq (%r14), %rbx
movl 0x78(%rsp), %ebp
movl 0x7c(%rsp), %eax
movq %rax, 0x10(%rsp)
movl 0x84(%rsp), %eax
movq %rax, 0x8(%rsp)
movl 0x80(%rsp), %eax
movq %rax, 0x30(%rsp)
movl 0x88(%rsp), %eax
movq %rax, 0x28(%rsp)
movl 0x8c(%rsp), %r12d
movl 0xa8(%rsp), %eax
cmpq $0x5, %rax
ja 0xc14a
leaq 0xa68f(%rip), %rcx      # 0x16744
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xab60(%rip), %rdx      # 0x16c25
leaq 0x5c64(%rip), %rcx      # 0x11d30
leaq 0xab59(%rip), %r8       # 0x16c2c
jmp 0xc12f
leaq 0xab49(%rip), %rdx      # 0x16c25
leaq 0xab9e(%rip), %rcx      # 0x16c81
leaq 0xab9b(%rip), %r8       # 0x16c85
jmp 0xc12f
leaq 0xab32(%rip), %rdx      # 0x16c25
leaq 0xab5d(%rip), %rcx      # 0x16c57
leaq 0xab5a(%rip), %r8       # 0x16c5b
jmp 0xc12f
leaq 0xab1b(%rip), %rdx      # 0x16c25
leaq 0xab5a(%rip), %rcx      # 0x16c6b
leaq 0xab57(%rip), %r8       # 0x16c6f
jmp 0xc12f
leaq 0xab04(%rip), %rdx      # 0x16c25
leaq 0x80ad(%rip), %rcx      # 0x141d5
leaq 0xab12(%rip), %r8       # 0x16c41
leaq 0x80a7(%rip), %r9       # 0x141dd
leaq 0xb0(%rsp), %rdi
movl $0x64, %esi
xorl %eax, %eax
callq 0x2390
subq $0x8, %rsp
leaq 0x20(%rsp), %r13
leaq 0xb8(%rsp), %r15
leaq 0x807b(%rip), %r11      # 0x141dd
leaq 0x5bc7(%rip), %r10      # 0x11d30
leaq 0xa669(%rip), %rsi      # 0x167d9
leaq 0x168(%rsp), %r14
leaq 0x128(%rsp), %rcx
leaq 0x40(%rsp), %r8
movq %r14, %rdi
movq %rbx, %rdx
movl %ebp, %r9d
movl $0x0, %eax
pushq %r13
pushq %r15
pushq %r12
pushq 0x48(%rsp)
pushq 0x58(%rsp)
pushq 0x38(%rsp)
pushq %r11
pushq %r10
pushq 0x58(%rsp)
callq 0x2050
addq $0x50, %rsp
movq %r14, %rdi
callq 0x20c0
movq %r14, %rdi
movq %rax, %rsi
callq 0xcd1c
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, 0xb0(%rsp)
jmp 0xc14a