// File: /workspace/github_c_makefile_star2_O1/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 0xd89c
leaq 0x1930c(%rip), %r12     # 0x21a80
movq (%r12), %rcx
movslq %eax, %rdi
imulq $0x26a8, %rdi, %r15     # imm = 0x26A8
movl 0x2818(%rcx,%r15), %r14d
movl %ebp, %esi
callq 0x7b05
testl %eax, %eax
je 0x87fa
movq (%r12), %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 0xbe23(%rip), %rsi      # 0x145ee
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 0xcd1c
jmp 0x88ec
movq %rsp, %rdi
movb $0x0, (%rdi)
movq (%r12), %rax
addq %r15, %rax
movslq %ebp, %rcx
imulq $0x9c, %rcx, %rcx
leaq (%rcx,%rax), %r13
addq $0x330, %r13            # imm = 0x330
movq %r13, %rsi
callq 0x21c0
cmpl $0x18, %r14d
jg 0x88ec
testl %ebp, %ebp
js 0x88ec
movl $0x19, %eax
subl %r14d, %eax
cmpl %ebp, %eax
jle 0x88ec
movq %r13, %rdi
movl $0x18, %r13d
subl %r14d, %r13d
cmpl %ebp, %r13d
je 0x88b3
jle 0x8897
movl %ebp, %eax
imulq $0x9c, %rax, %rax
leaq (%r15,%rax), %r14
addq $0x3cc, %r14            # imm = 0x3CC
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 0x886d
movq (%r12), %rax
addq %r15, %rax
movl %r13d, %ecx
imulq $0x9c, %rcx, %rcx
leaq (%rcx,%rax), %rdi
addq $0x330, %rdi            # imm = 0x330
movl $0x9c, %edx
xorl %esi, %esi
callq 0x20f0
movq (%r12), %rax
incl 0x2818(%rax,%r15)
leaq 0xc0(%rbx), %rdx
leaq 0xbd54(%rip), %rsi      # 0x1462d
leaq 0x80(%rsp), %rdi
movq %rsp, %r8
movq %rbx, %rcx
jmp 0x87d3
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq