// File: /workspace/github_c_makefile_star2_O1/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 0x1ea05
testl %eax, %eax
je 0x21f1a
leaq 0x6b78f(%rip), %rdi     # 0x8d6a2
xorl %eax, %eax
callq 0x2d800
leaq 0x54a45f(%rip), %rax    # 0x56c380
movzwl 0x1a2(%rax), %ebp
movslq %ebx, %r14
cmpw $-0x1, %bp
je 0x21fcb
imulq $0x2c, %r14, %rax
addq 0xac050(%rip), %rax     # 0xcdf90
movq %rax, 0x8(%rsp)
leaq 0x552c44(%rip), %r12    # 0x574b90
leaq 0x10c2bd(%rip), %r15    # 0x12e210
movswq %bp, %r13
movzwl (%r12,%r13,2), %ebp
movq (%r15,%r13,8), %rax
movswq 0x2a(%rax), %rbx
cmpq $0x4000, %rbx           # imm = 0x4000
jb 0x21f8b
movq 0x8(%rsp), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
leaq 0x6b44a(%rip), %rdi     # 0x8d3c9
movl $0x64, %ecx
xorl %eax, %eax
callq 0x2d800
movq (%r15,%r14,8), %rax
movq (%r15,%r13,8), %rcx
movl (%rax), %edx
movl 0x4(%rax), %eax
subl (%rcx), %edx
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
subl 0x4(%rcx), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
addl %esi, %ecx
cmpl $0x27ff, %ecx           # imm = 0x27FF
ja 0x21fc5
leaq 0x1b4254(%rip), %rax    # 0x1d6210
movq (%rax,%rbx,8), %rax
orw $0x4, 0x6(%rax)
cmpw $-0x1, %bp
jne 0x21f53
leaq 0x54a3ae(%rip), %rax    # 0x56c380
movzwl 0x192(%rax), %r13d
cmpw $-0x1, %r13w
je 0x22098
imulq $0x2c, %r14, %rax
addq 0xabfa0(%rip), %rax     # 0xcdf90
movq %rax, 0x8(%rsp)
leaq 0x552b94(%rip), %r8     # 0x574b90
leaq 0x10c20d(%rip), %r15    # 0x12e210
leaq 0x1b4206(%rip), %rbp    # 0x1d6210
movq %r14, 0x10(%rsp)
movswq %r13w, %r12
movzwl (%r8,%r12,2), %r13d
movq (%r15,%r12,8), %rax
movswq 0x2a(%rax), %rbx
cmpq $0x4000, %rbx           # imm = 0x4000
jb 0x22052
movq 0x8(%rsp), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
leaq 0x6b38e(%rip), %rdi     # 0x8d3c9
movl $0x65, %ecx
xorl %eax, %eax
movq %r8, %r14
callq 0x2d800
movq %r14, %r8
movq 0x10(%rsp), %r14
movq (%rbp,%rbx,8), %rax
cmpw $0xcb, 0x8(%rax)
je 0x2208d
movq (%r15,%r14,8), %rcx
movq (%r15,%r12,8), %rdx
movl (%rcx), %esi
movl 0x4(%rcx), %ecx
subl (%rdx), %esi
movl %esi, %edi
negl %edi
cmovsl %esi, %edi
subl 0x4(%rdx), %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
addl %edi, %edx
cmpl $0x27ff, %edx           # imm = 0x27FF
ja 0x2208d
orb $0x4, 0x6(%rax)
cmpw $-0x1, %r13w
jne 0x2200f
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq