// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/src/tekstat.c
// Function: attackifclose
void
attackifclose(short i, int snum, int dist)
{
     int      mindist;
     short     ext;

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

     if( !validplayer(snum) ) {
          crashgame("atakifclse: bad plrnum");
     }
     if( health[snum] <= 0 ) {
          return;
     }
     ext=sprptr[i]->extra;
     if( !validext(ext) ) {
          return;
     }

     switch( sprptr[i]->statnum ) {
     case CHASE:
          mindist=CHASEATTDIST;
          break;
     case PATROL:
     case GUARD:
          mindist=GUARDATTDIST;
          break;
     case STALK:
          mindist=STALKATTDIST;
          break;
     default:
          mindist=MINATTACKDIST;
          break;
     }

     switch( sprptr[i]->picnum ) {
     case RATPIC:
          mindist=1024L;
          break;
     case BATPIC:
          if( RMOD4("STAT1968") != 0 ) {
               return;
          }
          mindist=1024;
          if( dist <= 1024 ) {
               sprptr[i]->z=posz[snum]-4096;
          }

          break;
     default:
          break;
     }

	if ( (dist < mindist) ) {
          switch( sprptr[i]->statnum ) {
          default:
               sprptr[i]->ang=
                 getangle(posx[snum]-sprptr[i]->x,posy[snum]-sprptr[i]->y);
               newstatus(i, ATTACK);
               break;
          }
     }

 return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebx
movl %esi, %r14d
movl %edi, %ebp
callq 0x1ea05
testl %eax, %eax
je 0x21dea
leaq 0x6b885(%rip), %rdi     # 0x8d668
xorl %eax, %eax
callq 0x2d800
movl %r14d, %edi
callq 0xf210
testl %eax, %eax
jne 0x21e04
leaq 0x6b885(%rip), %rdi     # 0x8d682
xorl %eax, %eax
callq 0x2d800
movslq %r14d, %r12
leaq 0xbf782(%rip), %rax     # 0xe1590
cmpl $0x0, (%rax,%r12,4)
jle 0x21eea
movswq %bp, %r14
leaq 0x10c3ec(%rip), %r15    # 0x12e210
movq (%r15,%r14,8), %rcx
cmpw $0x3fff, 0x2a(%rcx)     # imm = 0x3FFF
ja 0x21eea
movzwl 0x1a(%rcx), %edx
addl $0xffffff35, %edx       # imm = 0xFFFFFF35
xorl %eax, %eax
testl $0xfffb, %edx           # imm = 0xFFFB
setne %dl
movzwl 0xe(%rcx), %ecx
cmpl $0x12f, %ecx            # imm = 0x12F
je 0x21e64
cmpl $0x104, %ecx            # imm = 0x104
jne 0x21e9a
movl $0x400, %eax            # imm = 0x400
jmp 0x21ea4
leaq 0x6b82e(%rip), %rdi     # 0x8d699
callq 0x2be4a
testb $0x18, %al
jne 0x21eea
movl $0x400, %eax            # imm = 0x400
cmpl $0x400, %ebx            # imm = 0x400
jg 0x21ea4
leaq 0xbf6c8(%rip), %rcx     # 0xe1550
movl $0xfffff000, %edx       # imm = 0xFFFFF000
addl (%rcx,%r12,4), %edx
movq (%r15,%r14,8), %rcx
movl %edx, 0x8(%rcx)
jmp 0x21ea4
movb %dl, %al
shll $0xb, %eax
addl $0x1800, %eax           # imm = 0x1800
cmpl %ebx, %eax
jle 0x21eea
leaq 0xbf621(%rip), %rax     # 0xe14d0
movl (%rax,%r12,4), %edi
movq (%r15,%r14,8), %rax
subl (%rax), %edi
leaq 0xbf650(%rip), %rcx     # 0xe1510
movl (%rcx,%r12,4), %esi
subl 0x4(%rax), %esi
callq 0x469df
movq (%r15,%r14,8), %rcx
movw %ax, 0x1c(%rcx)
movswl %r14w, %edi
movl $0x12c, %esi            # imm = 0x12C
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1fc27
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq