// File: /workspace/github_c_makefile_star2_O3/ajpaulson[P]srogue11/state.c
// Function: rs_read_thing
int rs_read_thing(int inf, struct thing *t)
{
    int id;
    int listid = 0, index = -1;
    struct linked_list *item;
        
    if (rs_read_int(inf, &id) != 0)
    {
        if ((id != RSID_THING) && (id != RSID_THING_NULL)) {
            fmterr = "RSID_THING mismatch";
            format_error = TRUE;
        }
        else if (id == RSID_THING_NULL)
        {
            printf("NULL Thing?\n\r");
        }
        else
        {
            rs_read_stats(inf, &t->t_stats);
            rs_read_coord(inf, &t->t_pos);
            rs_read_coord(inf, &t->t_oldpos);

            /* 
                t_dest can be (listid,index):
                0,0: NULL
                0,1: location of hero
                1,i: location of a thing (monster)
                2,i: location of an object
                3,i: location of gold in a room

                We need to remember what we are chasing rather than 
                the current location of what we are chasing.
            */
            
            rs_read_int(inf, &listid);
            rs_read_int(inf, &index);
            t->t_reserved = -1;

            if (listid == 0) /* hero or NULL */
            {
                if (index == 1)
                    t->t_dest = &hero;
                else
                    t->t_dest = NULL;
            }
            else if (listid == 1) /* monster/thing */
            {
                t->t_dest     = NULL;
                t->t_reserved = index;
            }
            else if (listid == 2) /* object */
            {
                struct object *obj;

                item = get_list_item(lvl_obj, index);

                if (item != NULL)
                {
                    obj = OBJPTR(item);
                    t->t_dest = &obj->o_pos;
                }
            }
            else if (listid == 3) /* gold */
            {
                t->t_dest = &rooms[index].r_gold;
            }
            else
                t->t_dest = NULL;

            rs_read_object_list(inf, &t->t_pack);
            rs_read_room_reference(inf, &t->t_room);
            rs_read_long(inf, &t->t_flags);
            rs_read_int(inf, &t->t_indx);
            rs_read_int(inf, &t->t_nomove);
            rs_read_int(inf, &t->t_nocmd);
            rs_read_boolean(inf, &t->t_turn);
            rs_read_char(inf, &t->t_type);
            rs_read_char(inf, &t->t_disguise);
            rs_read_char(inf, &t->t_oldch);
        }
    }
    else format_error = TRUE;
    
    return(READSTAT);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movl $0x0, 0x18(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
leaq 0x1c(%rsp), %rsi
callq 0x15bb9
testl %eax, %eax
je 0x17f4d
movl 0x1c(%rsp), %eax
cmpl $0xabcd0002, %eax       # imm = 0xABCD0002
je 0x17eba
cmpl $0xdead0002, %eax       # imm = 0xDEAD0002
jne 0x17f3f
leaq 0xb315(%rip), %rdi      # 0x231c3
xorl %eax, %eax
callq 0x61c0
jmp 0x18094
movl %ebp, %edi
movq %rbx, %rsi
callq 0x17030
leaq 0x50(%rbx), %rsi
movl %ebp, %edi
callq 0x15bb9
leaq 0x54(%rbx), %rsi
movl %ebp, %edi
callq 0x15bb9
leaq 0x58(%rbx), %rsi
movl %ebp, %edi
callq 0x15bb9
leaq 0x5c(%rbx), %rsi
movl %ebp, %edi
callq 0x15bb9
leaq 0x18(%rsp), %r14
movl %ebp, %edi
movq %r14, %rsi
callq 0x15bb9
leaq 0xc(%rsp), %rsi
movl %ebp, %edi
callq 0x15bb9
movb $-0x1, 0x90(%rbx)
movl (%r14), %eax
cmpq $0x3, %rax
ja 0x17f5c
leaq 0xadbe(%rip), %rcx      # 0x22ce0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x1, 0xc(%rsp)
jne 0x17f5c
leaq 0x15d27(%rip), %rax     # 0x2dc60
addq $0x50, %rax
jmp 0x17fa4
leaq 0xb269(%rip), %rax      # 0x231af
movq %rax, 0x15583(%rip)     # 0x2d4d0
movl $0x1, 0x1b531(%rip)     # 0x33488
jmp 0x18094
movq $0x0, 0x60(%rbx)
jmp 0x17fbc
leaq 0x158db(%rip), %rax     # 0x2d848
movq (%rax), %rax
testq %rax, %rax
je 0x17fbc
movl 0xc(%rsp), %ecx
incl %ecx
decl %ecx
je 0x180ae
movq (%rax), %rax
testq %rax, %rax
jne 0x17f7b
jmp 0x17fbc
movslq 0xc(%rsp), %rax
imulq $0x68, %rax, %rax
leaq 0x15913(%rip), %rcx     # 0x2d8b0
addq %rcx, %rax
addq $0x10, %rax
movq %rax, 0x60(%rbx)
jmp 0x17fbc
movq $0x0, 0x60(%rbx)
movb 0xc(%rsp), %al
movb %al, 0x90(%rbx)
leaq 0x68(%rbx), %rsi
movl %ebp, %edi
callq 0x1775e
leaq 0x10(%rsp), %r14
movl %ebp, %edi
movq %r14, %rsi
callq 0x15bb9
movslq (%r14), %rax
imulq $0x68, %rax, %rax
addq 0x11f2c(%rip), %rax     # 0x29f10
movq %rax, 0x70(%rbx)
leaq 0x10(%rsp), %rsi
movl %ebp, %edi
movl $0x4, %edx
callq 0x15ade
cmpl $0x0, 0x1b490(%rip)     # 0x33490
jne 0x18009
movq 0x10(%rsp), %rax
jmp 0x1800b
xorl %eax, %eax
movq %rax, 0x78(%rbx)
leaq 0x80(%rbx), %rsi
movl %ebp, %edi
callq 0x15bb9
leaq 0x84(%rbx), %rsi
movl %ebp, %edi
callq 0x15bb9
leaq 0x88(%rbx), %rsi
movl %ebp, %edi
callq 0x15bb9
leaq 0x10(%rsp), %r14
movl %ebp, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x15ade
cmpb $0x0, (%r14)
setne 0x8c(%rbx)
leaq 0x8d(%rbx), %rsi
movl %ebp, %edi
movl $0x1, %edx
callq 0x15ade
leaq 0x8e(%rbx), %rsi
movl %ebp, %edi
movl $0x1, %edx
callq 0x15ade
addq $0x8f, %rbx
movl %ebp, %edi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x15ade
movl 0x1b3e6(%rip), %ecx     # 0x33480
xorl %eax, %eax
orl 0x1b3e6(%rip), %ecx     # 0x33488
sete %al
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x17fbc
movq 0x10(%rax), %rax
jmp 0x17fa4