// File: /workspace/github_c_makefile_star2_O2/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 0x1cfc4
testl %eax, %eax
je 0x200b5
leaq 0x62642(%rip), %rdi     # 0x826f0
xorl %eax, %eax
callq 0x2acb8
movl %r14d, %edi
callq 0xe2e0
testl %eax, %eax
jne 0x200cf
leaq 0x62642(%rip), %rdi     # 0x8270a
xorl %eax, %eax
callq 0x2acb8
movslq %r14d, %r12
leaq 0xba4b7(%rip), %rax     # 0xda590
cmpl $0x0, (%rax,%r12,4)
jle 0x201b4
movswq %bp, %r14
leaq 0x107141(%rip), %r15    # 0x127230
movq (%r15,%r14,8), %rcx
cmpw $0x3fff, 0x2a(%rcx)     # imm = 0x3FFF
ja 0x201b4
movzwl 0x1a(%rcx), %edx
addl $0xffffff35, %edx       # imm = 0xFFFFFF35
xorl %eax, %eax
testw $0xfffb, %dx            # imm = 0xFFFB
setne %dl
movzwl 0xe(%rcx), %ecx
cmpl $0x12f, %ecx            # imm = 0x12F
je 0x2012e
cmpl $0x104, %ecx            # imm = 0x104
jne 0x20164
movl $0x400, %eax            # imm = 0x400
jmp 0x2016e
leaq 0x625ec(%rip), %rdi     # 0x82721
callq 0x2945b
testb $0x18, %al
jne 0x201b4
movl $0x400, %eax            # imm = 0x400
cmpl $0x400, %ebx            # imm = 0x400
jg 0x2016e
leaq 0xba3fe(%rip), %rcx     # 0xda550
movl $0xfffff000, %edx       # imm = 0xFFFFF000
addl (%rcx,%r12,4), %edx
movq (%r15,%r14,8), %rcx
movl %edx, 0x8(%rcx)
jmp 0x2016e
movb %dl, %al
shll $0xb, %eax
addl $0x1800, %eax           # imm = 0x1800
cmpl %ebx, %eax
jle 0x201b4
leaq 0xba357(%rip), %rax     # 0xda4d0
movl (%rax,%r12,4), %edi
movq (%r15,%r14,8), %rax
subl (%rax), %edi
leaq 0xba386(%rip), %rcx     # 0xda510
movl (%rcx,%r12,4), %esi
subl 0x4(%rax), %esi
callq 0x43e64
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 0x1e16a
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq