// File: /workspace/github_c_makefile_star2_O3/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, %r14d
movl %r8d, %r15d
movl %ecx, %ebp
movl %edx, (%rsp)
movl %esi, 0x4(%rsp)
movl %edi, %ebx
movb 0x78(%rsp), %r13b
movzwl 0x70(%rsp), %eax
movw %ax, 0xa(%rsp)
callq 0x1eb81
testl %eax, %eax
je 0x22663
leaq 0x6e1b3(%rip), %rdi     # 0x9080f
xorl %eax, %eax
callq 0x2eb88
movl %r15d, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movswq %bx, %rbx
leaq 0x10ebb8(%rip), %rax    # 0x131230
movq (%rax,%rbx,8), %rax
movswq 0x2a(%rax), %r15
cmpq $0x4000, %r15           # imm = 0x4000
jb 0x22698
leaq 0x6e198(%rip), %rdi     # 0x90829
xorl %eax, %eax
callq 0x2eb88
leaq 0x1b6b91(%rip), %rax    # 0x1d9230
movq (%rax,%rbx,8), %rax
movzwl 0x2(%rax), %r12d
movl %r12d, %edi
callq 0xf230
testl %eax, %eax
je 0x22c92
movsbl %r13b, %r13d
leal -0x1(%r13), %eax
cmpl $0x4, %eax
jb 0x22729
leal -0x5(%r13), %eax
cmpl $0x4, %eax
jae 0x2278a
leaq 0x1b6b57(%rip), %rax    # 0x1d9230
movq (%rax,%r15,8), %rax
movzwl 0x12(%rax), %eax
cmpl $0xf09, %eax            # imm = 0xF09
jle 0x228a1
leal -0xf0a(%rax), %ecx
cmpl $0x3b, %ecx
movl (%rsp), %ebp
ja 0x2270e
movabsq $0x800010000000401, %rdx # imm = 0x800010000000401
btq %rcx, %rdx
jb 0x228ed
cmpl $0xfa1, %eax            # imm = 0xFA1
je 0x228ed
cmpl $0xf70, %eax            # imm = 0xF70
je 0x228ed
jmp 0x228c3
leaq 0x1b6b00(%rip), %rax    # 0x1d9230
movq (%rax,%r15,8), %rax
movzwl 0x12(%rax), %eax
cmpl $0xf09, %eax            # imm = 0xF09
movl (%rsp), %ebp
jg 0x228ca
cmpl $0x7e6, %eax            # imm = 0x7E6
jle 0x22b2b
leal -0xebd(%rax), %ecx
cmpl $0x2d, %ecx
ja 0x22775
movl $0x92, %edi
movabsq $0x202108000001, %rdx   # imm = 0x202108000001
btq %rcx, %rdx
jb 0x228f2
cmpl $0x7e7, %eax            # imm = 0x7E7
jne 0x22b64
movl $0x62, %edi
jmp 0x228f2
testl %r13d, %r13d
jne 0x22c88
leaq 0x1b6a96(%rip), %rax    # 0x1d9230
movq (%rax,%r15,8), %rax
movzwl 0x12(%rax), %eax
cmpl $0x118, %eax            # imm = 0x118
movl 0x4(%rsp), %ebx
movq %r12, %r14
je 0x227d3
movl $0x1f, %edi
cmpl $0xf46, %eax            # imm = 0xF46
je 0x227c1
movl $0x93, %edi
movl %ebx, %esi
movl (%rsp), %edx
xorl %ecx, %ecx
movl $0x4, %r8d
callq 0x1c370
leal (,%r14,4), %eax
leaq 0xc1cee(%rip), %rcx     # 0xe44d0
subl (%rcx,%rax), %ebx
movl %ebx, %ecx
negl %ecx
cmovsl %ebx, %ecx
leaq 0xc1d1d(%rip), %rdx     # 0xe4510
movl (%rsp), %esi
subl (%rdx,%rax), %esi
movl %esi, %eax
negl %eax
cmovsl %esi, %eax
addq %rcx, %rax
cmpq $0x3ff, %rax            # imm = 0x3FF
ja 0x22c92
movl %r14d, %eax
leaq 0xc1d37(%rip), %rcx     # 0xe4550
subl (%rcx,%rax,4), %ebp
movl %ebp, %eax
negl %eax
cmovsl %ebp, %eax
cmpl $0x2fff, %eax           # imm = 0x2FFF
ja 0x22c92
movl %r14d, %edi
callq 0xf582
leaq 0x1b69f3(%rip), %r12    # 0x1d9230
movq (%r12,%r15,8), %rax
movzwl 0x4(%rax), %eax
testb $0x8, %al
movq 0x10(%rsp), %rbx
je 0x2287d
movl $0x92, %edi
movl 0x4(%rsp), %esi
movl (%rsp), %edx
xorl %ecx, %ecx
movl $0x4, %r8d
callq 0x1c370
movswl %bx, %esi
movswl %r14w, %edi
xorl %edx, %edx
callq 0x22593
movq (%r12,%r15,8), %rax
movzwl 0x4(%rax), %eax
testb $0x4, %al
jne 0x22cab
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 0x22593
addl $0xfffff143, %eax       # imm = 0xFFFFF143
cmpl $0x2d, %eax
movl (%rsp), %ebp
ja 0x228c3
movl $0x92, %edi
movabsq $0x202108000001, %rcx   # imm = 0x202108000001
btq %rax, %rcx
jb 0x228f2
movl $0x69, %edi
jmp 0x228f2
leal -0xf0a(%rax), %ecx
cmpl $0x3b, %ecx
ja 0x22b4e
movabsq $0x800010000000401, %rdx # imm = 0x800010000000401
btq %rcx, %rdx
jae 0x22b4e
movl $0x93, %edi
movq %r12, 0x30(%rsp)
movl 0x4(%rsp), %r12d
movl %r12d, %esi
movl %ebp, %edx
xorl %ecx, %ecx
movl $0x4, %r8d
callq 0x1c370
leal -0x3(%r13), %eax
cmpl $0x3, %eax
jae 0x229e1
shll $0xb, %r14d
movl $0x32000, %eax          # imm = 0x32000
subl %r14d, %eax
leaq 0xc1c22(%rip), %rcx     # 0xe4550
movq 0x30(%rsp), %rdx
movl (%rcx,%rdx,4), %r15d
movzwl 0x18(%rsp), %ecx
leal 0x200(%rcx), %edx
movl $0x7ff, %esi            # imm = 0x7FF
andl %esi, %edx
leaq 0x55d280(%rip), %rdi    # 0x57fbd0
movswl (%rdi,%rdx,2), %r8d
andl %esi, %ecx
movswl (%rdi,%rcx,2), %r9d
leaq 0x20(%rsp), %r10
leaq 0x24(%rsp), %r11
leaq 0x28(%rsp), %rbx
leaq 0xc(%rsp), %r14
movswl 0xa(%rsp), %ecx
movl %r12d, %edi
movl %ebp, %esi
movl %r15d, %edx
pushq $0x1000040              # imm = 0x1000040
pushq %r10
pushq %r11
pushq %rbx
pushq %r14
leaq 0x56(%rsp), %r10
pushq %r10
leaq 0x3e(%rsp), %r10
pushq %r10
pushq %rax
callq 0x49337
addq $0x40, %rsp
movswl (%r14), %edi
testl %edi, %edi
jle 0x22a4f
leaq 0x1c(%rsp), %rsi
callq 0x22de9
testl %eax, %eax
je 0x22b01
movl 0x1c(%rsp), %ebp
movl %ebp, %edi
callq 0xf582
movswl 0x10(%rsp), %esi
movswl %bp, %edi
movl $0x3, %edx
callq 0x22593
jmp 0x22c88
cmpl $0x6, %r13d
leaq 0x10e844(%rip), %r14    # 0x131230
jne 0x22c88
movq (%r14,%rbx,8), %rax
movswl 0x18(%rax), %edi
movl $0x191, %esi            # imm = 0x191
callq 0x1eac8
cmpw $-0x1, %ax
je 0x22c88
movq (%r14,%rbx,8), %rcx
movl (%rcx), %ecx
movswq %ax, %r12
movq (%r14,%r12,8), %rax
movl %ecx, (%rax)
movq (%r14,%rbx,8), %rax
movl 0x4(%rax), %eax
movq (%r14,%r12,8), %rcx
movl %eax, 0x4(%rcx)
leaq 0x1b67fd(%rip), %rax    # 0x1d9230
movq (%rax,%r15,8), %rax
cmpw $0x1f4, 0x8(%rax)       # imm = 0x1F4
movq (%r14,%rbx,8), %rax
jne 0x22b6e
movl 0x8(%rax), %eax
jmp 0x22b86
movswl 0xe(%rsp), %edi
movl $0x3, %esi
callq 0x1eac8
cmpw $-0x1, %ax
je 0x22c88
movswq %ax, %rax
imulq $0x2c, %rax, %rcx
leaq 0x40b0b9(%rip), %rdx    # 0x42db30
movl 0x28(%rsp), %esi
movl %esi, (%rdx,%rcx)
movl 0x24(%rsp), %esi
movl %esi, 0x4(%rdx,%rcx)
movl $0x800, %esi            # imm = 0x800
addl 0x20(%rsp), %esi
leaq (%rdx,%rcx), %rdi
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 0x18(%rsp), %esi
movw %si, 0x1c(%rdx,%rcx)
movq 0x10(%rsp), %rsi
addl $0x4000, %esi           # imm = 0x4000
movw %si, 0x1e(%rdx,%rcx)
movabsq $0x3f000000000000, %rsi # imm = 0x3F000000000000
movq %rsi, 0x20(%rdx,%rcx)
movl $0xffff0000, 0x28(%rdx,%rcx) # imm = 0xFFFF0000
leaq (%rax,%rax,2), %rsi
shlq $0x2, %rsi
addq 0xae4be(%rip), %rsi     # 0xd0fb0
movl $0x3, %edx
callq 0x6110e
jmp 0x22c88
movswl 0xc(%rsp), %r14d
movl %r13d, %edi
movl 0x4(%rsp), %esi
movl (%rsp), %edx
movl %r15d, %ecx
movl %r14d, %r8d
callq 0xf2d6
movl %r14d, %edi
movl %eax, %esi
callq 0x21ba2
jmp 0x22c88
cmpl $0x490, %eax            # imm = 0x490
je 0x22b64
cmpl $0x6eb, %eax            # imm = 0x6EB
je 0x22ca1
cmpl $0x73e, %eax            # imm = 0x73E
jne 0x22b64
movl $0x61, %edi
jmp 0x228f2
cmpl $0xfa1, %eax            # imm = 0xFA1
je 0x228ed
cmpl $0xf70, %eax            # imm = 0xF70
je 0x228ed
movl $0x5f, %edi
jmp 0x228f2
movswq 0x18(%rax), %rax
leaq 0x1d66b6(%rip), %rcx    # 0x1f9230
movq (%rcx,%rax,8), %rcx
movl $0xffffe000, %eax       # imm = 0xFFFFE000
addl 0x8(%rcx), %eax
movq (%r14,%r12,8), %rcx
movl %eax, 0x8(%rcx)
movq (%r14,%r12,8), %rax
movw $0x1, 0xc(%rax)
movq (%r14,%r12,8), %rax
movw $0x138, 0xe(%rax)       # imm = 0x138
movq (%r14,%r12,8), %rax
movb $-0x20, 0x10(%rax)
movq (%r14,%r12,8), %rax
movb $0x20, %cl
movb %cl, 0x14(%rax)
movq (%r14,%r12,8), %rax
movb %cl, 0x15(%rax)
movq (%r14,%rbx,8), %rax
movzwl 0x1c(%rax), %eax
movq (%r14,%r12,8), %rcx
movw %ax, 0x1c(%rcx)
movq (%r14,%r12,8), %rax
movl $0x200, %ecx            # imm = 0x200
addl 0x1c(%rax), %ecx
movl $0x7ff, %edx            # imm = 0x7FF
andl %edx, %ecx
leaq 0x55cfed(%rip), %rsi    # 0x57fbd0
movswl (%rsi,%rcx,2), %ecx
shrl $0x4, %ecx
movw %cx, 0x20(%rax)
movq (%r14,%r12,8), %rax
movzwl 0x1c(%rax), %ecx
andl %edx, %ecx
movswl (%rsi,%rcx,2), %ecx
shrl $0x4, %ecx
movw %cx, 0x22(%rax)
movq 0x30(%rsp), %rax
leal (,%rax,4), %ebx
leaq 0xc18ba(%rip), %rax     # 0xe44d0
movl (%rax,%rbx), %eax
movq (%r14,%r12,8), %rcx
subl (%rcx), %eax
imull %eax, %eax
leaq 0xc18e7(%rip), %rdx     # 0xe4510
movl (%rdx,%rbx), %edi
subl 0x4(%rcx), %edi
imull %edi, %edi
addl %eax, %edi
callq 0x48a4d
movl %eax, %ecx
cmpl $0x1, %eax
adcl $0x0, %ecx
leaq 0xc1908(%rip), %rax     # 0xe4550
movl (%rax,%rbx), %eax
movq (%r14,%r12,8), %rsi
subl 0x8(%rsi), %eax
shll $0x9, %eax
addl $0x100000, %eax         # imm = 0x100000
cltd
idivl %ecx
movw %ax, 0x24(%rsi)
movq (%r14,%r12,8), %rax
movq 0x10(%rsp), %rcx
movw %cx, 0x1e(%rax)
movq (%r14,%r12,8), %rax
movb $0x10, 0x12(%rax)
movq (%r14,%r12,8), %rax
xorl %ecx, %ecx
movw %cx, 0x26(%rax)
movq (%r14,%r12,8), %rax
movw %cx, 0x28(%rax)
movq 0x10(%rsp), %rdi
callq 0x22139
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x60, %edi
jmp 0x228f2
movl %ebx, %edi
callq 0x22cda
movswl %bx, %ebx
movswl %r14w, %edi
movl %ebx, %esi
movl $0x6, %edx
callq 0x22593
movl %ebx, %edi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1eb19