// File: /workspace/github_c_makefile_star2_O3/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 0x1eb81
testl %eax, %eax
je 0x22030
leaq 0x6e763(%rip), %rdi     # 0x9078c
xorl %eax, %eax
callq 0x2eb88
movl %r14d, %edi
callq 0xf230
testl %eax, %eax
jne 0x2204a
leaq 0x6e763(%rip), %rdi     # 0x907a6
xorl %eax, %eax
callq 0x2eb88
movslq %r14d, %r12
leaq 0xc253c(%rip), %rax     # 0xe4590
cmpl $0x0, (%rax,%r12,4)
jle 0x22130
movswq %bp, %r14
leaq 0x10f1c6(%rip), %r15    # 0x131230
movq (%r15,%r14,8), %rcx
cmpw $0x3fff, 0x2a(%rcx)     # imm = 0x3FFF
ja 0x22130
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 0x220aa
cmpl $0x104, %ecx            # imm = 0x104
jne 0x220e0
movl $0x400, %eax            # imm = 0x400
jmp 0x220ea
leaq 0x6e70c(%rip), %rdi     # 0x907bd
callq 0x2d112
testb $0x18, %al
jne 0x22130
movl $0x400, %eax            # imm = 0x400
cmpl $0x400, %ebx            # imm = 0x400
jg 0x220ea
leaq 0xc2482(%rip), %rcx     # 0xe4550
movl $0xfffff000, %edx       # imm = 0xFFFFF000
addl (%rcx,%r12,4), %edx
movq (%r15,%r14,8), %rcx
movl %edx, 0x8(%rcx)
jmp 0x220ea
movb %dl, %al
shll $0xb, %eax
addl $0x1800, %eax           # imm = 0x1800
cmpl %ebx, %eax
jle 0x22130
leaq 0xc23db(%rip), %rax     # 0xe44d0
movl (%rax,%r12,4), %edi
movq (%r15,%r14,8), %rax
subl (%rax), %edi
leaq 0xc240a(%rip), %rcx     # 0xe4510
movl (%rcx,%r12,4), %esi
subl 0x4(%rax), %esi
callq 0x48943
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 0x1fe98
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq