// File: /workspace/github_c_makefile_star2_O2/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 0xc860
leaq 0x1824f(%rip), %r12     # 0x1fa80
movq (%r12), %rcx
movslq %eax, %rdi
imulq $0x26a8, %rdi, %r15     # imm = 0x26A8
movl 0x2818(%rcx,%r15), %r14d
movl %ebp, %esi
callq 0x6cdd
testl %eax, %eax
je 0x78b7
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 0xbd66(%rip), %rsi      # 0x135ee
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 0xbd04
jmp 0x7944
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 0x7944
testl %ebp, %ebp
js 0x7944
pushq $0x19
popq %rax
subl %r14d, %eax
cmpl %ebp, %eax
jle 0x7944
movq %r13, %rdi
pushq $0x18
popq %r13
subl %r14d, %r13d
cmpl %ebp, %r13d
je 0x7975
movl %ebp, %eax
imulq $0x9c, %rax, %rax
leaq (%r15,%rax), %r14
addq $0x3cc, %r14            # imm = 0x3CC
movq (%r12), %rsi
cmpl %ebp, %r13d
jle 0x7956
leaq (%rsi,%r14), %rdi
addq $-0x9c, %rdi
addq %r14, %rsi
movl $0x9c, %edx
callq 0x2170
addq $0x9c, %r14
incl %ebp
jmp 0x7918
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x1a0, %rsi            # imm = 0x1A0
movl %r13d, %eax
addq %r15, %rsi
imulq $0x9c, %rax, %rax
leaq (%rax,%rsi), %rdi
addq $0x190, %rdi            # imm = 0x190
movl $0x9c, %edx
xorl %esi, %esi
callq 0x20f0
movq (%r12), %rax
incl 0x2818(%rax,%r15)
leaq 0xc0(%rbx), %rdx
leaq 0xbc92(%rip), %rsi      # 0x1362d
leaq 0x80(%rsp), %rdi
movq %rsp, %r8
movq %rbx, %rcx
jmp 0x7890