// File: /workspace/github_c_makefile_star2_O3/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 0x410c01(%rip), %rdx    # 0x42db30
leaq (%rdx,%rcx), %r14
xorl %r13d, %r13d
testb $-0x80, 0xc(%rdx,%rcx)
jne 0x1cf5c
movswq 0xe(%r14), %rcx
leaq 0x595717(%rip), %rdx    # 0x5b2660
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 0x4acdd
addq $0x20, %rsp
movl %eax, 0x10(%rsp)
movzwl (%r12), %ecx
movzwl 0x18(%r14), %eax
cmpw %ax, %cx
sete %dl
testw %cx, %cx
sets %sil
orb %dl, %sil
jne 0x1cfcc
movswl %r15w, %edi
movswl %cx, %esi
callq 0x48b21
movzwl 0x18(%r14), %eax
movzwl 0xc(%r14), %r12d
movl %r12d, %ecx
andl $-0x2, %ecx
movw %cx, 0xc(%r14)
movl (%r14), %edi
movl 0x4(%r14), %esi
movl 0x8(%r14), %edx
decl %edx
movzbl 0x12(%r14), %r10d
shll $0x2, %r10d
leaq 0xc877f(%rip), %r11     # 0xe5778
movswl %ax, %ecx
leaq 0xc876d(%rip), %r15     # 0xe5770
leaq 0xc876a(%rip), %r9      # 0xe5774
movq %r15, %r8
pushq %rbp
movq %r11, %rbp
pushq %r10
pushq 0xb3f27(%rip)           # 0xd0f40
pushq %r11
callq 0x4d1fe
addq $0x20, %rsp
movw %r12w, 0xc(%r14)
addl %r13d, %ebx
addl 0x8(%r14), %ebx
cmpl (%r15), %ebx
jle 0x1d047
cmpl (%rbp), %ebx
jg 0x1d047
subl %r13d, %ebx
movl %ebx, 0x8(%r14)
movl 0x10(%rsp), %eax
jmp 0x1d05a
movl 0x10(%rsp), %eax
testw %ax, %ax
jne 0x1d05a
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