// File: /workspace/github_c_makefile_star2_O1/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 0xd89c
movl %eax, %ebp
movq %r15, %rdi
callq 0xd89c
leaq 0x13313(%rip), %rcx     # 0x21a80
movq (%rcx), %r14
cmpl $-0x1, %eax
je 0xe7d1
movslq %ebp, %rcx
imulq $0x26a8, %rcx, %rbp     # imm = 0x26A8
cmpl $0x0, 0x132c(%r14,%rbp)
je 0xe7f3
leaq 0x1a0(%r14), %r12
cltq
imulq $0x26a8, %rax, %r13     # imm = 0x26A8
cmpl $0x0, 0x2660(%r12,%r13)
je 0xe83e
addq $0x100, %r14            # imm = 0x100
leaq 0x96df(%rip), %rdx      # 0x17e96
movq %rsp, %rdi
movl $0x190, %esi            # imm = 0x190
movq %r14, %rcx
movq %rbx, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x2390
jmp 0xe816
addq $0x100, %r14            # imm = 0x100
leaq 0x9579(%rip), %rdx      # 0x17d58
movq %rsp, %rdi
movl $0x190, %esi            # imm = 0x190
movq %r14, %rcx
xorl %eax, %eax
callq 0x2390
jmp 0xe816
addq $0x100, %r14            # imm = 0x100
leaq 0x9582(%rip), %rdx      # 0x17d83
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 0xcd1c
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 0xe8a0
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 0xe8b3
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 0x965d(%rip), %rdx      # 0x17ef8
jmp 0xe7b7
addq $0x100, %r14            # imm = 0x100
leaq 0x960e(%rip), %rdx      # 0x17ebc
jmp 0xe801
addq $0x100, %r14            # imm = 0x100
leaq 0x9666(%rip), %rdx      # 0x17f27
movq %rsp, %rdi
movl $0x190, %esi            # imm = 0x190
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x2390
jmp 0xe816