// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movq %rdi, %r15
callq 0x2080
pushq $0x64
popq %rbx
cltd
idivl %ebx
movl %edx, 0x18(%rsp)
callq 0x2080
cltd
idivl %ebx
movl %ebp, %ebx
movl %edx, %r14d
pushq $0x28
popq %rbp
testl %ebx, %ebx
je 0xac8c
leaq 0x14f10(%rip), %r13     # 0x1fa80
movq (%r13), %r15
cmpl $0x0, 0xf2e64(%r15)
je 0xabdb
leaq 0xf2e00(%r15), %rcx
addq $0x100, %r15            # imm = 0x100
leaq 0xabd9(%rip), %rsi      # 0x1576c
leaq 0x160(%rsp), %r12
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
movq %r12, %rdi
callq 0x20c0
movq %r12, %rdi
movq %rax, %rsi
callq 0xbd04
movq (%r13), %r15
movl 0xf2e44(%r15), %eax
movl 0xf2e58(%r15), %ecx
movl %ecx, 0xf2e68(%r15)
movl %eax, 0xf2e40(%r15)
leaq 0xf2e00(%r15), %r12
callq 0x2080
cltd
idivl %ebp
movslq %edx, %rax
imulq $0x78, %rax, %rax
leaq (%r15,%rax), %rsi
addq $0xf1b40, %rsi          # imm = 0xF1B40
pushq $0xf
popq %rcx
movq %r12, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq (%r13), %rsi
movl $0x1, 0xf2e64(%rsi)
movl 0x148(%rsi), %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
cmpq %rax, %rcx
je 0xac3c
andl $0x0, 0x280c(%rsi,%rax)
addq $0x26a8, %rax           # imm = 0x26A8
jmp 0xac27
movw $0x3a, 0x120(%rsp)
addq $0xf2e00, %rsi          # imm = 0xF2E00
pushq $0x1e
popq %rcx
leaq 0x38(%rsp), %rdi
rep  movsl (%rsi), %es:(%rdi)
xorl %r12d, %r12d
cmpl $0xe, %r14d
jg 0xaf26
callq 0x2080
pushq $0x5
popq %rcx
cltd
idivl %ecx
leaq 0x14e0a(%rip), %rax     # 0x1fa80
movq (%rax), %rsi
testl %ebx, %ebx
je 0xad41
movl %edx, 0xf2e70(%rsi)
jmp 0xad4f
movl %ebx, 0x10(%rsp)
movq %r15, %rdi
callq 0xc860
leaq 0x14de1(%rip), %rcx     # 0x1fa80
movq (%rcx), %rbx
movslq %eax, %r12
imulq $0x26a8, %r12, %r13     # imm = 0x26A8
cmpl $0x0, 0x12d0(%rbx,%r13)
jne 0xb163
leaq (%rbx,%r13), %rax
addq $0x126c, %rax           # imm = 0x126C
movq %rax, 0x8(%rsp)
callq 0x2080
cltd
idivl %ebp
movslq %edx, %rax
imulq $0x78, %rax, %rax
leaq (%rbx,%rax), %rsi
addq $0xf1b40, %rsi          # imm = 0xF1B40
pushq $0x1e
popq %rbp
movq %rbp, %rcx
movq 0x8(%rsp), %rdi
rep  movsl (%rsi), %es:(%rdi)
leaq 0x14d88(%rip), %rbx     # 0x1fa80
movq (%rbx), %rax
movl $0x1, 0x12d0(%rax,%r13)
leaq 0xaab4(%rip), %rsi      # 0x157c2
leaq 0x120(%rsp), %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
movq (%rbx), %rax
leaq (%rax,%r13), %rsi
addq $0x126c, %rsi           # imm = 0x126C
leaq 0x38(%rsp), %rdi
movq %rbp, %rcx
rep  movsl (%rsi), %es:(%rdi)
movl 0x10(%rsp), %ebx
jmp 0xac5a
imulq $0x26a8, %r12, %rax     # imm = 0x26A8
movl %edx, 0x12dc(%rsi,%rax)
cmpl $0x4, %edx
ja 0xae2e
movl %edx, %eax
leaq 0xa9df(%rip), %rcx      # 0x15740
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testl %ebx, %ebx
je 0xaecf
shll 0xf2e40(%rsi)
movdqu 0xf2e48(%rsi), %xmm0
paddd %xmm0, %xmm0
movdqu %xmm0, 0xf2e48(%rsi)
jmp 0xae36
testl %ebx, %ebx
je 0xae42
imull $0xa, 0xf2e40(%rsi), %eax
movl %eax, 0xf2e40(%rsi)
movdqu 0xf2e48(%rsi), %xmm0
movdqa 0xa97a(%rip), %xmm1     # 0x15730
pshufd $0xf5, %xmm0, %xmm2     # xmm2 = xmm0[1,1,3,3]
pmuludq %xmm1, %xmm0
pshufd $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3]
pmuludq %xmm1, %xmm2
pshufd $0xe8, %xmm2, %xmm1     # xmm1 = xmm2[0,2,2,3]
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movdqu %xmm0, 0xf2e48(%rsi)
imull $0x6, 0xf2e5c(%rsi), %eax
movl %eax, 0xf2e5c(%rsi)
imull $0x6, 0xf2e58(%rsi), %eax
jmp 0xae0f
testl %ebx, %ebx
je 0xaead
shll $0x2, 0xf2e48(%rsi)
jmp 0xae36
testl %ebx, %ebx
je 0xaebe
imull $0x5, 0xf2e58(%rsi), %eax
movl %eax, 0xf2e58(%rsi)
jmp 0xae36
testl %ebx, %ebx
je 0xaef5
imull $0x3, 0xf2e5c(%rsi), %eax
movl %eax, 0xf2e5c(%rsi)
jmp 0xae36
testl %ebx, %ebx
je 0xaf0b
addq $0xf2e00, %rsi          # imm = 0xF2E00
jmp 0xaf1c
imulq $0x26a8, %r12, %rax     # imm = 0x26A8
imull $0xa, 0x12ac(%rsi,%rax), %ecx
movl %ecx, 0x12ac(%rsi,%rax)
movdqu 0x12b4(%rsi,%rax), %xmm0
movdqa 0xa8c7(%rip), %xmm1     # 0x15730
pshufd $0xf5, %xmm0, %xmm2     # xmm2 = xmm0[1,1,3,3]
pmuludq %xmm1, %xmm0
pshufd $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3]
pmuludq %xmm1, %xmm2
pshufd $0xe8, %xmm2, %xmm1     # xmm1 = xmm2[0,2,2,3]
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movdqu %xmm0, 0x12b4(%rsi,%rax)
imull $0x6, 0x12c8(%rsi,%rax), %ecx
movl %ecx, 0x12c8(%rsi,%rax)
imull $0x6, 0x12c4(%rsi,%rax), %ecx
movl %ecx, 0x12c4(%rsi,%rax)
jmp 0xaf0b
imulq $0x26a8, %r12, %rax     # imm = 0x26A8
shll $0x2, 0x12b4(%rsi,%rax)
jmp 0xaf0b
imulq $0x26a8, %r12, %rax     # imm = 0x26A8
shll $0x2, 0x12c4(%rsi,%rax)
jmp 0xaf0b
imulq $0x26a8, %r12, %rax     # imm = 0x26A8
shll 0x12ac(%rsi,%rax)
movdqu 0x12b4(%rsi,%rax), %xmm0
paddd %xmm0, %xmm0
movdqu %xmm0, 0x12b4(%rsi,%rax)
jmp 0xaf0b
imulq $0x26a8, %r12, %rax     # imm = 0x26A8
imull $0x3, 0x12c8(%rsi,%rax), %ecx
movl %ecx, 0x12c8(%rsi,%rax)
imulq $0x26a8, %r12, %rax     # imm = 0x26A8
addq %rax, %rsi
addq $0x126c, %rsi           # imm = 0x126C
pushq $0x1e
popq %rcx
leaq 0x38(%rsp), %rdi
rep  movsl (%rsi), %es:(%rdi)
andq $0x0, 0x27(%rsp)
andq $0x0, 0x20(%rsp)
cmpl $0x59, 0x18(%rsp)
jg 0xaff1
callq 0x2080
pushq $0x3
popq %rcx
cltd
idivl %ecx
leaq 0x14b31(%rip), %rax     # 0x1fa80
movq (%rax), %rax
cmpl $0x1, %edx
je 0xaf8a
testl %edx, %edx
jne 0xafcf
imulq $0x26a8, %r12, %rcx     # imm = 0x26A8
leaq 0xf2e74(%rax), %rdx
testl %ebx, %ebx
leaq 0x12e0(%rax,%rcx), %rax
cmovneq %rdx, %rax
andl $0x0, (%rax)
leaq 0xa852(%rip), %rsi      # 0x157d3
leaq 0xa854(%rip), %rdx      # 0x157dc
jmp 0xafba
imulq $0x26a8, %r12, %rcx     # imm = 0x26A8
leaq 0xf2e74(%rax), %rdx
testl %ebx, %ebx
leaq 0x12e0(%rax,%rcx), %rax
cmovneq %rdx, %rax
movl $0x1, (%rax)
leaq 0xa82d(%rip), %rsi      # 0x157e0
leaq 0x5d76(%rip), %rdx      # 0x10d30
leaq 0x821c(%rip), %rcx      # 0x131dd
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x2050
jmp 0xaff1
testl %ebx, %ebx
je 0xafdf
movl $0x2, 0xf2e74(%rax)
jmp 0xaff1
imulq $0x26a8, %r12, %rcx     # imm = 0x26A8
movl $0x2, 0x12e0(%rax,%rcx)
leaq 0x14a88(%rip), %rax     # 0x1fa80
movl $0x100, %ebx            # imm = 0x100
addq (%rax), %rbx
movl 0x78(%rsp), %ebp
movl 0x7c(%rsp), %eax
movq %rax, 0x18(%rsp)
movl 0x84(%rsp), %eax
movq %rax, 0x10(%rsp)
movl 0x80(%rsp), %eax
movq %rax, 0x8(%rsp)
movl 0x88(%rsp), %eax
movq %rax, 0x30(%rsp)
movl 0x8c(%rsp), %r12d
movl 0xa8(%rsp), %eax
cmpq $0x5, %rax
ja 0xb0e4
leaq 0xa703(%rip), %rcx      # 0x15754
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xabd4(%rip), %rdx      # 0x15c35
leaq 0x5cc8(%rip), %rcx      # 0x10d30
leaq 0xabcd(%rip), %r8       # 0x15c3c
jmp 0xb0cb
leaq 0xabbd(%rip), %rdx      # 0x15c35
leaq 0xac12(%rip), %rcx      # 0x15c91
leaq 0xac0f(%rip), %r8       # 0x15c95
jmp 0xb0cb
leaq 0xaba6(%rip), %rdx      # 0x15c35
leaq 0xabd1(%rip), %rcx      # 0x15c67
leaq 0xabce(%rip), %r8       # 0x15c6b
jmp 0xb0cb
leaq 0xab8f(%rip), %rdx      # 0x15c35
leaq 0xabce(%rip), %rcx      # 0x15c7b
leaq 0xabcb(%rip), %r8       # 0x15c7f
jmp 0xb0cb
leaq 0xab78(%rip), %rdx      # 0x15c35
leaq 0x8111(%rip), %rcx      # 0x131d5
leaq 0xab86(%rip), %r8       # 0x15c51
leaq 0x810b(%rip), %r9       # 0x131dd
leaq 0xb0(%rsp), %rdi
pushq $0x64
popq %rsi
xorl %eax, %eax
callq 0x23a0
subq $0x8, %rsp
leaq 0x28(%rsp), %r13
leaq 0xb8(%rsp), %r15
leaq 0x80e1(%rip), %r11      # 0x131dd
leaq 0x5c2d(%rip), %r10      # 0x10d30
leaq 0xa6df(%rip), %rsi      # 0x157e9
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 0x50(%rsp)
pushq 0x30(%rsp)
pushq 0x40(%rsp)
pushq %r11
pushq %r10
pushq 0x60(%rsp)
callq 0x2050
addq $0x50, %rsp
movq %r14, %rdi
callq 0x20c0
movq %r14, %rdi
movq %rax, %rsi
callq 0xbd04
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, 0xb0(%rsp)
jmp 0xb0e4