// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/src/tekstat.c
// Function: enemygunshot
void
enemygunshot(int  sn)
{
     int       j,nextj,ext;
     int      dist;

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

	j=headspritestat[STROLL];
    	while( j != -1 ) {
		nextj = nextspritestat[j];

          ext=sprptr[j]->extra;
          if( !validext(ext) ) {
               noextcrashgame(sn,100);
          }
     	dist = abs(sprptr[sn]->x-sprptr[j]->x)+abs(sprptr[sn]->y-sprptr[j]->y);
 		if( dist < HEARGUNSHOTDIST ) {
               sprXTptr[ext]->aimask|=AI_JUSTSHOTAT;
          }

		j = nextj;
	}

	j=headspritestat[STANDING];
    	while( j != -1 ) {
		nextj = nextspritestat[j];

          ext=sprptr[j]->extra;
          if( !validext(ext) ) {
               noextcrashgame(sn,101);
          }

          // guards not woken by enemies gun shot
          if( sprXTptr[ext]->basestat != GUARD ) {
     	     dist = abs(sprptr[sn]->x-sprptr[j]->x)+abs(sprptr[sn]->y-sprptr[j]->y);
 		     if( dist < HEARGUNSHOTDIST ) {
                    sprXTptr[ext]->aimask|=AI_JUSTSHOTAT;
               }
          }

		j = nextj;
	}

    #ifdef WAKEUPGUARDSBYENEMYGUNSHOT
	j=headspritestat[GUARD];
    	while( j != -1 ) {
		nextj = nextspritestat[j];

          if( j == sn ) {
               j=nextj;
               continue;
          }

          ext=sprptr[j]->extra;
          if( !validext(ext) ) {
               noextcrashgame(sn,102);
          }
     	dist = labs(sprptr[sn]->x-sprptr[j]->x)+labs(sprptr[sn]->y-sprptr[j]->y);
 		if( dist < HEARGUNSHOTDIST ) {
               sprXTptr[ext]->aimask|=AI_JUSTSHOTAT;
          }

		j = nextj;
	}
    #endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, 0x4(%rsp)
callq 0x1cfc4
testl %eax, %eax
je 0x201e3
leaq 0x6254e(%rip), %rdi     # 0x8272a
xorl %eax, %eax
callq 0x2acb8
leaq 0x5451b6(%rip), %rax    # 0x5653a0
movzwl 0x1a2(%rax), %ebp
movslq 0x4(%rsp), %r14
leaq 0x54d9b3(%rip), %r15    # 0x56dbb0
leaq 0x10702c(%rip), %r12    # 0x127230
cmpw $-0x1, %bp
je 0x2027c
movswq %bp, %rbx
movzwl (%r15,%rbx,2), %ebp
movq (%r12,%rbx,8), %rax
movswq 0x2a(%rax), %r13
cmpq $0x4000, %r13           # imm = 0x4000
jb 0x20235
movl 0x4(%rsp), %edi
pushq $0x64
popq %rsi
callq 0x1d148
movq (%r12,%rbx,8), %rax
movq (%r12,%r14,8), %rcx
movq (%rcx), %xmm0
movq (%rax), %xmm1
psubd %xmm1, %xmm0
movdqa %xmm0, %xmm1
psrad $0x1f, %xmm1
pxor %xmm1, %xmm0
psubd %xmm1, %xmm0
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
paddd %xmm0, %xmm1
movd %xmm1, %eax
cmpl $0x27ff, %eax           # imm = 0x27FF
ja 0x20204
leaq 0x1aefbf(%rip), %rax    # 0x1cf230
movq (%rax,%r13,8), %rax
orw $0x4, 0x6(%rax)
jmp 0x20204
leaq 0x54511d(%rip), %rax    # 0x5653a0
movzwl 0x192(%rax), %ebp
cmpw $-0x1, %bp
je 0x2030a
movswq %bp, %r13
movzwl (%r15,%r13,2), %ebp
movq (%r12,%r13,8), %rax
movswq 0x2a(%rax), %rbx
cmpq $0x4000, %rbx           # imm = 0x4000
jb 0x202b7
movl 0x4(%rsp), %edi
pushq $0x65
popq %rsi
callq 0x1d148
leaq 0x1aef72(%rip), %rax    # 0x1cf230
movq (%rax,%rbx,8), %rax
cmpw $0xcb, 0x8(%rax)
je 0x2028a
movq (%r12,%r14,8), %rcx
movq (%r12,%r13,8), %rdx
movq (%rcx), %xmm0
movq (%rdx), %xmm1
psubd %xmm1, %xmm0
movdqa %xmm0, %xmm1
psrad $0x1f, %xmm1
pxor %xmm1, %xmm0
psubd %xmm1, %xmm0
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
paddd %xmm0, %xmm1
movd %xmm1, %ecx
cmpl $0x27ff, %ecx           # imm = 0x27FF
ja 0x2028a
orb $0x4, 0x6(%rax)
jmp 0x2028a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq