// File: /workspace/github_c_makefile_star2_O3/Ziddykins[P]Dawn/src/inventory.c
// Function: equip_inventory
void equip_inventory(struct Message *message, int slot, int unequip, int all) {
    int i = get_pindex(message->sender_nick);
    char out[MAX_MESSAGE_BUFFER];

    if (all) {
        int count = 0;
        for (int j = 0; j < MAX_INVENTORY_SLOTS - dawn->players[i].available_slots; j++) {
            if (!unequip && !is_equipped(i, j)) {
                equip_toggle(i, j);
                acknowledge_new(i, j);
                count++;
            } else if (unequip && is_equipped(i, j)) {
                equip_toggle(i, j);
                count++;
            }
        }

        sprintf(out, "PRIVMSG %s :%s, %d pieces of equipment have been %s\r\n",
                message->receiver, message->sender_nick, count, unequip ? "unequipped" : "equipped");
        add_msg(out, strlen(out));
        return;
    }

    if (slot > MAX_INVENTORY_SLOTS) return;

    if (slot >= (MAX_INVENTORY_SLOTS - dawn->players[i].available_slots)) {
        sprintf(out, "PRIVMSG %s :There is nothing in slot %d\r\n", message->receiver, slot);
        add_msg(out, strlen(out));
        return;
    }

    if (unequip && is_equipped(i, slot)) {
        sprintf(out, "PRIVMSG %s :%s unequipped\r\n", message->receiver, dawn->players[i].inventory[slot].name);
        equip_toggle(i, slot);
        add_msg(out, strlen(out));
        return;
    } else if (unequip && !is_equipped(i, slot)) {
        sprintf(out, "PRIVMSG %s :%s is not equipped\r\n", message->receiver,
                dawn->players[i].inventory[slot].name);
        add_msg(out, strlen(out));
        return;
    }

    if (is_equippable(i, slot) && !is_equipped(i, slot)) {
        sprintf(out, "PRIVMSG %s :%s equipped\r\n", message->receiver, dawn->players[i].inventory[slot].name);
        equip_toggle(i, slot);
        acknowledge_new(i, slot);
    } else {
        sprintf(out, "PRIVMSG %s :%s is either unequippable or already equipped\r\n",
                message->receiver,
                dawn->players[i].inventory[slot].name);
    }
    add_msg(out, strlen(out));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x190, %rsp            # imm = 0x190
movl %ecx, %r15d
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
callq 0xda6c
testl %r15d, %r15d
je 0x7eba
leaq 0x19c92(%rip), %rcx     # 0x21a80
movq (%rcx), %rcx
cltq
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
movl 0x2818(%rcx,%rax), %edx
xorl %r8d, %r8d
cmpl $0x18, %edx
jg 0x7e65
movl $0x19, %esi
subl %edx, %esi
cmpl $0x2, %esi
movl $0x1, %edx
cmovgel %esi, %edx
addq %rcx, %rax
addq $0x3c8, %rax            # imm = 0x3C8
imulq $0x9c, %rdx, %rcx
xorl %edx, %edx
xorl %r8d, %r8d
movb (%rax,%rdx), %sil
testl %ebp, %ebp
je 0x7e44
testb $0x4, %sil
je 0x7e59
andb $-0x5, %sil
jmp 0x7e52
testb $0x4, %sil
jne 0x7e59
andb $-0x6, %sil
orb $0x4, %sil
movb %sil, (%rax,%rdx)
incl %r8d
addq $0x9c, %rdx
cmpq %rdx, %rcx
jne 0x7e30
leaq 0xc0(%rbx), %rdx
testl %ebp, %ebp
leaq 0xc3fd(%rip), %rax      # 0x14272
leaq 0xc3f4(%rip), %r9       # 0x14270
cmoveq %rax, %r9
leaq 0xc3b3(%rip), %rsi      # 0x1423a
movq %rsp, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2050
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x20c0
movq %rbx, %rdi
movq %rax, %rsi
callq 0xcefe
addq $0x190, %rsp            # imm = 0x190
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x19, %r14d
jg 0x7eaa
leaq 0x19bb9(%rip), %r12     # 0x21a80
movq (%r12), %rcx
cltq
imulq $0x26a8, %rax, %r15     # imm = 0x26A8
movl $0x19, %eax
subl 0x2818(%rcx,%r15), %eax
cmpl %r14d, %eax
jle 0x7f25
addq $0x1a0, %rcx            # imm = 0x1A0
movslq %r14d, %rax
addq %r15, %rcx
imulq $0x9c, %rax, %r14
addq $0xc0, %rbx
addq %r14, %rcx
addq $0x190, %rcx            # imm = 0x190
movb 0x98(%rcx), %al
testl %ebp, %ebp
je 0x7f48
testb $0x4, %al
jne 0x7f7f
leaq 0xc3a1(%rip), %rsi      # 0x142c1
jmp 0x7fac
addq $0xc0, %rbx
leaq 0xc348(%rip), %rsi      # 0x1427b
movq %rsp, %rdi
movq %rbx, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2050
jmp 0x7e94
andb $0xc, %al
cmpb $0x8, %al
jne 0x7fa5
leaq 0xc38d(%rip), %rsi      # 0x142e2
movq %rsp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
addq (%r12), %r15
movb 0x3c8(%r14,%r15), %al
andb $-0x2, %al
xorb $0x4, %al
movb %al, 0x3c8(%r14,%r15)
jmp 0x7e94
leaq 0xc31f(%rip), %rsi      # 0x142a5
movq %rsp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
addq (%r12), %r15
xorb $0x4, 0x3c8(%r14,%r15)
jmp 0x7e94
leaq 0xc350(%rip), %rsi      # 0x142fc
movq %rsp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
jmp 0x7e94
nop