// File: /workspace/github_c_makefile_star2_O3/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, %r14d
movl %edx, %r9d
movl %esi, %r8d
cmpb $0x1, 0x60(%rsp)
movl $0x1000040, %ecx        # imm = 0x1000040
movl $0x10001, %r12d         # imm = 0x10001
cmovel %ecx, %r12d
movl %edi, %r15d
movslq %edi, %rcx
imulq $0x2c, %rcx, %rcx
leaq 0x4109b8(%rip), %rdx    # 0x42db30
leaq (%rdx,%rcx), %rbx
xorl %ebp, %ebp
testb $-0x80, 0xc(%rdx,%rcx)
jne 0x1d1a0
movswq 0xe(%rbx), %rcx
leaq 0x5954cf(%rip), %rdx    # 0x5b2660
movswl (%rdx,%rcx,2), %ecx
movzbl 0x15(%rbx), %ebp
imull %ecx, %ebp
addl %ebp, %ebp
negl %ebp
movzwl 0x18(%rbx), %ecx
leaq 0xe(%rsp), %r13
movw %cx, (%r13)
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 %ebp, %ecx
leaq 0x1c(%rsp), %rdx
movl %ecx, (%rdx)
movzbl 0x12(%rbx), %r11d
shll $0x2, %r11d
movq %rbx, %rdi
movq %r13, %rcx
pushq %r12
pushq %r10
pushq %rax
pushq %r11
callq 0x4acdd
addq $0x20, %rsp
movl %eax, 0x8(%rsp)
movzwl (%r13), %eax
testw %ax, %ax
js 0x1d214
cmpw 0x18(%rbx), %ax
je 0x1d214
movswl %r15w, %edi
movswl %ax, %esi
callq 0x48b21
movzwl 0xe(%rsp), %eax
testw %ax, %ax
js 0x1d257
movzwl %ax, %ecx
leaq 0x1dc00d(%rip), %rax    # 0x1f9230
movq (%rax,%rcx,8), %rcx
cmpw $0x4, 0x22(%rcx)
jne 0x1d257
cmpw $-0x1, 0x2a(%rbx)
je 0x1d257
cmpw $0x142, 0x1a(%rbx)      # imm = 0x142
je 0x1d351
movswq 0x18(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movl 0x8(%rax), %eax
subl %ebp, %eax
movl %eax, 0x8(%rbx)
jmp 0x1d351
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 0xc84f5(%rip), %r10     # 0xe577c
leaq 0xc84ea(%rip), %r11     # 0xe5778
leaq 0xc84db(%rip), %r13     # 0xe5770
leaq 0xc84d8(%rip), %r9      # 0xe5774
movq %r13, %r8
pushq %r12
movq %r11, %r12
pushq %rax
pushq %r10
pushq %r11
callq 0x4d1fe
addq $0x20, %rsp
movw %r15w, 0xc(%rbx)
addl %ebp, %r14d
addl 0x8(%rbx), %r14d
movl %r14d, 0x1c(%rsp)
cmpl (%r13), %r14d
jle 0x1d2d2
movl (%r12), %eax
cmpl %eax, %r14d
jle 0x1d2e8
movl 0x8(%rsp), %ebp
testw %bp, %bp
jne 0x1d355
movzwl 0xe(%rsp), %ebp
addl $0x4000, %ebp           # imm = 0x4000
jmp 0x1d355
movq 0x20(%rsp), %rcx
movl %ecx, %edx
subl %eax, %edx
movl 0x10(%rsp), %esi
je 0x1d34a
cmpw $0x3fff, 0x2a(%rbx)     # imm = 0x3FFF
ja 0x1d34a
movl %eax, 0x8(%rbx)
movl %edx, %eax
negl %eax
cmovsl %edx, %eax
movswq 0xe(%rbx), %rdi
leaq 0x59534b(%rip), %rdx    # 0x5b2660
movswl (%rdx,%rdi,2), %edi
movzbl 0x15(%rbx), %edx
addl %edi, %edx
shll $0x8, %edx
addl $0xffffc000, %edx       # imm = 0xFFFFC000
cmpl %edx, %eax
movl 0x8(%rsp), %ebp
jle 0x1d355
movl $0x4000, %ebp           # imm = 0x4000
addl 0x18(%rbx), %ebp
movswl %si, %edi
movl 0x18(%rsp), %esi
movl 0x14(%rsp), %edx
callq 0x48ab4
jmp 0x1d355
subl %ebp, %r14d
movl %r14d, 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