// File: /workspace/github_c_makefile_star2_O1/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
movl %edi, %ebp
movl $0x0, 0x4(%rsp)
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
leaq 0x8(%rsp), %rsi
callq 0x15d65
testl %eax, %eax
je 0x18117
movl 0x8(%rsp), %eax
cmpl $0xabcd0002, %eax       # imm = 0xABCD0002
je 0x18084
cmpl $0xdead0002, %eax       # imm = 0xDEAD0002
jne 0x18109
leaq 0xb0d3(%rip), %rdi      # 0x2314b
xorl %eax, %eax
callq 0x61c0
jmp 0x18250
movl %ebp, %edi
movq %rbx, %rsi
callq 0x171fe
leaq 0x50(%rbx), %rsi
movl %ebp, %edi
callq 0x15d65
leaq 0x54(%rbx), %rsi
movl %ebp, %edi
callq 0x15d65
leaq 0x58(%rbx), %rsi
movl %ebp, %edi
callq 0x15d65
leaq 0x5c(%rbx), %rsi
movl %ebp, %edi
callq 0x15d65
leaq 0x4(%rsp), %r14
movl %ebp, %edi
movq %r14, %rsi
callq 0x15d65
movq %rsp, %rsi
movl %ebp, %edi
callq 0x15d65
movb $-0x1, 0x90(%rbx)
movl (%r14), %eax
cmpq $0x3, %rax
ja 0x18126
leaq 0xab7e(%rip), %rcx      # 0x22c68
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x1, (%rsp)
jne 0x18126
leaq 0x15b60(%rip), %rax     # 0x2dc60
addq $0x50, %rax
jmp 0x18190
leaq 0xb027(%rip), %rax      # 0x23137
movq %rax, 0x153b9(%rip)     # 0x2d4d0
movl $0x1, 0x1b367(%rip)     # 0x33488
jmp 0x18250
movq $0x0, 0x60(%rbx)
jmp 0x18194
leaq 0x15711(%rip), %rax     # 0x2d848
movq (%rax), %rcx
testq %rcx, %rcx
je 0x1817f
movl (%rsp), %edx
incl %edx
xorl %eax, %eax
decl %edx
je 0x18183
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x18146
jmp 0x18187
movslq (%rsp), %rax
imulq $0x68, %rax, %rax
leaq 0x1574d(%rip), %rcx     # 0x2d8b0
addq %rcx, %rax
addq $0x10, %rax
jmp 0x18190
movq $0x0, 0x60(%rbx)
movb (%rsp), %al
movb %al, 0x90(%rbx)
jmp 0x18194
xorl %eax, %eax
jmp 0x18187
movq 0x10(%rcx), %rax
testq %rax, %rax
je 0x18194
movq 0x10(%rax), %rax
movq %rax, 0x60(%rbx)
leaq 0x68(%rbx), %rsi
movl %ebp, %edi
callq 0x1790d
leaq 0xc(%rsp), %r14
movl %ebp, %edi
movq %r14, %rsi
callq 0x15d65
movslq (%r14), %rax
imulq $0x68, %rax, %rax
addq 0x11d54(%rip), %rax     # 0x29f10
movq %rax, 0x70(%rbx)
leaq 0x78(%rbx), %rsi
movl %ebp, %edi
callq 0x16076
leaq 0x80(%rbx), %rsi
movl %ebp, %edi
callq 0x15d65
leaq 0x84(%rbx), %rsi
movl %ebp, %edi
callq 0x15d65
leaq 0x88(%rbx), %rsi
movl %ebp, %edi
callq 0x15d65
leaq 0xc(%rsp), %r14
movl %ebp, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x15c8d
cmpb $0x0, (%r14)
setne 0x8c(%rbx)
leaq 0x8d(%rbx), %rsi
movl %ebp, %edi
movl $0x1, %edx
callq 0x15c8d
leaq 0x8e(%rbx), %rsi
movl %ebp, %edi
movl $0x1, %edx
callq 0x15c8d
addq $0x8f, %rbx
movl %ebp, %edi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x15c8d
movl 0x1b22a(%rip), %ecx     # 0x33480
xorl %eax, %eax
orl 0x1b22a(%rip), %ecx     # 0x33488
sete %al
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq