// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3a8, %rsp            # imm = 0x3A8
movq %rdi, -0x30(%rbp)
movl %esi, -0x34(%rbp)
movl $0x0, -0x288(%rbp)
movl $0x0, -0x284(%rbp)
callq 0x2080
movl $0x64, %ecx
cltd
idivl %ecx
movl %edx, -0x290(%rbp)
callq 0x2080
movl $0x64, %ecx
cltd
idivl %ecx
movl %edx, -0x28c(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x1097d
leaq 0x1828a(%rip), %rax     # 0x28a70
movq (%rax), %rax
cmpl $0x0, 0xf2e64(%rax)
je 0x10896
leaq -0x1d0(%rbp), %rdi
leaq 0x1826c(%rip), %rax     # 0x28a70
movq (%rax), %rdx
addq $0x100, %rdx            # imm = 0x100
leaq 0x1825b(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0xf2e00, %rcx          # imm = 0xF2E00
leaq 0xef68(%rip), %rsi      # 0x1f78e
movb $0x0, %al
callq 0x2050
leaq -0x1d0(%rbp), %rax
movq %rax, -0x328(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x20c0
movq -0x328(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
leaq 0x18213(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl 0xf2e58(%rax), %ecx
leaq 0x18203(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl %ecx, 0xf2e68(%rax)
leaq 0x181f3(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl 0xf2e44(%rax), %ecx
leaq 0x181e3(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl %ecx, 0xf2e40(%rax)
leaq 0x181d3(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0xf2e00, %rax          # imm = 0xF2E00
movq %rax, -0x330(%rbp)
leaq 0x181bc(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0xf1b40, %rax          # imm = 0xF1B40
movq %rax, -0x338(%rbp)
callq 0x2080
movq -0x338(%rbp), %rsi
movq -0x330(%rbp), %rdi
movl $0x28, %ecx
cltd
idivl %ecx
movslq %edx, %rax
imulq $0x78, %rax, %rax
addq %rax, %rsi
movl $0x78, %edx
callq 0x2170
leaq 0x18176(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl $0x1, 0xf2e64(%rax)
movl $0x0, -0x284(%rbp)
movl -0x284(%rbp), %eax
leaq 0x18152(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
cmpl 0x148(%rcx), %eax
jge 0x10965
leaq 0x18140(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x284(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl $0x0, 0x266c(%rax)
movl -0x284(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x284(%rbp)
jmp 0x10911
leaq -0x280(%rbp), %rdi
leaq 0xaf6e(%rip), %rsi      # 0x1b8e1
callq 0x21c0
jmp 0x10a73
movq -0x30(%rbp), %rdi
callq 0x13ba0
movl %eax, -0x288(%rbp)
leaq 0x180dd(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x288(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
cmpl $0x0, 0x1130(%rax)
je 0x109bb
jmp 0x10e69
leaq 0x180ae(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x288(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
addq $0x10cc, %rax           # imm = 0x10CC
movq %rax, -0x340(%rbp)
leaq 0x18080(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0xf1b40, %rax          # imm = 0xF1B40
movq %rax, -0x348(%rbp)
callq 0x2080
movq -0x348(%rbp), %rsi
movq -0x340(%rbp), %rdi
movl $0x28, %ecx
cltd
idivl %ecx
movslq %edx, %rax
imulq $0x78, %rax, %rax
addq %rax, %rsi
movl $0x78, %edx
callq 0x2170
leaq 0x1803a(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x288(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl $0x1, 0x1130(%rax)
leaq -0x280(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0xed78(%rip), %rsi      # 0x1f7e4
movb $0x0, %al
callq 0x2050
cmpl $0x0, -0x34(%rbp)
je 0x10a9d
leaq 0x17ff0(%rip), %rax     # 0x28a70
movq (%rax), %rsi
addq $0xf2e00, %rsi          # imm = 0xF2E00
leaq -0x308(%rbp), %rdi
movl $0x78, %edx
callq 0x2170
jmp 0x10ad7
leaq 0x17fcc(%rip), %rax     # 0x28a70
movq (%rax), %rsi
addq $0x1a0, %rsi            # imm = 0x1A0
movslq -0x288(%rbp), %rax
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
addq %rax, %rsi
addq $0x10cc, %rsi           # imm = 0x10CC
leaq -0x308(%rbp), %rdi
movl $0x78, %edx
callq 0x2170
cmpl $0xf, -0x28c(%rbp)
jge 0x10bbc
callq 0x2080
movl $0x5, %ecx
cltd
idivl %ecx
movl %edx, -0x30c(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x10b15
movl -0x30c(%rbp), %ecx
leaq 0x17f66(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl %ecx, 0xf2e70(%rax)
jmp 0x10b42
movl -0x30c(%rbp), %ecx
leaq 0x17f4e(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x288(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rax
movl %ecx, 0x113c(%rax)
movl -0x30c(%rbp), %edi
movl -0x288(%rbp), %esi
movl -0x34(%rbp), %edx
callq 0x10e80
cmpl $0x0, -0x34(%rbp)
je 0x10b80
leaq 0x17f0d(%rip), %rax     # 0x28a70
movq (%rax), %rsi
addq $0xf2e00, %rsi          # imm = 0xF2E00
leaq -0x308(%rbp), %rdi
movl $0x78, %edx
callq 0x2170
jmp 0x10bba
leaq 0x17ee9(%rip), %rax     # 0x28a70
movq (%rax), %rsi
addq $0x1a0, %rsi            # imm = 0x1A0
movslq -0x288(%rbp), %rax
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
addq %rax, %rsi
addq $0x10cc, %rsi           # imm = 0x10CC
leaq -0x308(%rbp), %rdi
movl $0x78, %edx
callq 0x2170
jmp 0x10bbc
leaq -0x31b(%rbp), %rdi
xorl %esi, %esi
movl $0xf, %edx
callq 0x20f0
cmpl $0x5a, -0x290(%rbp)
jge 0x10d27
callq 0x2080
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, -0x320(%rbp)
cmpl $0x0, -0x320(%rbp)
jne 0x10c67
cmpl $0x0, -0x34(%rbp)
je 0x10c14
leaq 0x17e6b(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl $0x0, 0xf2e74(%rax)
jmp 0x10c3f
leaq 0x17e55(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x288(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl $0x0, 0x1140(%rax)
leaq -0x31b(%rbp), %rdi
leaq 0xeba8(%rip), %rsi      # 0x1f7f5
leaq 0xebaa(%rip), %rdx      # 0x1f7fe
leaq 0xc58a(%rip), %rcx      # 0x1d1e5
movb $0x0, %al
callq 0x2050
jmp 0x10d25
cmpl $0x1, -0x320(%rbp)
jne 0x10cdc
cmpl $0x0, -0x34(%rbp)
je 0x10c8c
leaq 0x17df3(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl $0x1, 0xf2e74(%rax)
jmp 0x10cb7
leaq 0x17ddd(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x288(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl $0x1, 0x1140(%rax)
leaq -0x31b(%rbp), %rdi
leaq 0xeb3d(%rip), %rsi      # 0x1f802
leaq 0xa064(%rip), %rdx      # 0x1ad30
leaq 0xc512(%rip), %rcx      # 0x1d1e5
movb $0x0, %al
callq 0x2050
jmp 0x10d23
cmpl $0x0, -0x34(%rbp)
je 0x10cf8
leaq 0x17d87(%rip), %rax     # 0x28a70
movq (%rax), %rax
movl $0x2, 0xf2e74(%rax)
jmp 0x10d23
leaq 0x17d71(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x288(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl $0x2, 0x1140(%rax)
jmp 0x10d25
jmp 0x10d27
leaq -0x1d0(%rbp), %rax
movq %rax, -0x388(%rbp)
leaq 0x17d34(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x100, %rax            # imm = 0x100
movq %rax, -0x380(%rbp)
leaq -0x280(%rbp), %rax
movq %rax, -0x378(%rbp)
leaq -0x308(%rbp), %rax
movq %rax, -0x370(%rbp)
movl -0x2c8(%rbp), %eax
movl %eax, -0x364(%rbp)
movl -0x2c4(%rbp), %eax
movl %eax, -0x35c(%rbp)
movl -0x2bc(%rbp), %r15d
movl -0x2c0(%rbp), %r14d
movl -0x2b8(%rbp), %ebx
movl -0x2b4(%rbp), %eax
movl %eax, -0x360(%rbp)
movl -0x298(%rbp), %edi
leaq -0x240(%rbp), %rsi
callq 0x11340
movq -0x388(%rbp), %rdi
movq -0x380(%rbp), %rdx
movq -0x378(%rbp), %rcx
movq -0x370(%rbp), %r8
movl -0x364(%rbp), %r9d
movl -0x360(%rbp), %r11d
movq %rax, %r10
movl -0x35c(%rbp), %eax
leaq -0x31b(%rbp), %rsi
movq %rsi, -0x358(%rbp)
leaq 0xea11(%rip), %rsi      # 0x1f80b
leaq 0x9f2f(%rip), %r13      # 0x1ad30
leaq 0xc3dd(%rip), %r12      # 0x1d1e5
movl %eax, (%rsp)
movq -0x358(%rbp), %rax
movq %r13, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movl %r15d, 0x18(%rsp)
movl %r14d, 0x20(%rsp)
movl %ebx, 0x28(%rsp)
movl %r11d, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movb $0x0, %al
callq 0x2050
leaq -0x1d0(%rbp), %rax
movq %rax, -0x350(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x20c0
movq -0x350(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
addq $0x3a8, %rsp            # imm = 0x3A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)