// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/src/tekstat.c
// Function: enemyshootgun
void
enemyshootgun(short sprnum,int x,int y,int z,short daang,int dahoriz,
              short dasectnum,char guntype)
{
     short     hitsect,hitwall,hitsprite,daang2;
     int       j,daz2,hitx,hity,hitz,discrim;
     int       ext,target,pnum;

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

     ext=sprptr[sprnum]->extra;
     if( !validext(ext) ) {
          crashgame("enemyshootgun: bad ext");
     }
     target=sprXTptr[sprnum]->target;
     if( !validplayer(target) ) {
          return;
     }

     // enemy gun fire sounds
     switch (guntype) {
     case 0:
          switch( sprXTptr[ext]->attackpic ) {
          case RATATTACKPIC:
               break;
          case 3910:
               playsound(S_WH_8,x,y,0,ST_NOUPDATE);
               break;
          default:
               playsound(S_MATRIX_ATTACK2,x,y,0,ST_NOUPDATE);
               break;
          }
          break;
     case 1:
     case 2:
     case 3:
     case 4:
          switch( sprXTptr[ext]->attackpic ) {
          case 3773:
          case 3800:
          case 3805:
          case 3810:
          case 3818:
               playsound(S_MATRIX_ATTACK,x,y,0,ST_NOUPDATE);
               break;
          case 3850:
          case 3860:
          case 3890:
          case 3909:
          case 3952:
          case 4001:
               playsound(S_MATRIX_ATTACK2,x,y,0,ST_NOUPDATE);
               break;
          case COPATTACKPIC:
               playsound(S_ENEMYGUN1,x,y,0,ST_NOUPDATE);
               break;
          case ANTATTACKPIC:
               playsound(S_ENEMYGUN2,x,y,0,ST_NOUPDATE);
               break;
          case MAATTACKPIC:
               playsound(S_ENEMYGUN3,x,y,0,ST_NOUPDATE);
               break;
          case SAMATTACKPIC:
               playsound(S_ENEMYGUN4,x,y,0,ST_NOUPDATE);
               break;
          default:
               playsound(S_ENEMYGUN1,x,y,0,ST_NOUPDATE);
               break;
          }
          break;
     case 5:
     case 6:
     case 7:
     case 8:
          switch( sprXTptr[ext]->attackpic ) {
          case 3773:
          case 3800:
          case 3805:
          case 3810:
          case 3818:
               playsound(S_MATRIX_ATTACK,x,y,0,ST_NOUPDATE);
               break;
          case 3850:
          case 3860:
          case 3890:
          case 3909:
          case 3952:
          case 4001:
               playsound(S_MATRIX_ATTACK2,x,y,0,ST_NOUPDATE);
               break;
          default:
               playsound(S_AUTOGUN,x,y,0,ST_NOUPDATE);
          }
          break;
     default:
          break;
     }

     // gun shot code
     switch (guntype) {
     case 0:
          if( (labs(x-posx[target])+labs(y-posy[target])) < 1024 ) {
               if( labs(z-posz[target]) < 12288 ) {
                    playerpainsound(target);
                    if( ((sprXTptr[ext]->fxmask)&FX_HOLOGRAM) != 0 ) {
                         playsound(S_MATRIX_ATTACK,x,y,0,ST_NOUPDATE);
                         enemywoundplayer(target,sprnum,0);
                    }
                    if( ((sprXTptr[ext]->fxmask)&FX_ANDROID) != 0 ) {
                         androidexplosion(sprnum);
                         enemywoundplayer(target,sprnum,6);
                         //changespritestat(sprnum, VANISH);
                         jsdeletesprite(sprnum);
                    }
                    else {
                         enemywoundplayer(target,sprnum,0);
                    }
               }
          }
          return;
     case GUN3FLAG:
     case GUN4FLAG:
     case GUN5FLAG:
          daang2=daang;
          daz2=((100-dahoriz)<<11);
          z=posz[target];     // instead of calculating a dot product angle
          hitscan(x,y,z,dasectnum,sintable[(daang2+2560)&2047],
               sintable[(daang2+2048)&2047],daz2,
               &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1);
          if( hitsprite > 0 ) {
               if( playerhit(hitsprite, &pnum) ) {
                    playerpainsound(pnum);
                    enemywoundplayer(pnum,sprnum,3);
               }
               else {
                    damagesprite(hitsprite,tekgundamage(guntype,x,y,z,hitsprite));
               }
          }
          else {
               j=jsinsertsprite(hitsect, 3);
               if( j != -1 ) {
                    fillsprite(j,hitx,hity,hitz+(8<<8),2,-4,0,32,16,16,0,0,
                               EXPLOSION,daang,0,0,0,sprnum+MAXSPRITES,hitsect,3,63,0,0);
               }
          }
          break;
     case GUN6FLAG:
	     j = jsinsertsprite(sprptr[sprnum]->sectnum, PROJECTILE);
          if ( j ==  -1 ) {
               break;
          }
	     sprptr[j]->x=sprptr[sprnum]->x;
	     sprptr[j]->y=sprptr[sprnum]->y;
          switch( sprXTptr[ext]->basestat ) {
          case FLY:
	          sprptr[j]->z=sprptr[sprnum]->z;
               break;
          default:
	          sprptr[j]->z=sectptr[sprptr[sprnum]->sectnum]->floorz-8192;
               break;
          }
	     sprptr[j]->cstat=0x01;
	     sprptr[j]->picnum=PULSARPIC;
	     sprptr[j]->shade=-32;
	     sprptr[j]->xrepeat=32;
	     sprptr[j]->yrepeat=32;
	     sprptr[j]->ang=sprptr[sprnum]->ang;
	     sprptr[j]->xvel=(sintable[(sprptr[j]->ang+2560)&2047]>>4);
	     sprptr[j]->yvel=(sintable[(sprptr[j]->ang+2048)&2047]>>4);
          discrim=ksqrt((posx[target]-sprptr[j]->x)*(posx[target]-sprptr[j]->x) +
				    (posy[target]-sprptr[j]->y)*(posy[target]-sprptr[j]->y));
          if ( discrim == 0 ) {
               discrim=1;
          }
	     sprptr[j]->zvel=((posz[target]+(8<<8)-sprptr[j]->z)<<9)/discrim;
          sprptr[j]->owner=sprnum;
	     sprptr[j]->clipdist=16L;
	     sprptr[j]->lotag=0;
	     sprptr[j]->hitag=0;
          break;
     default:
          break;
     }

     if( guntype != 0 ) {
          enemygunshot(sprnum);
     }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, %r13d
movl %r8d, %ebp
movl %ecx, 0x18(%rsp)
movl %edx, 0x8(%rsp)
movl %esi, 0x4(%rsp)
movl %edi, %ebx
movb 0x78(%rsp), %al
movb %al, 0x3(%rsp)
movzwl 0x70(%rsp), %eax
movw %ax, 0xe(%rsp)
callq 0x1ea05
testl %eax, %eax
je 0x223fa
leaq 0x6b2f8(%rip), %rdi     # 0x8d6eb
xorl %eax, %eax
callq 0x2d800
movl %ebp, 0x14(%rsp)
movswq %bx, %rbp
leaq 0x10be07(%rip), %rax    # 0x12e210
movq (%rax,%rbp,8), %rax
movswq 0x2a(%rax), %r15
cmpq $0x4000, %r15           # imm = 0x4000
jb 0x22429
leaq 0x6b2e3(%rip), %rdi     # 0x8d705
xorl %eax, %eax
callq 0x2d800
leaq 0x1b3de0(%rip), %rax    # 0x1d6210
movq (%rax,%rbp,8), %rax
movzwl 0x2(%rax), %r14d
movl %r14d, %edi
callq 0xf210
testl %eax, %eax
je 0x22a2b
movsbl 0x3(%rsp), %r12d
leal -0x1(%r12), %eax
cmpl $0x4, %eax
jb 0x224bb
leal -0x5(%r12), %eax
cmpl $0x4, %eax
jae 0x22516
leaq 0x1b3da2(%rip), %rax    # 0x1d6210
movq (%rax,%r15,8), %rax
movzwl 0x12(%rax), %eax
cmpl $0xf09, %eax            # imm = 0xF09
jle 0x22543
leal -0xf0a(%rax), %ecx
cmpl $0x3b, %ecx
ja 0x224a0
movabsq $0x800010000000401, %rdx # imm = 0x800010000000401
btq %rcx, %rdx
jb 0x2258c
cmpl $0xfa1, %eax            # imm = 0xFA1
je 0x2258c
cmpl $0xf70, %eax            # imm = 0xF70
je 0x2258c
jmp 0x22562
leaq 0x1b3d4e(%rip), %rax    # 0x1d6210
movq (%rax,%r15,8), %rax
movzwl 0x12(%rax), %eax
cmpl $0xf09, %eax            # imm = 0xF09
jg 0x22569
cmpl $0x7e6, %eax            # imm = 0x7E6
jle 0x2288b
leal -0xebd(%rax), %ecx
cmpl $0x2d, %ecx
ja 0x22504
movl $0x92, %edi
movabsq $0x202108000001, %rdx   # imm = 0x202108000001
btq %rcx, %rdx
jb 0x22591
cmpl $0x7e7, %eax            # imm = 0x7E7
jne 0x228ef
movl $0x62, %edi
jmp 0x22591
testl %r12d, %r12d
jne 0x22a24
leaq 0x1b3cea(%rip), %rax    # 0x1d6210
movq (%rax,%r15,8), %rax
movzwl 0x12(%rax), %eax
cmpl $0x118, %eax            # imm = 0x118
je 0x225a6
movl $0x1f, %edi
cmpl $0xf46, %eax            # imm = 0xF46
je 0x22591
jmp 0x2258c
addl $0xfffff143, %eax       # imm = 0xFFFFF143
cmpl $0x2d, %eax
ja 0x22562
movl $0x92, %edi
movabsq $0x202108000001, %rcx   # imm = 0x202108000001
btq %rax, %rcx
jb 0x22591
movl $0x69, %edi
jmp 0x22591
leal -0xf0a(%rax), %ecx
cmpl $0x3b, %ecx
ja 0x228d9
movabsq $0x800010000000401, %rdx # imm = 0x800010000000401
btq %rcx, %rdx
jae 0x228d9
movl $0x93, %edi
movl 0x4(%rsp), %esi
movl 0x8(%rsp), %edx
xorl %ecx, %ecx
movl $0x4, %r8d
callq 0x1c1f1
leal -0x3(%r12), %eax
cmpl $0x3, %eax
jae 0x22680
movq %rbx, 0x18(%rsp)
shll $0xb, %r13d
movl $0x32000, %eax          # imm = 0x32000
subl %r13d, %eax
leaq 0xbef84(%rip), %rcx     # 0xe1550
movl (%rcx,%r14,4), %r14d
movzwl 0x14(%rsp), %ecx
leal 0x200(%rcx), %edx
movl $0x7ff, %esi            # imm = 0x7FF
andl %esi, %edx
leaq 0x55a5c7(%rip), %rdi    # 0x57cbb0
movswl (%rdi,%rdx,2), %r8d
andl %esi, %ecx
movswl (%rdi,%rcx,2), %r9d
leaq 0x28(%rsp), %r10
leaq 0x2c(%rsp), %r11
leaq 0x30(%rsp), %r15
leaq 0x10(%rsp), %r13
leaq 0x36(%rsp), %rbp
leaq 0x12(%rsp), %rbx
movswl 0xe(%rsp), %ecx
movl 0x4(%rsp), %edi
movl 0x8(%rsp), %esi
movl %r14d, %edx
pushq $0x1000040              # imm = 0x1000040
pushq %r10
pushq %r11
pushq %r15
pushq %r13
pushq %rbp
pushq %rbx
pushq %rax
callq 0x473e4
addq $0x40, %rsp
movswl (%r13), %edi
testl %edi, %edi
jle 0x22769
leaq 0x24(%rsp), %rsi
callq 0x22b8d
testl %eax, %eax
movq 0x18(%rsp), %rbx
je 0x228ae
movl 0x24(%rsp), %ebp
movl %ebp, %edi
callq 0xf566
movswl %bx, %esi
movswl %bp, %edi
movl $0x3, %edx
callq 0x2232d
jmp 0x22a1d
cmpl $0x6, %r12d
je 0x22822
testl %r12d, %r12d
jne 0x22a24
leal (,%r14,4), %eax
leaq 0xbee2e(%rip), %rcx     # 0xe14d0
movl 0x4(%rsp), %edx
subl (%rcx,%rax), %edx
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
leaq 0xbee59(%rip), %rdx     # 0xe1510
movl 0x8(%rsp), %esi
subl (%rdx,%rax), %esi
movl %esi, %eax
negl %eax
cmovsl %esi, %eax
addq %rcx, %rax
cmpq $0x3ff, %rax            # imm = 0x3FF
ja 0x22a2b
movl %r14d, %eax
leaq 0xbee72(%rip), %rcx     # 0xe1550
movl 0x18(%rsp), %edx
subl (%rcx,%rax,4), %edx
movl %edx, %eax
negl %eax
cmovsl %edx, %eax
cmpl $0x2fff, %eax           # imm = 0x2FFF
ja 0x22a2b
movl %r14d, %edi
callq 0xf566
leaq 0x1b3b0a(%rip), %rax    # 0x1d6210
movq (%rax,%r15,8), %rax
testb $0x8, 0x4(%rax)
je 0x22738
movl $0x92, %edi
movl 0x4(%rsp), %esi
movl 0x8(%rsp), %edx
xorl %ecx, %ecx
movl $0x4, %r8d
callq 0x1c1f1
movswl %bx, %esi
movswl %r14w, %edi
xorl %edx, %edx
callq 0x2232d
leaq 0x1b3ad1(%rip), %rax    # 0x1d6210
movq (%rax,%r15,8), %rax
testb $0x4, 0x4(%rax)
jne 0x22a44
movswl %bx, %esi
movswl %r14w, %edi
xorl %edx, %edx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2232d
movswl 0x12(%rsp), %edi
movl $0x3, %esi
callq 0x1e94c
cmpw $-0x1, %ax
movq 0x18(%rsp), %rbx
je 0x22a1d
movswq %ax, %rax
imulq $0x2c, %rax, %rcx
leaq 0x40837a(%rip), %rdx    # 0x42ab10
leaq (%rdx,%rcx), %rdi
movl 0x30(%rsp), %esi
movl %esi, (%rdx,%rcx)
movl 0x2c(%rsp), %esi
movl %esi, 0x4(%rdx,%rcx)
movl $0x800, %esi            # imm = 0x800
addl 0x28(%rsp), %esi
movl %esi, 0x8(%rdx,%rcx)
movl $0x1ab0002, 0xc(%rdx,%rcx) # imm = 0x1AB0002
movw $0xfc, 0x10(%rdx,%rcx)
movb $0x20, 0x12(%rdx,%rcx)
movl $0x1010, 0x14(%rdx,%rcx) # imm = 0x1010
movl 0x14(%rsp), %esi
movw %si, 0x1c(%rdx,%rcx)
movl $0x0, 0x20(%rdx,%rcx)
movw $0x0, 0x24(%rdx,%rcx)
leal 0x4000(%rbx), %esi
movw %si, 0x1e(%rdx,%rcx)
movl $0x3f, 0x26(%rdx,%rcx)
movw $0xffff, 0x2a(%rdx,%rcx) # imm = 0xFFFF
leaq (%rax,%rax,2), %rsi
shlq $0x2, %rsi
addq 0xab7a5(%rip), %rsi     # 0xcdfb8
movl $0x3, %edx
callq 0x5da55
jmp 0x22a1d
leaq 0x10b9e7(%rip), %r13    # 0x12e210
movq (%r13,%rbp,8), %rax
movswl 0x18(%rax), %edi
movl $0x191, %esi            # imm = 0x191
callq 0x1e94c
cmpw $-0x1, %ax
je 0x22a1d
movq (%r13,%rbp,8), %rcx
movl (%rcx), %ecx
movswq %ax, %r12
movq (%r13,%r12,8), %rax
movl %ecx, (%rax)
movq (%r13,%rbp,8), %rax
movl 0x4(%rax), %eax
movq (%r13,%r12,8), %rcx
movl %eax, 0x4(%rcx)
leaq 0x1b39a1(%rip), %rax    # 0x1d6210
movq (%rax,%r15,8), %rax
cmpw $0x1f4, 0x8(%rax)       # imm = 0x1F4
movq (%r13,%rbp,8), %rax
movq %rbx, %r15
jne 0x228f9
movl 0x8(%rax), %eax
jmp 0x22911
cmpl $0x490, %eax            # imm = 0x490
je 0x228ef
cmpl $0x6eb, %eax            # imm = 0x6EB
je 0x22a3a
cmpl $0x73e, %eax            # imm = 0x73E
jne 0x228ef
movl $0x61, %edi
jmp 0x22591
movswl 0x10(%rsp), %r13d
movl %r12d, %edi
movl 0x4(%rsp), %esi
movl 0x8(%rsp), %edx
movl %r14d, %ecx
movl %r13d, %r8d
callq 0xf2b6
movl %r13d, %edi
movl %eax, %esi
callq 0x21942
jmp 0x22a1d
cmpl $0xfa1, %eax            # imm = 0xFA1
je 0x2258c
cmpl $0xf70, %eax            # imm = 0xF70
je 0x2258c
movl $0x5f, %edi
jmp 0x22591
movswq 0x18(%rax), %rax
leaq 0x1d390b(%rip), %rcx    # 0x1f6210
movq (%rcx,%rax,8), %rcx
movl $0xffffe000, %eax       # imm = 0xFFFFE000
addl 0x8(%rcx), %eax
movq (%r13,%r12,8), %rcx
movl %eax, 0x8(%rcx)
movq (%r13,%r12,8), %rax
movw $0x1, 0xc(%rax)
movq (%r13,%r12,8), %rax
movw $0x138, 0xe(%rax)       # imm = 0x138
movq (%r13,%r12,8), %rax
movb $-0x20, 0x10(%rax)
movq (%r13,%r12,8), %rax
movb $0x20, %cl
movb %cl, 0x14(%rax)
movq (%r13,%r12,8), %rax
movb %cl, 0x15(%rax)
movq (%r13,%rbp,8), %rax
movzwl 0x1c(%rax), %eax
movq (%r13,%r12,8), %rcx
movw %ax, 0x1c(%rcx)
movq (%r13,%r12,8), %rax
movl $0x200, %ecx            # imm = 0x200
addl 0x1c(%rax), %ecx
movl $0x7ff, %edx            # imm = 0x7FF
andl %edx, %ecx
leaq 0x55a239(%rip), %rsi    # 0x57cbb0
movswl (%rsi,%rcx,2), %ecx
shrl $0x4, %ecx
movw %cx, 0x20(%rax)
movq (%r13,%r12,8), %rax
movzwl 0x1c(%rax), %ecx
andl %edx, %ecx
movswl (%rsi,%rcx,2), %ecx
shrl $0x4, %ecx
movw %cx, 0x22(%rax)
leal (,%r14,4), %ebx
leaq 0xbeb29(%rip), %rax     # 0xe14d0
movl (%rax,%rbx), %eax
movq (%r13,%r12,8), %rcx
subl (%rcx), %eax
imull %eax, %eax
leaq 0xbeb55(%rip), %rdx     # 0xe1510
movl (%rdx,%rbx), %edi
subl 0x4(%rcx), %edi
imull %edi, %edi
addl %eax, %edi
callq 0x46ae1
movl %eax, %ecx
cmpl $0x1, %eax
adcl $0x0, %ecx
leaq 0xbeb76(%rip), %rax     # 0xe1550
movl (%rax,%rbx), %eax
movq (%r13,%r12,8), %rsi
subl 0x8(%rsi), %eax
shll $0x9, %eax
addl $0x100000, %eax         # imm = 0x100000
cltd
idivl %ecx
movw %ax, 0x24(%rsi)
movq (%r13,%r12,8), %rax
movw %bp, 0x1e(%rax)
movq (%r13,%r12,8), %rax
movb $0x10, 0x12(%rax)
movq (%r13,%r12,8), %rax
xorl %ecx, %ecx
movw %cx, 0x26(%rax)
movq (%r13,%r12,8), %rax
movw %cx, 0x28(%rax)
movq %r15, %rbx
cmpb $0x0, 0x3(%rsp)
je 0x22a2b
movl %ebx, %edi
callq 0x21ef3
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x60, %edi
jmp 0x22591
movl %ebx, %edi
callq 0x22a73
movswl %bx, %ebx
movswl %r14w, %edi
movl %ebx, %esi
movl $0x6, %edx
callq 0x2232d
movl %ebx, %edi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1e99d