// File: /workspace/github_c_makefile_star2_O0/ajpaulson[P]srogue11/state.c
// Function: rs_write_thing
int rs_write_thing(FILE *savef, struct thing *t)
{
    int i = -1;
    
    if (t == NULL)
    {
        rs_write_int(savef, RSID_THING_NULL);
        return(WRITESTAT);
    }
    
    rs_write_int(savef, RSID_THING);

    rs_write_stats(savef, &t->t_stats);
    rs_write_coord(savef, t->t_pos);
    rs_write_coord(savef, t->t_oldpos);

    /* 
        t_dest can be:
        0,0: NULL
        0,1: location of hero
        0,3: global coord 'delta'
        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.
    */

    if (t->t_dest == &hero)
    {
        rs_write_int(savef,0);
        rs_write_int(savef,1);
    }
    else if (t->t_dest != NULL)
    {
        i = find_thing_coord(mlist, t->t_dest);
            
        if (i >=0 )
        {
            rs_write_int(savef,1);
            rs_write_int(savef,i);
        }
        else
        {
            i = find_object_coord(lvl_obj, t->t_dest);
            
            if (i >= 0)
            {
                rs_write_int(savef,2);
                rs_write_int(savef,i);
            }
            else
            {
                i = find_room_coord(rooms, t->t_dest, MAXROOMS);
        
                if (i >= 0) 
                {
                    rs_write_int(savef,3);
                    rs_write_int(savef,i);
                }
                else 
                {
                    rs_write_int(savef, 0);
                    rs_write_int(savef,1); /* chase the hero anyway */
                }
            }
        }
    }
    else
    {
        rs_write_int(savef,0);
        rs_write_int(savef,0);
    }
    
    rs_write_object_list(savef, t->t_pack);
    rs_write_room_reference(savef, t->t_room);
    rs_write_long(savef, t->t_flags);
    rs_write_int(savef, t->t_indx);
    rs_write_int(savef, t->t_nomove);
    rs_write_int(savef, t->t_nocmd);
    rs_write_boolean(savef, t->t_turn);
    rs_write_char(savef, t->t_type);
    rs_write_char(savef, t->t_disguise);
    rs_write_char(savef, t->t_oldch);
    
    return(WRITESTAT);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
cmpq $0x0, -0x18(%rbp)
jne 0x1f803
movq -0x10(%rbp), %rdi
movl $0xdead0002, %esi       # imm = 0xDEAD0002
callq 0x1bf60
cmpl $0x0, 0x1d101(%rip)     # 0x3c8f4
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4(%rbp)
jmp 0x1fa44
movq -0x10(%rbp), %rdi
movl $0xabcd0002, %esi       # imm = 0xABCD0002
callq 0x1bf60
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1e650
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rsi
callq 0x1d360
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rsi
callq 0x1d360
movq -0x18(%rbp), %rax
leaq 0x17885(%rip), %rcx     # 0x370d0
addq $0x50, %rcx
cmpq %rcx, 0x60(%rax)
jne 0x1f873
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x1bf60
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x1bf60
jmp 0x1f972
movq -0x18(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x1f95a
leaq 0x17427(%rip), %rax     # 0x36cb0
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rsi
callq 0x1f610
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x1f8c1
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x1bf60
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x1bf60
jmp 0x1f958
leaq 0x173f0(%rip), %rax     # 0x36cb8
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rsi
callq 0x1f680
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x1f8fd
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x1bf60
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x1bf60
jmp 0x1f956
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rsi
leaq 0x17414(%rip), %rdi     # 0x36d20
movl $0x9, %edx
callq 0x1f760
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x1f93b
movq -0x10(%rbp), %rdi
movl $0x3, %esi
callq 0x1bf60
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x1bf60
jmp 0x1f954
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x1bf60
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x1bf60
jmp 0x1f956
jmp 0x1f958
jmp 0x1f970
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x1bf60
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x1bf60
jmp 0x1f972
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rsi
callq 0x1f170
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rsi
callq 0x1de00
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rsi
callq 0x1c2d0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x80(%rax), %esi
callq 0x1bf60
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x84(%rax), %esi
callq 0x1bf60
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x88(%rax), %esi
callq 0x1bf60
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movb 0x8c(%rax), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x1bf00
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movsbl 0x8d(%rax), %esi
callq 0x1bec0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movsbl 0x8e(%rax), %esi
callq 0x1bec0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movsbl 0x8f(%rax), %esi
callq 0x1bec0
cmpl $0x0, 0x1cebb(%rip)     # 0x3c8f4
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)