// File: /workspace/github_c_makefile_star2_O3/Ziddykins[P]Dawn/src/spells.c
// Function: cast_revive
void cast_revive(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.revive.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].alive) {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s, %s is already alive\r\n",
                dawn->active_room, username, target);
        add_msg(out, strlen(out));
        return;
    }

    if (strcmp(username, target) == 0) {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s, you can't revive yourself... You're dead.\r\n",
                dawn->active_room, username);
        add_msg(out, strlen(out));
        return;
    }

    int revive_cost = 1 + dawn->players[pindex].spellbook.revive.level * 6;

    if (dawn->players[pindex].mana >= revive_cost) {
        dawn->players[pindex].mana -= revive_cost;
        dawn->players[tindex].alive = 1;
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s has revived %s from the dead!\r\n",
                dawn->active_room, username, target);
        add_msg(out, strlen(out));
    } else {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s, you do not have the required %d mana to cast this spell\r\n",
                dawn->active_room, username, revive_cost);
        add_msg(out, strlen(out));
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rsi, %r15
movq %rdi, %rbx
callq 0xda6c
movl %eax, %ebp
movq %r15, %rdi
callq 0xda6c
leaq 0x13033(%rip), %rcx     # 0x21a80
movq (%rcx), %r14
cmpl $-0x1, %eax
je 0xeab1
movslq %ebp, %rcx
imulq $0x26a8, %rcx, %rbp     # imm = 0x26A8
cmpl $0x0, 0x132c(%r14,%rbp)
je 0xead3
leaq 0x1a0(%r14), %r12
cltq
imulq $0x26a8, %rax, %r13     # imm = 0x26A8
cmpl $0x0, 0x2660(%r12,%r13)
je 0xeb1e
addq $0x100, %r14            # imm = 0x100
leaq 0x945f(%rip), %rdx      # 0x17ef6
movq %rsp, %rdi
movl $0x190, %esi            # imm = 0x190
movq %r14, %rcx
movq %rbx, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x2390
jmp 0xeaf6
addq $0x100, %r14            # imm = 0x100
leaq 0x92f9(%rip), %rdx      # 0x17db8
movq %rsp, %rdi
movl $0x190, %esi            # imm = 0x190
movq %r14, %rcx
xorl %eax, %eax
callq 0x2390
jmp 0xeaf6
addq $0x100, %r14            # imm = 0x100
leaq 0x9302(%rip), %rdx      # 0x17de3
movq %rsp, %rdi
movl $0x190, %esi            # imm = 0x190
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x2390
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x20c0
movq %rbx, %rdi
movq %rax, %rsi
callq 0xcefe
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r15, %rsi
callq 0x22d0
testl %eax, %eax
je 0xeb80
leaq (%r14,%rbp), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movl 0x1184(%rax), %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,2), %edx
leal (%rcx,%rcx,2), %r9d
incl %r9d
movl 0x2680(%rax), %ecx
cmpl %edx, %ecx
jle 0xeb93
leaq (%r12,%r13), %rdx
addq $0x2660, %rdx           # imm = 0x2660
subl %r9d, %ecx
movl %ecx, 0x2680(%rax)
movl $0x1, (%rdx)
addq $0x100, %r14            # imm = 0x100
leaq 0x93dd(%rip), %rdx      # 0x17f58
jmp 0xea97
addq $0x100, %r14            # imm = 0x100
leaq 0x938e(%rip), %rdx      # 0x17f1c
jmp 0xeae1
addq $0x100, %r14            # imm = 0x100
leaq 0x93e6(%rip), %rdx      # 0x17f87
movq %rsp, %rdi
movl $0x190, %esi            # imm = 0x190
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x2390
jmp 0xeaf6