// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/spells.c
// Function: cast_fireball
void cast_fireball(const char *username, const char *target) {
    int pindex = get_pindex(username);
    int tindex = get_pindex(target);
    char out[MAX_MESSAGE_BUFFER];

    if (tindex == -1) {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :Invalid target\r\n", dawn->active_room);
        add_msg(out, strlen(out));
        return;
    }

    if (!dawn->players[pindex].spellbook.fireball.learned) {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s, you do not know this spell\r\n",
                 dawn->active_room, username);
        add_msg(out, strlen(out));
        return;
    }

    if (dawn->players[tindex].health <= 0) {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s, %s is dead\r\n",
                 dawn->active_room, username, target);
        add_msg(out, strlen(out));
        return;
    }

    if (dawn->players[pindex].level >= dawn->players[tindex].level * 3) {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s, pick on someone your own size!\r\n",
                 dawn->active_room, username);
        add_msg(out, strlen(out));
        return;
    }

    if (strcmp(username, target) == 0) {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s whips a fireball at a mirror; it bounces back"
                ", hitting themselves for 1 point of damage. Well done.\r\n", dawn->active_room, username);
        dawn->players[pindex].health--;
        add_msg(out, strlen(out));
        return;
    }

    int fireball_cost = 1 + dawn->players[pindex].spellbook.fireball.level * 7;
    int fireball_damage =
            1 + rand() % dawn->players[pindex].intelligence * dawn->players[pindex].spellbook.fireball.level;

    if (dawn->players[pindex].mana >= fireball_cost) {
        int target_save = 1 + rand() % dawn->players[tindex].m_def;
        char result[128];
        dawn->players[pindex].mana -= fireball_cost;
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s hurls a fireball at %s! ",
                 dawn->active_room, username, target);
        if (target_save == fireball_damage) {
            snprintf(result, 128, "%s's shields had just enough energy to absorb the entire fireball!\r\n", target);
        } else if (target_save < fireball_damage) {
            struct Message tmpmsg;
            strcpy(tmpmsg.sender_nick, target);
            strcpy(tmpmsg.receiver, dawn->active_room);
            snprintf(result, 128, "%s is hit for %d damage!\r\n", target, fireball_damage - target_save);
            dawn->players[tindex].health -= fireball_damage - target_save;
            check_alive(&tmpmsg);
        } else if (target_save > fireball_damage) {
            snprintf(result, 128, "%s swats the fireball out of the sky with ease\r\n", target);
        }
        strncat(out, result, MAX_MESSAGE_BUFFER - strlen(result));
    }
    add_msg(out, strlen(out));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb80, %rsp            # imm = 0xB80
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x13ba0
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x13ba0
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x15b0a
leaq -0x1b0(%rbp), %rdi
leaq 0x12fb1(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0x100, %rcx            # imm = 0x100
movl $0x190, %esi            # imm = 0x190
leaq 0xb29b(%rip), %rdx      # 0x20d70
movb $0x0, %al
callq 0x2390
leaq -0x1b0(%rbp), %rax
movq %rax, -0xb48(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x20c0
movq -0xb48(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x16043
leaq 0x12f5f(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x14(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
cmpl $0x0, 0x1180(%rax)
jne 0x15b8e
leaq -0x1b0(%rbp), %rdi
leaq 0x12f31(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0x100, %rcx            # imm = 0x100
movq -0x8(%rbp), %r8
movl $0x190, %esi            # imm = 0x190
leaq 0xb242(%rip), %rdx      # 0x20d9b
movb $0x0, %al
callq 0x2390
leaq -0x1b0(%rbp), %rax
movq %rax, -0xb50(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x20c0
movq -0xb50(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x16043
leaq 0x12edb(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x18(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
cmpq $0x0, 0x2650(%rax)
jg 0x15c17
leaq -0x1b0(%rbp), %rdi
leaq 0x12eac(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0x100, %rcx            # imm = 0x100
movq -0x8(%rbp), %r8
movq -0x10(%rbp), %r9
movl $0x190, %esi            # imm = 0x190
leaq 0xb3a7(%rip), %rdx      # 0x20f89
movb $0x0, %al
callq 0x2390
leaq -0x1b0(%rbp), %rax
movq %rax, -0xb58(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x20c0
movq -0xb58(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x16043
leaq 0x12e52(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x14(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl 0x2668(%rax), %eax
leaq 0x12e2e(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
addq $0x1a0, %rcx            # imm = 0x1A0
movslq -0x18(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rcx
imull $0x3, 0x2668(%rcx), %ecx
cmpl %ecx, %eax
jl 0x15cc2
leaq -0x1b0(%rbp), %rdi
leaq 0x12dfd(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0x100, %rcx            # imm = 0x100
movq -0x8(%rbp), %r8
movl $0x190, %esi            # imm = 0x190
leaq 0xb319(%rip), %rdx      # 0x20fa6
movb $0x0, %al
callq 0x2390
leaq -0x1b0(%rbp), %rax
movq %rax, -0xb60(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x20c0
movq -0xb60(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x16043
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x22d0
cmpl $0x0, %eax
jne 0x15d65
leaq -0x1b0(%rbp), %rdi
leaq 0x12d8a(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0x100, %rcx            # imm = 0x100
movq -0x8(%rbp), %r8
movl $0x190, %esi            # imm = 0x190
leaq 0xb2d7(%rip), %rdx      # 0x20fd7
movb $0x0, %al
callq 0x2390
leaq 0x12d62(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x14(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movq 0x2650(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x2650(%rax)
leaq -0x1b0(%rbp), %rax
movq %rax, -0xb68(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x20c0
movq -0xb68(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x16043
leaq 0x12d04(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x14(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
imull $0x7, 0x1178(%rax), %eax
addl $0x1, %eax
movl %eax, -0x1b4(%rbp)
callq 0x2080
leaq 0x12cd1(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
addq $0x1a0, %rcx            # imm = 0x1A0
movslq -0x14(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rcx
cltd
idivl 0x2688(%rcx)
movl %edx, %eax
leaq 0x12ca9(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
addq $0x1a0, %rcx            # imm = 0x1A0
movslq -0x14(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rcx
imull 0x1178(%rcx), %eax
addl $0x1, %eax
movl %eax, -0x1b8(%rbp)
leaq 0x12c7a(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x14(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl 0x2680(%rax), %eax
cmpl -0x1b4(%rbp), %eax
jl 0x1601a
callq 0x2080
leaq 0x12c45(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
addq $0x1a0, %rcx            # imm = 0x1A0
movslq -0x18(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rcx
cltd
idivl 0x2690(%rcx)
addl $0x1, %edx
movl %edx, -0x1bc(%rbp)
movl -0x1b4(%rbp), %edx
leaq 0x12c10(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x14(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl 0x2680(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x2680(%rax)
leaq -0x1b0(%rbp), %rdi
leaq 0x12bdd(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0x100, %rcx            # imm = 0x100
movq -0x8(%rbp), %r8
movq -0x10(%rbp), %r9
movl $0x190, %esi            # imm = 0x190
leaq 0xb19b(%rip), %rdx      # 0x2104c
movb $0x0, %al
callq 0x2390
movl -0x1bc(%rbp), %eax
cmpl -0x1b8(%rbp), %eax
jne 0x15ee9
leaq -0x240(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x80, %esi
leaq 0xb197(%rip), %rdx      # 0x21074
movb $0x0, %al
callq 0x2390
jmp 0x15fd7
movl -0x1bc(%rbp), %eax
cmpl -0x1b8(%rbp), %eax
jge 0x15fa7
leaq -0xb40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21c0
leaq -0xb40(%rbp), %rdi
addq $0xc0, %rdi
leaq 0x12b50(%rip), %rax     # 0x28a70
movq (%rax), %rsi
addq $0x100, %rsi            # imm = 0x100
callq 0x21c0
leaq -0x240(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl -0x1b8(%rbp), %r8d
subl -0x1bc(%rbp), %r8d
movl $0x80, %esi
leaq 0xb165(%rip), %rdx      # 0x210b9
movb $0x0, %al
callq 0x2390
movl -0x1b8(%rbp), %eax
subl -0x1bc(%rbp), %eax
movslq %eax, %rdx
leaq 0x12aff(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x18(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movq 0x2650(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x2650(%rax)
leaq -0xb40(%rbp), %rdi
callq 0x4590
jmp 0x15fd5
movl -0x1bc(%rbp), %eax
cmpl -0x1b8(%rbp), %eax
jle 0x15fd3
leaq -0x240(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x80, %esi
leaq 0xb108(%rip), %rdx      # 0x210d4
movb $0x0, %al
callq 0x2390
jmp 0x15fd5
jmp 0x15fd7
leaq -0x1b0(%rbp), %rax
movq %rax, -0xb78(%rbp)
leaq -0x240(%rbp), %rax
movq %rax, -0xb70(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x20c0
movq -0xb78(%rbp), %rdi
movq -0xb70(%rbp), %rsi
movl $0x190, %edx            # imm = 0x190
subq %rax, %rdx
callq 0x2120
leaq -0x1b0(%rbp), %rax
movq %rax, -0xb80(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x20c0
movq -0xb80(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
addq $0xb80, %rsp            # imm = 0xB80
popq %rbp
retq
nopl (%rax)