// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %rbx
subq $0x68, %rsp
movw %di, %ax
movb 0x10(%rbp), %dil
movw %ax, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movsbl 0x10(%rbp), %eax
movl %eax, -0x44(%rbp)
testl %eax, %eax
je 0x28366
jmp 0x28352
movl -0x44(%rbp), %eax
subl $0x1, %eax
je 0x2836f
jmp 0x2835c
movl -0x44(%rbp), %eax
subl $0x2, %eax
je 0x28378
jmp 0x2837f
movl $0x10001, -0x34(%rbp)   # imm = 0x10001
jmp 0x2837f
movl $0x1000040, -0x34(%rbp) # imm = 0x1000040
jmp 0x2837f
movl $0x10001, -0x34(%rbp)   # imm = 0x10001
movswq -0xc(%rbp), %rcx
leaq 0x44e755(%rip), %rax    # 0x476ae0
imulq $0x2c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movswl 0xc(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x283d2
movq -0x40(%rbp), %rax
movswq 0xe(%rax), %rcx
leaq 0x5d1458(%rip), %rax    # 0x5f9810
movswl (%rax,%rcx,2), %ecx
movq -0x40(%rbp), %rax
movzbl 0x15(%rax), %eax
imull %eax, %ecx
shll %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x28(%rbp)
jmp 0x283d9
movl $0x0, -0x28(%rbp)
movq -0x40(%rbp), %rax
movw 0x18(%rax), %ax
movw %ax, -0x2c(%rbp)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x4, %rsi
movl -0x10(%rbp), %r8d
movl -0x14(%rbp), %r9d
movq -0x40(%rbp), %rax
movzbl 0x12(%rax), %ebx
shll $0x2, %ebx
movl -0x1c(%rbp), %r11d
movl -0x20(%rbp), %r10d
movl -0x34(%rbp), %eax
leaq -0x24(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x6d430
movw %ax, -0x2a(%rbp)
movswl -0x2c(%rbp), %eax
movq -0x40(%rbp), %rcx
movswl 0x18(%rcx), %ecx
cmpl %ecx, %eax
je 0x28467
movswl -0x2c(%rbp), %eax
cmpl $0x0, %eax
jl 0x28467
movw -0xc(%rbp), %ax
movswl %ax, %edi
movswl -0x2c(%rbp), %esi
callq 0x69bd0
movq -0x40(%rbp), %rax
movw 0xc(%rax), %ax
movw %ax, -0x2e(%rbp)
movq -0x40(%rbp), %rax
movswl 0xc(%rax), %ecx
andl $-0x2, %ecx
movw %cx, 0xc(%rax)
movq -0x40(%rbp), %rax
movl (%rax), %edi
movq -0x40(%rbp), %rax
movl 0x4(%rax), %esi
movq -0x40(%rbp), %rax
movl 0x8(%rax), %edx
subl $0x1, %edx
movq -0x40(%rbp), %rax
movw 0x18(%rax), %cx
movq -0x40(%rbp), %rax
movzbl 0x12(%rax), %r10d
shll $0x2, %r10d
movl -0x34(%rbp), %eax
leaq 0x106278(%rip), %r8     # 0x12e730
leaq 0x106275(%rip), %r9     # 0x12e734
leaq 0x106272(%rip), %rbx    # 0x12e738
leaq 0x10626f(%rip), %r11    # 0x12e73c
movswl %cx, %ecx
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x70760
movw -0x2e(%rbp), %cx
movq -0x40(%rbp), %rax
movw %cx, 0xc(%rax)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
addl -0x28(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
leaq 0x106223(%rip), %rcx    # 0x12e730
cmpl (%rcx), %eax
jle 0x2851f
movl -0x24(%rbp), %eax
leaq 0x10621d(%rip), %rcx    # 0x12e738
cmpl (%rcx), %eax
jle 0x28541
movswl -0x2a(%rbp), %eax
cmpl $0x0, %eax
je 0x28532
movw -0x2a(%rbp), %ax
movw %ax, -0xa(%rbp)
jmp 0x28556
movswl -0x2c(%rbp), %eax
addl $0x4000, %eax           # imm = 0x4000
movw %ax, -0xa(%rbp)
jmp 0x28556
movl -0x24(%rbp), %ecx
subl -0x28(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x8(%rax)
movw -0x2a(%rbp), %ax
movw %ax, -0xa(%rbp)
movw -0xa(%rbp), %ax
addq $0x68, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)