// File: /workspace/github_c_makefile_star2_O3/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
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
testl %ebx, %ebx
je 0xbdf7
leaq 0x15ede(%rip), %r12     # 0x21a80
movq (%r12), %r14
cmpl $0x0, 0xf2e64(%r14)
je 0xbc0d
leaq 0xf2e00(%r14), %rcx
addq $0x100, %r14            # imm = 0x100
leaq 0xabf7(%rip), %rsi      # 0x167bc
leaq 0x160(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2050
movq %r15, %rdi
callq 0x20c0
movq %r15, %rdi
movq %rax, %rsi
callq 0xcefe
movq (%r12), %r14
movl 0xf2e44(%r14), %eax
movl 0xf2e58(%r14), %ecx
movl %ecx, 0xf2e68(%r14)
movl %eax, 0xf2e40(%r14)
leaq 0xf2e00(%r14), %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 (%r14,%rax), %rsi
addq $0xf1b40, %rsi          # imm = 0xF1B40
movl $0xf, %ecx
movq %r15, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq (%r12), %rsi
movl $0x1, 0xf2e64(%rsi)
movslq 0x148(%rsi), %rax
testq %rax, %rax
jle 0xbd7c
leal 0x3(%rax), %ecx
decq %rax
movq %rax, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %ecx
imulq $0x9aa0, %rcx, %rax     # imm = 0x9AA0
movdqa 0x93ed(%rip), %xmm1     # 0x15080
movdqa 0x5605(%rip), %xmm2     # 0x112a0
xorl %ecx, %ecx
movdqa 0x560b(%rip), %xmm3     # 0x112b0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x93db(%rip), %xmm5     # 0x15090
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %edx
notl %edx
testb $0x1, %dl
je 0xbcf4
movl $0x0, 0x280c(%rsi,%rcx)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0xbd0d
movl $0x0, 0x4eb4(%rsi,%rcx)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %edx
testb $0x1, %dl
je 0xbd4f
movl $0x0, 0x755c(%rsi,%rcx)
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0xbd64
movl $0x0, 0x9c04(%rsi,%rcx)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x9aa0, %rcx           # imm = 0x9AA0
cmpq %rcx, %rax
jne 0xbcb5
movw $0x3a, 0x120(%rsp)
addq $0xf2e00, %rsi          # imm = 0xF2E00
leaq 0x38(%rsp), %rdi
movl $0x1e, %ecx
rep  movsl (%rsi), %es:(%rdi)
xorl %r14d, %r14d
cmpl $0xe, %r13d
jg 0xbf1d
callq 0x2080
movslq %eax, %rdi
imulq $0x66666667, %rdi, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rax
addl %ecx, %eax
leal (%rax,%rax,4), %eax
subl %eax, %edi
movq (%r12), %rax
movl %edi, 0xf2e70(%rax)
xorl %r14d, %r14d
xorl %esi, %esi
movl %ebx, %edx
callq 0xc1b7
movl $0xf2e00, %esi          # imm = 0xF2E00
addq (%r12), %rsi
leaq 0x38(%rsp), %rdi
movl $0x1e, %ecx
rep  movsl (%rsi), %es:(%rdi)
jmp 0xbf1d
movl %ebp, 0x8(%rsp)
movq %r15, %rdi
callq 0xda6c
movl %eax, %r14d
leaq 0x15c73(%rip), %rax     # 0x21a80
movq (%rax), %r12
movslq %r14d, %rax
imulq $0x26a8, %rax, %rbp     # imm = 0x26A8
cmpl $0x0, 0x12d0(%r12,%rbp)
jne 0xc198
leaq (%r12,%rbp), %rax
addq $0x126c, %rax           # imm = 0x126C
movq %rax, 0x10(%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 (%r12,%rax), %rsi
addq $0xf1b40, %rsi          # imm = 0xF1B40
movl $0x1e, %ecx
movq 0x10(%rsp), %rdi
rep  movsl (%rsi), %es:(%rdi)
leaq 0x15c01(%rip), %r12     # 0x21a80
movq (%r12), %rax
movl $0x1, 0x12d0(%rax,%rbp)
leaq 0xa97d(%rip), %rsi      # 0x16812
leaq 0x120(%rsp), %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
movq (%r12), %rax
leaq (%rax,%rbp), %rsi
addq $0x126c, %rsi           # imm = 0x126C
leaq 0x38(%rsp), %rdi
movl $0x1e, %ecx
rep  movsl (%rsi), %es:(%rdi)
cmpl $0xf, %r13d
jge 0xbf19
callq 0x2080
movslq %eax, %rdi
imulq $0x66666667, %rdi, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rax
addl %ecx, %eax
leal (%rax,%rax,4), %eax
subl %eax, %edi
movq (%r12), %rax
movl %edi, 0x12dc(%rax,%rbp)
movl %r14d, %esi
xorl %edx, %edx
callq 0xc1b7
movq (%r12), %rax
leaq (%rax,%rbp), %rsi
addq $0x126c, %rsi           # imm = 0x126C
leaq 0x38(%rsp), %rdi
movl $0x1e, %ecx
rep  movsl (%rsi), %es:(%rdi)
movl 0x8(%rsp), %ebp
movslq %ebp, %rax
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rcx
addl %edx, %ecx
imull $0x64, %ecx, %ecx
subl %ecx, %eax
xorl %ecx, %ecx
movq %rcx, 0x1f(%rsp)
movq %rcx, 0x18(%rsp)
cmpl $0x59, %eax
jg 0xc024
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
leaq 0x15b0a(%rip), %rax     # 0x21a80
movq (%rax), %rax
cmpl $0x1, %ecx
je 0xbfb7
testl %ecx, %ecx
jne 0xbfff
movslq %r14d, %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
leaq 0xf2e74(%rax), %rdx
testl %ebx, %ebx
leaq 0x12e0(%rax,%rcx), %rax
cmovneq %rdx, %rax
movl $0x0, (%rax)
leaq 0xa875(%rip), %rsi      # 0x16823
leaq 0xa877(%rip), %rdx      # 0x1682c
jmp 0xbfea
movslq %r14d, %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
leaq 0xf2e74(%rax), %rdx
testl %ebx, %ebx
leaq 0x12e0(%rax,%rcx), %rax
cmovneq %rdx, %rax
movl $0x1, (%rax)
leaq 0xa84d(%rip), %rsi      # 0x16830
leaq 0x5d7e(%rip), %rdx      # 0x11d68
leaq 0x8224(%rip), %rcx      # 0x14215
leaq 0x18(%rsp), %rdi
xorl %eax, %eax
callq 0x2050
jmp 0xc024
testl %ebx, %ebx
je 0xc00f
movl $0x2, 0xf2e74(%rax)
jmp 0xc024
movslq %r14d, %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
movl $0x2, 0x12e0(%rax,%rcx)
leaq 0x15a55(%rip), %rax     # 0x21a80
movl $0x100, %ebx            # imm = 0x100
addq (%rax), %rbx
movl 0x78(%rsp), %ebp
movl 0x7c(%rsp), %eax
movq %rax, 0x8(%rsp)
movl 0x84(%rsp), %eax
movq %rax, 0x10(%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 0xc119
leaq 0xa70c(%rip), %rcx      # 0x16790
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xabf1(%rip), %rdx      # 0x16c85
leaq 0x5ccd(%rip), %rcx      # 0x11d68
leaq 0xabea(%rip), %r8       # 0x16c8c
jmp 0xc0fe
leaq 0xabda(%rip), %rdx      # 0x16c85
leaq 0xac2f(%rip), %rcx      # 0x16ce1
leaq 0xac2c(%rip), %r8       # 0x16ce5
jmp 0xc0fe
leaq 0xabc3(%rip), %rdx      # 0x16c85
leaq 0xabee(%rip), %rcx      # 0x16cb7
leaq 0xabeb(%rip), %r8       # 0x16cbb
jmp 0xc0fe
leaq 0xabac(%rip), %rdx      # 0x16c85
leaq 0xabeb(%rip), %rcx      # 0x16ccb
leaq 0xabe8(%rip), %r8       # 0x16ccf
jmp 0xc0fe
leaq 0xab95(%rip), %rdx      # 0x16c85
leaq 0x8116(%rip), %rcx      # 0x1420d
leaq 0xaba3(%rip), %r8       # 0x16ca1
leaq 0x8110(%rip), %r9       # 0x14215
leaq 0xb0(%rsp), %rdi
movl $0x64, %esi
xorl %eax, %eax
callq 0x2390
subq $0x8, %rsp
leaq 0x20(%rsp), %r13
leaq 0xb8(%rsp), %r15
leaq 0x80e4(%rip), %r11      # 0x14215
leaq 0x5c30(%rip), %r10      # 0x11d68
leaq 0xa6fa(%rip), %rsi      # 0x16839
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 0x40(%rsp)
pushq %r11
pushq %r10
pushq 0x50(%rsp)
callq 0x2050
addq $0x50, %rsp
movq %r14, %rdi
callq 0x20c0
movq %r14, %rdi
movq %rax, %rsi
callq 0xcefe
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, 0xb0(%rsp)
jmp 0xc119