// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %edi
leaq -0x14(%rbp), %rsi
callq 0x1c810
cmpl $0x0, %eax
je 0x1fc9f
cmpl $0xabcd0002, -0x14(%rbp) # imm = 0xABCD0002
je 0x1fab1
cmpl $0xdead0002, -0x14(%rbp) # imm = 0xDEAD0002
je 0x1fab1
leaq 0xdde2(%rip), %rax      # 0x2d87d
movq %rax, 0x16ace(%rip)     # 0x36570
movl $0x1, 0x1ce4c(%rip)     # 0x3c8f8
jmp 0x1fc9d
cmpl $0xdead0002, -0x14(%rbp) # imm = 0xDEAD0002
jne 0x1facd
leaq 0xddd0(%rip), %rdi      # 0x2d891
movb $0x0, %al
callq 0x61b0
jmp 0x1fc9b
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x1e740
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x50, %rsi
callq 0x1d3a0
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x58, %rsi
callq 0x1d3a0
movl -0x4(%rbp), %edi
leaq -0x18(%rbp), %rsi
callq 0x1c810
movl -0x4(%rbp), %edi
leaq -0x1c(%rbp), %rsi
callq 0x1c810
movq -0x10(%rbp), %rax
movb $-0x1, 0x90(%rax)
cmpl $0x0, -0x18(%rbp)
jne 0x1fb4e
cmpl $0x1, -0x1c(%rbp)
jne 0x1fb3d
movq -0x10(%rbp), %rax
leaq 0x1759d(%rip), %rcx     # 0x370d0
addq $0x50, %rcx
movq %rcx, 0x60(%rax)
jmp 0x1fb49
movq -0x10(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0x1fbe6
cmpl $0x1, -0x18(%rbp)
jne 0x1fb71
movq -0x10(%rbp), %rax
movq $0x0, 0x60(%rax)
movl -0x1c(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x90(%rax)
jmp 0x1fbe4
cmpl $0x2, -0x18(%rbp)
jne 0x1fbae
leaq 0x1713a(%rip), %rax     # 0x36cb8
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
callq 0x1bd40
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x1fbac
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
jmp 0x1fbe2
cmpl $0x3, -0x18(%rbp)
jne 0x1fbd4
movslq -0x1c(%rbp), %rax
leaq 0x17161(%rip), %rcx     # 0x36d20
imulq $0x68, %rax, %rax
addq %rax, %rcx
addq $0x10, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
jmp 0x1fbe0
movq -0x10(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0x1fbe2
jmp 0x1fbe4
jmp 0x1fbe6
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x68, %rsi
callq 0x1f040
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x70, %rsi
callq 0x1de70
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x78, %rsi
callq 0x1ccf0
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x80, %rsi
callq 0x1c810
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x84, %rsi
callq 0x1c810
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x88, %rsi
callq 0x1c810
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x8c, %rsi
callq 0x1c7b0
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x8d, %rsi
callq 0x1c760
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x8e, %rsi
callq 0x1c760
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x8f, %rsi
callq 0x1c760
jmp 0x1fc9d
jmp 0x1fca9
movl $0x1, 0x1cc4f(%rip)     # 0x3c8f8
xorl %eax, %eax
cmpl $0x0, 0x1cc46(%rip)     # 0x3c8f8
movb %al, -0x31(%rbp)
jne 0x1fcc4
cmpl $0x0, 0x1cc32(%rip)     # 0x3c8f0
sete %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)