// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movw %di, %ax
movw %ax, -0x2(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movswl -0x2(%rbp), %edi
callq 0x2aec0
cmpl $0x0, %eax
je 0x30a11
leaq 0xa9b02(%rip), %rdi     # 0xda50c
movb $0x0, %al
callq 0x44240
movl -0x8(%rbp), %edi
callq 0x11c50
cmpl $0x0, %eax
jne 0x30a2c
leaq 0xa9b01(%rip), %rdi     # 0xda526
movb $0x0, %al
callq 0x44240
movslq -0x8(%rbp), %rcx
leaq 0xfced9(%rip), %rax     # 0x12d910
cmpl $0x0, (%rax,%rcx,4)
jg 0x30a42
jmp 0x30bd1
movswq -0x2(%rbp), %rcx
leaq 0x149792(%rip), %rax    # 0x17a1e0
movq (%rax,%rcx,8), %rax
movw 0x2a(%rax), %ax
movw %ax, -0x12(%rbp)
movswl -0x12(%rbp), %edi
callq 0x2ae90
cmpl $0x0, %eax
jne 0x30a6d
jmp 0x30bd1
movswq -0x2(%rbp), %rcx
leaq 0x149767(%rip), %rax    # 0x17a1e0
movq (%rax,%rcx,8), %rax
movswl 0x1a(%rax), %eax
addl $0xffffff35, %eax       # imm = 0xFFFFFF35
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x4, %eax
ja 0x30ac0
movq -0x20(%rbp), %rax
leaq 0xa9758(%rip), %rcx     # 0xda1f4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x2000, -0x10(%rbp)    # imm = 0x2000
jmp 0x30ac7
movl $0x1800, -0x10(%rbp)    # imm = 0x1800
jmp 0x30ac7
movl $0x2000, -0x10(%rbp)    # imm = 0x2000
jmp 0x30ac7
movl $0x2000, -0x10(%rbp)    # imm = 0x2000
movswq -0x2(%rbp), %rcx
leaq 0x14970d(%rip), %rax    # 0x17a1e0
movq (%rax,%rcx,8), %rax
movswl 0xe(%rax), %eax
movl %eax, -0x24(%rbp)
subl $0x104, %eax            # imm = 0x104
je 0x30af3
jmp 0x30ae7
movl -0x24(%rbp), %eax
subl $0x12f, %eax            # imm = 0x12F
je 0x30afc
jmp 0x30b58
movl $0x400, -0x10(%rbp)     # imm = 0x400
jmp 0x30b5a
leaq 0xa9a3a(%rip), %rdi     # 0xda53d
callq 0x41510
sarl $0x3, %eax
andl $0xf, %eax
cltq
andq $0x3, %rax
cmpq $0x0, %rax
je 0x30b1f
jmp 0x30bd1
movl $0x400, -0x10(%rbp)     # imm = 0x400
cmpl $0x400, -0xc(%rbp)      # imm = 0x400
jg 0x30b56
movslq -0x8(%rbp), %rcx
leaq 0xfcd96(%rip), %rax     # 0x12d8d0
movl (%rax,%rcx,4), %ecx
subl $0x1000, %ecx           # imm = 0x1000
movswq -0x2(%rbp), %rdx
leaq 0x149691(%rip), %rax    # 0x17a1e0
movq (%rax,%rdx,8), %rax
movl %ecx, 0x8(%rax)
jmp 0x30b5a
jmp 0x30b5a
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x30bcf
movslq -0x8(%rbp), %rcx
leaq 0xfcce3(%rip), %rax     # 0x12d850
movl (%rax,%rcx,4), %edi
movswq -0x2(%rbp), %rcx
leaq 0x149664(%rip), %rax    # 0x17a1e0
movq (%rax,%rcx,8), %rax
subl (%rax), %edi
movslq -0x8(%rbp), %rcx
leaq 0xfcd03(%rip), %rax     # 0x12d890
movl (%rax,%rcx,4), %esi
movswq -0x2(%rbp), %rcx
leaq 0x149644(%rip), %rax    # 0x17a1e0
movq (%rax,%rcx,8), %rax
subl 0x4(%rax), %esi
callq 0x69950
movw %ax, %cx
movswq -0x2(%rbp), %rdx
leaq 0x149629(%rip), %rax    # 0x17a1e0
movq (%rax,%rdx,8), %rax
movw %cx, 0x1c(%rax)
movl $0x12c, %esi            # imm = 0x12C
movswl -0x2(%rbp), %edi
callq 0x2d0c0
jmp 0x30bcf
jmp 0x30bd1
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)