// File: /workspace/github_c_makefile_star2_O2/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 0xc860
movl %eax, %ebp
movq %r15, %rdi
callq 0xc860
leaq 0x122f1(%rip), %rcx     # 0x1fa80
movq (%rcx), %r14
cmpl $-0x1, %eax
je 0xd7f3
movslq %ebp, %rcx
imulq $0x26a8, %rcx, %rbp     # imm = 0x26A8
cmpl $0x0, 0x132c(%r14,%rbp)
je 0xd815
leaq 0x1a0(%r14), %r12
cltq
imulq $0x26a8, %rax, %r13     # imm = 0x26A8
cmpl $0x0, 0x2660(%r12,%r13)
je 0xd860
addq $0x100, %r14            # imm = 0x100
leaq 0x96ed(%rip), %rdx      # 0x16ec6
movq %rsp, %rdi
movl $0x190, %esi            # imm = 0x190
movq %r14, %rcx
movq %rbx, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x23a0
jmp 0xd838
addq $0x100, %r14            # imm = 0x100
leaq 0x9587(%rip), %rdx      # 0x16d88
movq %rsp, %rdi
movl $0x190, %esi            # imm = 0x190
movq %r14, %rcx
xorl %eax, %eax
callq 0x23a0
jmp 0xd838
addq $0x100, %r14            # imm = 0x100
leaq 0x9590(%rip), %rdx      # 0x16db3
movq %rsp, %rdi
movl $0x190, %esi            # imm = 0x190
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x23a0
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x20c0
movq %rbx, %rdi
movq %rax, %rsi
callq 0xbd04
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 0x22e0
testl %eax, %eax
je 0xd8bb
leaq (%r14,%rbp), %rax
addq $0x1a0, %rax            # imm = 0x1A0
imull $0x6, 0x1184(%rax), %edx
leal 0x1(%rdx), %r9d
movl 0x2680(%rax), %ecx
cmpl %edx, %ecx
jle 0xd8ce
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 0x9672(%rip), %rdx      # 0x16f28
jmp 0xd7d9
addq $0x100, %r14            # imm = 0x100
leaq 0x9623(%rip), %rdx      # 0x16eec
jmp 0xd823
addq $0x100, %r14            # imm = 0x100
leaq 0x967b(%rip), %rdx      # 0x16f57
movq %rsp, %rdi
movl $0x190, %esi            # imm = 0x190
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x23a0
jmp 0xd838