// File: /workspace/github_c_makefile_star2_O1/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 0xd89c
testl %r15d, %r15d
je 0x7e4c
leaq 0x19d00(%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 0x7df7
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 0x7dd6
testb $0x4, %sil
je 0x7deb
andb $-0x5, %sil
jmp 0x7de4
testb $0x4, %sil
jne 0x7deb
andb $-0x6, %sil
orb $0x4, %sil
movb %sil, (%rax,%rdx)
incl %r8d
addq $0x9c, %rdx
cmpq %rdx, %rcx
jne 0x7dc2
leaq 0xc0(%rbx), %rdx
testl %ebp, %ebp
leaq 0xc433(%rip), %rax      # 0x1423a
leaq 0xc42a(%rip), %r9       # 0x14238
cmoveq %rax, %r9
leaq 0xc3e9(%rip), %rsi      # 0x14202
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 0xcd1c
addq $0x190, %rsp            # imm = 0x190
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x19, %r14d
jg 0x7e3c
leaq 0x19c27(%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 0x7eb7
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 0x7eda
testb $0x4, %al
jne 0x7f11
leaq 0xc3d7(%rip), %rsi      # 0x14289
jmp 0x7f3e
addq $0xc0, %rbx
leaq 0xc37e(%rip), %rsi      # 0x14243
movq %rsp, %rdi
movq %rbx, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2050
jmp 0x7e26
andb $0xc, %al
cmpb $0x8, %al
jne 0x7f37
leaq 0xc3c3(%rip), %rsi      # 0x142aa
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 0x7e26
leaq 0xc355(%rip), %rsi      # 0x1426d
movq %rsp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
addq (%r12), %r15
xorb $0x4, 0x3c8(%r14,%r15)
jmp 0x7e26
leaq 0xc386(%rip), %rsi      # 0x142c4
movq %rsp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
jmp 0x7e26