// File: /workspace/github_c_makefile_star2_O3/Ziddykins[P]Dawn/src/items.c
// Function: drop_item
void drop_item(struct Message *message, int slot) {
    char out[MAX_MESSAGE_BUFFER];
    char item_name[128];
    int pindex = get_pindex(message->sender_nick);
    int total_items = MAX_INVENTORY_SLOTS - dawn->players[pindex].available_slots;
    static const struct Inventory empty;

    if (is_favorite(pindex, slot)) {
        sprintf(out, "PRIVMSG %s :%s, %s is a favorite item and can not be dropped\r\n",
                dawn->active_room, dawn->players[pindex].username, dawn->players[pindex].inventory[slot].name);
        add_msg(out, strlen(out));
        return;
    }

    item_name[0]   = '\0';
    strcpy(item_name, dawn->players[pindex].inventory[slot].name);

    if (total_items > 0 && slot < total_items && slot > -1) {
        int last_index = total_items - 1;
        if (slot == last_index) {
            dawn->players[pindex].inventory[slot] = empty;
        } else {
            for (int i=slot; i<last_index; i++) {
                dawn->players[pindex].inventory[i] = dawn->players[pindex].inventory[i + 1];
            }
            dawn->players[pindex].inventory[last_index] = empty;
        }
        dawn->players[pindex].available_slots++;
        sprintf(out, "PRIVMSG %s :%s has dropped the %s\r\n", message->receiver, message->sender_nick, item_name);
        add_msg(out, strlen(out));
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movl %esi, %ebp
movq %rdi, %rbx
callq 0xda6c
leaq 0x1927b(%rip), %r14     # 0x21a80
movq (%r14), %rcx
movslq %eax, %rdi
imulq $0x26a8, %rdi, %r15     # imm = 0x26A8
movl 0x2818(%rcx,%r15), %r12d
movl %ebp, %esi
callq 0x7b6d
testl %eax, %eax
je 0x8889
movq (%r14), %rax
leaq 0x100(%rax), %rdx
leaq (%rax,%r15), %rsi
leaq (%rax,%r15), %rcx
addq $0x1a0, %rcx            # imm = 0x1A0
movslq %ebp, %rax
imulq $0x9c, %rax, %rax
leaq (%rax,%rsi), %r8
addq $0x330, %r8             # imm = 0x330
leaq 0xbdc4(%rip), %rsi      # 0x1461e
leaq 0x80(%rsp), %rdi
xorl %eax, %eax
callq 0x2050
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
callq 0x20c0
movq %rbx, %rdi
movq %rax, %rsi
callq 0xcefe
jmp 0x898e
movq %rsp, %rdi
movb $0x0, (%rdi)
movq (%r14), %r13
leaq (%r15,%r13), %rax
movslq %ebp, %rcx
imulq $0x9c, %rcx, %rcx
leaq (%rcx,%rax), %r14
addq $0x330, %r14            # imm = 0x330
movq %r14, %rsi
callq 0x21c0
cmpl $0x18, %r12d
jg 0x898e
testl %ebp, %ebp
js 0x898e
movl $0x19, %eax
subl %r12d, %eax
cmpl %ebp, %eax
jle 0x898e
movq %r13, %rax
movl $0x18, %r13d
subl %r12d, %r13d
cmpl %ebp, %r13d
je 0x894c
jle 0x8931
movl %ebp, %eax
imulq $0x9c, %rax, %rax
leaq (%r15,%rax), %r14
addq $0x3cc, %r14            # imm = 0x3CC
leaq 0x1917d(%rip), %r12     # 0x21a80
movq (%r12), %rsi
leaq (%rsi,%r14), %rdi
addq $-0x9c, %rdi
addq %r14, %rsi
movl $0x9c, %edx
callq 0x2170
addq $0x9c, %r14
incl %ebp
cmpl %ebp, %r13d
jg 0x8903
movq (%r12), %rax
movq %rax, %rcx
addq %r15, %rcx
movl %r13d, %eax
imulq $0x9c, %rax, %rax
leaq (%rax,%rcx), %r14
addq $0x330, %r14            # imm = 0x330
movl $0x9c, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x20f0
leaq 0x1911e(%rip), %rax     # 0x21a80
movq (%rax), %rax
incl 0x2818(%rax,%r15)
leaq 0xc0(%rbx), %rdx
leaq 0xbce2(%rip), %rsi      # 0x1465d
leaq 0x80(%rsp), %rdi
movq %rsp, %r8
movq %rbx, %rcx
jmp 0x8862
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq