// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/spells.c
// Function: cast_heal
void cast_heal(const char *username, const char *target) {
    int pindex = get_pindex(username);
    int tindex = get_pindex(target);
    int stats[7] = {0};
    struct Message temp = {0};
    char out[MAX_MESSAGE_BUFFER];
    strncpy(temp.sender_nick, target, MAX_NICK_LENGTH);

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

    get_stat(&temp, stats);
    printf("%s stat0: %d\n", temp.sender_nick, stats[0]);

    if (!dawn->players[pindex].spellbook.heal.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, your magic powers are not yet strong enough "
                "to revive the dead\r\n", dawn->active_room, username);
        add_msg(out, strlen(out));
        return;
    }

    if (dawn->players[tindex].health == dawn->players[tindex].max_health+stats[0]) {
        snprintf(out, MAX_MESSAGE_BUFFER, "PRIVMSG %s :%s is already at full health\r\n",
                 dawn->active_room, target);
        add_msg(out, strlen(out));
        return;
    }

    int heal_cost = 1 + dawn->players[pindex].spellbook.heal.level * 5;
    int heal_amount = 10 + rand() % (dawn->players[pindex].level * 3);

    if (dawn->players[pindex].mana >= heal_cost) {
        dawn->players[tindex].health += heal_amount;
        if (dawn->players[tindex].health >= dawn->players[tindex].max_health + stats[0])
            dawn->players[tindex].health = dawn->players[tindex].max_health + stats[0];
        sprintf(out, "PRIVMSG %s :%s has healed %s for %d HP!\r\n", dawn->active_room, username, target, heal_amount);
    } else {
        sprintf(out, "PRIVMSG %s :%s, you don't have enough mana to cast this spell\r\n", dawn->active_room, username);
    }

    add_msg(out, strlen(out));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb00, %rsp            # imm = 0xB00
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)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x20f0
leaq -0x940(%rbp), %rdi
xorl %esi, %esi
movl $0x900, %edx            # imm = 0x900
callq 0x20f0
leaq -0x940(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq 0x10fbc(%rip), %rax     # 0x2625c
movl (%rax), %eax
movl %eax, %edx
callq 0x20e0
cmpl $-0x1, -0x18(%rbp)
jne 0x15308
leaq -0xad0(%rbp), %rdi
leaq 0x137b3(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0x100, %rcx            # imm = 0x100
movl $0x190, %esi            # imm = 0x190
leaq 0xba9d(%rip), %rdx      # 0x20d70
movb $0x0, %al
callq 0x2390
leaq -0xad0(%rbp), %rax
movq %rax, -0xae0(%rbp)
leaq -0xad0(%rbp), %rdi
callq 0x20c0
movq -0xae0(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x156e1
leaq -0x40(%rbp), %rsi
leaq -0x940(%rbp), %rdi
callq 0x16700
leaq -0x940(%rbp), %rsi
movl -0x40(%rbp), %edx
leaq 0xba64(%rip), %rdi      # 0x20d8d
movb $0x0, %al
callq 0x2040
leaq 0x13739(%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, 0x1158(%rax)
jne 0x153b4
leaq -0xad0(%rbp), %rdi
leaq 0x1370b(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0x100, %rcx            # imm = 0x100
movq -0x8(%rbp), %r8
movl $0x190, %esi            # imm = 0x190
leaq 0xba1c(%rip), %rdx      # 0x20d9b
movb $0x0, %al
callq 0x2390
leaq -0xad0(%rbp), %rax
movq %rax, -0xae8(%rbp)
leaq -0xad0(%rbp), %rdi
callq 0x20c0
movq -0xae8(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x156e1
leaq 0x136b5(%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 0x15439
leaq -0xad0(%rbp), %rdi
leaq 0x13686(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0x100, %rcx            # imm = 0x100
movq -0x8(%rbp), %r8
movl $0x190, %esi            # imm = 0x190
leaq 0xb9c4(%rip), %rdx      # 0x20dc8
movb $0x0, %al
callq 0x2390
leaq -0xad0(%rbp), %rax
movq %rax, -0xaf0(%rbp)
leaq -0xad0(%rbp), %rdi
callq 0x20c0
movq -0xaf0(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x156e1
leaq 0x13630(%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), %rax
leaq 0x1360b(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
addq $0x1a0, %rcx            # imm = 0x1A0
movslq -0x18(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rcx
movl 0x2670(%rcx), %ecx
addl -0x40(%rbp), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0x154eb
leaq -0xad0(%rbp), %rdi
leaq 0x135d4(%rip), %rax     # 0x28a70
movq (%rax), %rcx
addq $0x100, %rcx            # imm = 0x100
movq -0x10(%rbp), %r8
movl $0x190, %esi            # imm = 0x190
leaq 0xb963(%rip), %rdx      # 0x20e19
movb $0x0, %al
callq 0x2390
leaq -0xad0(%rbp), %rax
movq %rax, -0xaf8(%rbp)
leaq -0xad0(%rbp), %rdi
callq 0x20c0
movq -0xaf8(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x156e1
leaq 0x1357e(%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 $0x5, 0x1150(%rax), %eax
addl $0x1, %eax
movl %eax, -0xad4(%rbp)
callq 0x2080
leaq 0x1354b(%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 $0x3, 0x2668(%rcx), %ecx
cltd
idivl %ecx
addl $0xa, %edx
movl %edx, -0xad8(%rbp)
leaq 0x13519(%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 -0xad4(%rbp), %eax
jl 0x1568e
movslq -0xad8(%rbp), %rcx
leaq 0x134e2(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x18(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rax
addq 0x2650(%rax), %rcx
movq %rcx, 0x2650(%rax)
leaq 0x134b6(%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), %rax
leaq 0x13491(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
addq $0x1a0, %rcx            # imm = 0x1A0
movslq -0x18(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rcx
movl 0x2670(%rcx), %ecx
addl -0x40(%rbp), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jl 0x15657
leaq 0x13461(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x18(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl 0x2670(%rax), %eax
addl -0x40(%rbp), %eax
movslq %eax, %rcx
leaq 0x13437(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x18(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rax
movq %rcx, 0x2650(%rax)
leaq -0xad0(%rbp), %rdi
leaq 0x1340b(%rip), %rax     # 0x28a70
movq (%rax), %rdx
addq $0x100, %rdx            # imm = 0x100
movq -0x8(%rbp), %rcx
movq -0x10(%rbp), %r8
movl -0xad8(%rbp), %r9d
leaq 0xb7bf(%rip), %rsi      # 0x20e44
movb $0x0, %al
callq 0x2050
jmp 0x156b8
leaq -0xad0(%rbp), %rdi
leaq 0x133d4(%rip), %rax     # 0x28a70
movq (%rax), %rdx
addq $0x100, %rdx            # imm = 0x100
movq -0x8(%rbp), %rcx
leaq 0xb7bd(%rip), %rsi      # 0x20e6e
movb $0x0, %al
callq 0x2050
leaq -0xad0(%rbp), %rax
movq %rax, -0xb00(%rbp)
leaq -0xad0(%rbp), %rdi
callq 0x20c0
movq -0xb00(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
addq $0xb00, %rsp            # imm = 0xB00
popq %rbp
retq
nopw (%rax,%rax)