// File: /workspace/github_c_makefile_star2_O2/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 $0x10, %rsp
movq %rsi, %rbx
andl $0x0, 0x8(%rsp)
movl %edi, %ebp
orl $-0x1, 0x4(%rsp)
leaq 0xc(%rsp), %rsi
callq 0x14cb7
testl %eax, %eax
je 0x16b53
movl 0xc(%rsp), %eax
cmpl $0xabcd0002, %eax       # imm = 0xABCD0002
je 0x16ad6
cmpl $0xdead0002, %eax       # imm = 0xDEAD0002
jne 0x16b45
leaq 0xa6f9(%rip), %rdi      # 0x211c3
xorl %eax, %eax
callq 0x61c0
jmp 0x16c39
movl %ebp, %edi
movq %rbx, %rsi
callq 0x15e4c
leaq 0x50(%rbx), %rsi
movl %ebp, %edi
callq 0x153bb
leaq 0x58(%rbx), %rsi
movl %ebp, %edi
callq 0x153bb
leaq 0x8(%rsp), %r14
movl %ebp, %edi
movq %r14, %rsi
callq 0x14cb7
leaq 0x4(%rsp), %rsi
movl %ebp, %edi
callq 0x14cb7
movb $-0x1, 0x90(%rbx)
movl (%r14), %eax
cmpq $0x3, %rax
ja 0x16b62
leaq 0xa1b8(%rip), %rcx      # 0x20ce0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x1, 0x4(%rsp)
jne 0x16b62
leaq 0x17111(%rip), %rax     # 0x2dc50
addq $0x50, %rax
jmp 0x16b9e
leaq 0xa663(%rip), %rax      # 0x211af
movq %rax, 0x1696d(%rip)     # 0x2d4c0
movl $0x1, 0x1c91b(%rip)     # 0x33478
jmp 0x16c39
andq $0x0, 0x60(%rbx)
jmp 0x16bb3
leaq 0x16cc8(%rip), %rax     # 0x2d838
movq (%rax), %rdi
movl 0x4(%rsp), %esi
callq 0x14730
testq %rax, %rax
je 0x16bb3
movq 0x10(%rax), %rax
jmp 0x16b9e
movslq 0x4(%rsp), %rax
imulq $0x68, %rax, %rax
leaq 0x16d09(%rip), %rcx     # 0x2d8a0
addq %rcx, %rax
addq $0x10, %rax
movq %rax, 0x60(%rbx)
jmp 0x16bb3
andq $0x0, 0x60(%rbx)
movb 0x4(%rsp), %al
movb %al, 0x90(%rbx)
leaq 0x68(%rbx), %rsi
movl %ebp, %edi
callq 0x16490
leaq 0x70(%rbx), %rsi
movl %ebp, %edi
callq 0x158d3
leaq 0x78(%rbx), %rsi
movl %ebp, %edi
callq 0x14f6f
leaq 0x80(%rbx), %rsi
movl %ebp, %edi
callq 0x14cb7
leaq 0x84(%rbx), %rsi
movl %ebp, %edi
callq 0x14cb7
leaq 0x88(%rbx), %rsi
movl %ebp, %edi
callq 0x14cb7
leaq 0x8c(%rbx), %rsi
movl %ebp, %edi
callq 0x14c80
leaq 0x8d(%rbx), %rsi
movl %ebp, %edi
callq 0x14c64
leaq 0x8e(%rbx), %rsi
movl %ebp, %edi
callq 0x14c64
addq $0x8f, %rbx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x14c64
movl 0x1c831(%rip), %ecx     # 0x33470
xorl %eax, %eax
orl 0x1c831(%rip), %ecx     # 0x33478
sete %al
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq