// File: /workspace/github_c_makefile_star2_O2/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 0xc860
testl %r15d, %r15d
je 0x6ffa
leaq 0x18b41(%rip), %rcx     # 0x1fa80
movq (%rcx), %rcx
cltq
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
pushq $0x19
popq %rdx
addq %rcx, %rax
addq $0x3c8, %rax            # imm = 0x3C8
subl 0x2450(%rax), %edx
xorl %ecx, %ecx
testl %edx, %edx
cmovlel %ecx, %edx
imulq $0x9c, %rdx, %rdx
xorl %r8d, %r8d
cmpq %rcx, %rdx
je 0x6fa5
movb (%rax,%rcx), %sil
testl %ebp, %ebp
je 0x6f87
testb $0x4, %sil
je 0x6f9c
andb $-0x5, %sil
jmp 0x6f95
testb $0x4, %sil
jne 0x6f9c
andb $-0x6, %sil
orb $0x4, %sil
movb %sil, (%rax,%rcx)
incl %r8d
addq $0x9c, %rcx
jmp 0x6f6e
leaq 0xc0(%rbx), %rdx
testl %ebp, %ebp
leaq 0xc285(%rip), %rax      # 0x1323a
leaq 0xc27c(%rip), %r9       # 0x13238
cmoveq %rax, %r9
leaq 0xc23b(%rip), %rsi      # 0x13202
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 0xbd04
addq $0x190, %rsp            # imm = 0x190
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x19, %r14d
jg 0x6fea
leaq 0x18a79(%rip), %r12     # 0x1fa80
movq (%r12), %rcx
cltq
imulq $0x26a8, %rax, %r15     # imm = 0x26A8
pushq $0x19
popq %rax
subl 0x2818(%rcx,%r15), %eax
cmpl %r14d, %eax
jle 0x7063
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 0x7086
testb $0x4, %al
jne 0x70bd
leaq 0xc22b(%rip), %rsi      # 0x13289
jmp 0x70ea
addq $0xc0, %rbx
leaq 0xc1d2(%rip), %rsi      # 0x13243
movq %rsp, %rdi
movq %rbx, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2050
jmp 0x6fd4
andb $0xc, %al
cmpb $0x8, %al
jne 0x70e3
leaq 0xc217(%rip), %rsi      # 0x132aa
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 0x6fd4
leaq 0xc1a9(%rip), %rsi      # 0x1326d
movq %rsp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
addq (%r12), %r15
xorb $0x4, 0x3c8(%r14,%r15)
jmp 0x6fd4
leaq 0xc1da(%rip), %rsi      # 0x132c4
movq %rsp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
jmp 0x6fd4