// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/src/tekspr.c
// Function: movesprite
short
movesprite(short spritenum, int dx, int dy, int dz, int ceildist, int flordist, char cliptype)
{
     int           daz,zoffs;
     int           jumpz,deltaz;
     int           px,py,pz;
     short          retval,dasectnum,tempshort;
     short          failedsectnum;
     unsigned int dcliptype;
     spritetype     *spr;

    #ifdef PLRSPRDEBUG
     if( isaplayersprite(spritenum) ) {
          crashgame("messing w plrsprite at 19");
     }
    #endif

     switch (cliptype) {
          case NORMALCLIP: dcliptype = CLIPMASK0; break;
          case PROJECTILECLIP: dcliptype = CLIPMASK1; break;
          case CLIFFCLIP: dcliptype = CLIPMASK0; break;
     }

     spr = &sprite[spritenum];

     if ((spr->cstat&128) == 0)
          zoffs = -((tilesizy[spr->picnum]*spr->yrepeat)<<1);
     else
          zoffs = 0;

     dasectnum = spr->sectnum;
     px=spr->x;
     py=spr->y;
     pz=spr->z;
     daz = spr->z+zoffs;
     retval = clipmove(&spr->x,&spr->y,&daz,&dasectnum,dx,dy,
                                   ((int)spr->clipdist)<<2,ceildist,flordist,dcliptype);
     if( (dasectnum != spr->sectnum) && (dasectnum >= 0) ) {
          changespritesect(spritenum,dasectnum);
     }

     if( dasectnum >= 0 && (sectptr[dasectnum]->lotag == 4) && (spr->extra != -1) ) {
          switch( spr->statnum ) {
          case FLOATING:
               break;
          default:
               spr->z=sectptr[spr->sectnum]->floorz-zoffs;
               break;
          }
          return(retval);
     }

     tempshort = spr->cstat; spr->cstat &= ~1;
     getzrange(spr->x,spr->y,spr->z-1,spr->sectnum,
                     &globhiz,&globhihit,&globloz,&globlohit,
                     ((int)spr->clipdist)<<2,dcliptype);
     spr->cstat = tempshort;
     daz = spr->z+zoffs + dz;
     if( (daz <= globhiz) || (daz > globloz) ) {
          if( retval != 0 ) {
               return(retval);
          }
          else {
               return(16384+dasectnum);
          }
     }
     if( (globloz != pz) && (spr->extra >= 0) && (spr->extra < MAXSPRITES) ) {
          spr->z=globloz;
          deltaz=abs(pz-globloz);
          jumpz=tilesizy[spr->picnum]+(spr->yrepeat-64);
          jumpz<<=8;
          if( deltaz > jumpz ) {
               failedsectnum=spr->sectnum;
               setsprite(spritenum,px,py,pz);
               retval=failedsectnum+16384;
          }
     }
     else {
          spr->z = daz-zoffs;
     }

     return(retval);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r10d
movl %r8d, %eax
movl %ecx, %ebp
movl %edx, %r9d
movl %esi, %r8d
cmpb $0x1, 0x60(%rsp)
movl $0x1000040, %ecx        # imm = 0x1000040
movl $0x10001, %r14d         # imm = 0x10001
cmovel %ecx, %r14d
movl %edi, %r15d
movslq %edi, %rcx
imulq $0x2c, %rcx, %rcx
leaq 0x408255(%rip), %rdx    # 0x423b30
leaq (%rdx,%rcx), %rbx
xorl %r13d, %r13d
testb $-0x80, 0xc(%rdx,%rcx)
jne 0x1b908
movswq 0xe(%rbx), %rcx
leaq 0x58cd6b(%rip), %rdx    # 0x5a8660
movswl (%rdx,%rcx,2), %ecx
movzbl 0x15(%rbx), %r13d
imull %ecx, %r13d
addl %r13d, %r13d
negl %r13d
movzwl 0x18(%rbx), %ecx
leaq 0xe(%rsp), %r12
movw %cx, (%r12)
movl (%rbx), %ecx
movl %ecx, 0x18(%rsp)
movl 0x4(%rbx), %ecx
movl %ecx, 0x14(%rsp)
leaq 0x4(%rbx), %rsi
movl 0x8(%rbx), %ecx
movq %rcx, 0x20(%rsp)
addl %r13d, %ecx
leaq 0x1c(%rsp), %rdx
movl %ecx, (%rdx)
movzbl 0x12(%rbx), %r11d
shll $0x2, %r11d
movq %rbx, %rdi
movq %r12, %rcx
pushq %r14
pushq %r10
pushq %rax
pushq %r11
callq 0x460b8
addq $0x20, %rsp
movl %eax, 0x8(%rsp)
movzwl (%r12), %eax
movswl %r15w, %r15d
testw %ax, %ax
js 0x1b980
cmpw 0x18(%rbx), %ax
je 0x1b980
movswl %ax, %esi
movl %r15d, %edi
callq 0x43fe1
movzwl 0xe(%rsp), %eax
testw %ax, %ax
js 0x1b9c4
movzwl %ax, %ecx
leaq 0x1d38a1(%rip), %rax    # 0x1ef230
movq (%rax,%rcx,8), %rcx
cmpw $0x4, 0x22(%rcx)
jne 0x1b9c4
cmpw $-0x1, 0x2a(%rbx)
je 0x1b9c4
cmpw $0x142, 0x1a(%rbx)      # imm = 0x142
je 0x1bab6
movswq 0x18(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movl 0x8(%rax), %eax
subl %r13d, %eax
movl %eax, 0x8(%rbx)
jmp 0x1bab6
movl %r15d, 0x10(%rsp)
movzwl 0xc(%rbx), %r15d
movl %r15d, %eax
andl $-0x2, %eax
movw %ax, 0xc(%rbx)
movl (%rbx), %edi
movl 0x4(%rbx), %esi
movl 0x8(%rbx), %edx
decl %edx
movswl 0x18(%rbx), %ecx
movzbl 0x12(%rbx), %eax
shll $0x2, %eax
leaq 0xbfd88(%rip), %r10     # 0xdb77c
leaq 0xbfd7d(%rip), %r11     # 0xdb778
leaq 0xbfd6e(%rip), %r12     # 0xdb770
leaq 0xbfd6b(%rip), %r9      # 0xdb774
movq %r12, %r8
pushq %r14
movq %r11, %r14
pushq %rax
pushq %r10
pushq %r11
callq 0x4841a
addq $0x20, %rsp
movw %r15w, 0xc(%rbx)
addl %r13d, %ebp
addl 0x8(%rbx), %ebp
movl %ebp, 0x1c(%rsp)
cmpl (%r12), %ebp
jle 0x1ba3b
movl (%r14), %eax
cmpl %eax, %ebp
jle 0x1ba51
movl 0x8(%rsp), %ebp
testw %bp, %bp
jne 0x1baba
movzwl 0xe(%rsp), %ebp
addl $0x4000, %ebp           # imm = 0x4000
jmp 0x1baba
movq 0x20(%rsp), %rcx
movl %ecx, %edx
subl %eax, %edx
movl 0x10(%rsp), %edi
je 0x1bab0
cmpw $0x3fff, 0x2a(%rbx)     # imm = 0x3FFF
ja 0x1bab0
movl %eax, 0x8(%rbx)
movl %edx, %eax
negl %eax
cmovsl %edx, %eax
movswq 0xe(%rbx), %rsi
leaq 0x58cbe2(%rip), %rdx    # 0x5a8660
movswl (%rdx,%rsi,2), %esi
movzbl 0x15(%rbx), %edx
addl %esi, %edx
shll $0x8, %edx
addl $0xffffc000, %edx       # imm = 0xFFFFC000
cmpl %edx, %eax
movl 0x8(%rsp), %ebp
jle 0x1baba
movl $0x4000, %ebp           # imm = 0x4000
addl 0x18(%rbx), %ebp
movl 0x18(%rsp), %esi
movl 0x14(%rsp), %edx
callq 0x43f76
jmp 0x1baba
subl %r13d, %ebp
movl %ebp, 0x8(%rbx)
movl 0x8(%rsp), %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq