// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/src/tekspr.c
// Function: kenmovesprite
short
kenmovesprite(short spritenum, int dx, int dy, int dz, int ceildist, int flordist, char cliptype)
{
     int daz, zoffs;
     short retval, dasectnum, tempshort;
     unsigned int dcliptype;
     spritetype *spr;

    #ifdef PLRSPRDEBUG
     if( isaplayersprite(spritenum) ) {
          crashgame("messing w plrsprite at 17");
     }
    #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;  //Can't modify sprite sectors directly becuase of linked lists
     daz = spr->z+zoffs;  //Must do this if not using the new centered centering (of course)
     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);

          //Set the blocking bit to 0 temporarly so getzrange doesn't pick up
          //its own sprite
     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);
          return(16384+dasectnum);
     }
     spr->z = daz-zoffs;
     return(retval);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, %r10d
movl %r8d, %eax
movl %ecx, %ebx
movl %edx, %r9d
movl %esi, %r8d
cmpb $0x1, 0x50(%rsp)
movl $0x1000040, %ecx        # imm = 0x1000040
movl $0x10001, %ebp          # imm = 0x10001
cmovel %ecx, %ebp
movl %edi, %r15d
movslq %edi, %rcx
imulq $0x2c, %rcx, %rcx
leaq 0x40dd4d(%rip), %rdx    # 0x42ab10
leaq (%rdx,%rcx), %r14
xorl %r13d, %r13d
testb $-0x80, 0xc(%rdx,%rcx)
jne 0x1cdf0
movswq 0xe(%r14), %rcx
leaq 0x592863(%rip), %rdx    # 0x5af640
movswl (%rdx,%rcx,2), %ecx
movzbl 0x15(%r14), %r13d
imull %ecx, %r13d
addl %r13d, %r13d
negl %r13d
movzwl 0x18(%r14), %ecx
leaq 0xe(%rsp), %r12
movw %cx, (%r12)
movl 0x8(%r14), %ecx
addl %r13d, %ecx
leaq 0x14(%rsp), %rdx
movl %ecx, (%rdx)
leaq 0x4(%r14), %rsi
movzbl 0x12(%r14), %r11d
shll $0x2, %r11d
movq %r14, %rdi
movq %r12, %rcx
pushq %rbp
pushq %r10
pushq %rax
pushq %r11
callq 0x48f87
addq $0x20, %rsp
movl %eax, 0x10(%rsp)
movzwl (%r12), %eax
testw %ax, %ax
js 0x1ce50
cmpw 0x18(%r14), %ax
je 0x1ce50
movswl %r15w, %edi
movswl %ax, %esi
callq 0x46bb5
movzwl 0xc(%r14), %r12d
movl %r12d, %eax
andl $-0x2, %eax
movw %ax, 0xc(%r14)
movl (%r14), %edi
movl 0x4(%r14), %esi
movl 0x8(%r14), %edx
decl %edx
movswl 0x18(%r14), %ecx
movzbl 0x12(%r14), %eax
shll $0x2, %eax
leaq 0xc58fb(%rip), %r10     # 0xe277c
leaq 0xc58f0(%rip), %r11     # 0xe2778
leaq 0xc58e1(%rip), %r15     # 0xe2770
leaq 0xc58de(%rip), %r9      # 0xe2774
movq %r15, %r8
pushq %rbp
movq %r11, %rbp
pushq %rax
pushq %r10
pushq %r11
callq 0x4b1d2
addq $0x20, %rsp
movw %r12w, 0xc(%r14)
addl %r13d, %ebx
addl 0x8(%r14), %ebx
movl %ebx, 0x14(%rsp)
cmpl (%r15), %ebx
jle 0x1ced2
cmpl (%rbp), %ebx
jg 0x1ced2
subl %r13d, %ebx
movl %ebx, 0x8(%r14)
movl 0x10(%rsp), %eax
jmp 0x1cee5
movl 0x10(%rsp), %eax
testw %ax, %ax
jne 0x1cee5
movzwl 0xe(%rsp), %eax
addl $0x4000, %eax           # imm = 0x4000
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq