// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
movl %edi, %ebx
callq 0x1eb81
testl %eax, %eax
je 0x22160
leaq 0x6e66d(%rip), %rdi     # 0x907c6
xorl %eax, %eax
callq 0x2eb88
leaq 0x54d239(%rip), %rax    # 0x56f3a0
movzwl 0x1a2(%rax), %ebp
movslq %ebx, %r14
cmpw $-0x1, %bp
je 0x22224
imulq $0x2c, %r14, %rax
addq 0xaedfa(%rip), %rax     # 0xd0f80
movq %rax, 0x8(%rsp)
leaq 0x555a1e(%rip), %r12    # 0x577bb0
leaq 0x10f097(%rip), %r15    # 0x131230
movswq %bp, %r13
movzwl (%r12,%r13,2), %ebp
movq (%r15,%r13,8), %rax
movswq 0x2a(%rax), %rbx
cmpq $0x4000, %rbx           # imm = 0x4000
jb 0x221d5
movq 0x8(%rsp), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
leaq 0x6e328(%rip), %rdi     # 0x904ed
movl $0x64, %ecx
xorl %eax, %eax
callq 0x2eb88
movq (%r15,%r13,8), %rax
movq (%r15,%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 0x2221a
leaq 0x1b701f(%rip), %rax    # 0x1d9230
movq (%rax,%rbx,8), %rax
orw $0x4, 0x6(%rax)
cmpw $-0x1, %bp
jne 0x22199
leaq 0x54d175(%rip), %rax    # 0x56f3a0
movzwl 0x192(%rax), %ebp
cmpw $-0x1, %bp
je 0x222fe
imulq $0x2c, %r14, %rax
addq 0xaed39(%rip), %rax     # 0xd0f80
movq %rax, 0x8(%rsp)
leaq 0x55595d(%rip), %rsi    # 0x577bb0
leaq 0x10efd6(%rip), %r15    # 0x131230
leaq 0x1b6fcf(%rip), %r13    # 0x1d9230
movq %r14, 0x10(%rsp)
movswq %bp, %r12
movzwl (%rsi,%r12,2), %ebp
movq (%r15,%r12,8), %rax
movswq 0x2a(%rax), %rbx
cmpq $0x4000, %rbx           # imm = 0x4000
jb 0x222a9
movq %rsi, %r14
movq 0x8(%rsp), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
leaq 0x6e258(%rip), %rdi     # 0x904ed
movl $0x65, %ecx
xorl %eax, %eax
callq 0x2eb88
movq %r14, %rsi
movq 0x10(%rsp), %r14
movq (%r13,%rbx,8), %rax
cmpw $0xcb, 0x8(%rax)
je 0x222f4
movq (%r15,%r14,8), %rcx
movq (%r15,%r12,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 0x222f4
orb $0x4, 0x6(%rax)
cmpw $-0x1, %bp
jne 0x22266
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq