// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/src/tekgun.c
// Function: tekanimweap
void
tekanimweap(int gun,short p)
{
     int  ammo,firekey,fseq,seq,tics;
     int usegun;
     struct guntype *gunptr;

     if (gun < 0 || gun >= NUMWEAPONS) {
          crashgame("gun589: Invalid gun number (%d,p=%d)",gun,p);
     }
     if (option[4] != 0) {
          if (health[p] < 0 && dieframe[p] == 0) {
               dieframe[p]=TICSPERFRAME;
          }
          else if (dieframe[p] > 0) {
               sprptr[playersprite[p]]->picnum=
                    JAKEDEATHPIC+(dieframe[p]/DIEFRAMETIME);
               dieframe[p]+=TICSPERFRAME;
               return;
          }
          else {
               if ((syncbits[p]&2048) && firepicdelay[p] == 0) {
                    sprptr[playersprite[p]]->picnum=JAKEATTACKPIC;
                    firepicdelay[p]=16;
               }
               else if (firepicdelay[p] > 0) {
                    firepicdelay[p]--;
                    if (firepicdelay[p] <= 0) {
                         firepicdelay[p]=0;
                         sprptr[playersprite[p]]->picnum=JAKEWALKPIC;
                    }
               }
               if (firepicdelay[p] == 0 && syncvel[p] == 0 && syncsvel[p] == 0) {
                    sprptr[playersprite[p]]->picnum=JAKESTANDPIC;
               }
          }
     }
     if ((seq=fireseq[p]) == 0) {
          lastgun[p]=gun;
          return;
     }
     usegun=lastgun[p];
     if (usegun != gun) {
          gunptr=&guntype[usegun];
          fseq=gunptr->firepic-gunptr->pic;
          if (firedonetics[p] >= 0) {
               firedonetics[p]=2;
          }
          firekey=0;
     }
     else {
          firekey=(syncbits[p]&2048);
          if (firekey != 0) {
               drawweap[p]=1;
          }
     }
     if( (firekey == 0) && ((syncbits[p]&128) != 0) && firedonetics[p] == 1) {
//         ((firedonetics[p] == 1) || !hasammo(usegun,p)) ) {
          firedonetics[p]=2;
     }
     if (firedonetics[p] == 2) {
          firedonetics[p]=-1;
          drawweap[p]=0;
          if (firedonetics[p] <= 0) {
               gunptr=&guntype[usegun];
               fseq=gunptr->firepic-gunptr->pic;
               fireseq[p]=fseq;
          }
     }
     gunptr=&guntype[usegun];
     fseq=gunptr->firepic-gunptr->pic;
     if (seq-1 >= fseq) {
          tics=gunptr->tics;
     }
     else {
          tics=DRAWWEAPSPEED;
     }
     if (lockclock >= lastchaingun[p]+tics) {
          lastchaingun[p]=lockclock;
          ammo=hasammo(usegun,p);
          if (seq-1 >= fseq && ammo) {
               if (gunptr->action[seq-fseq-1]) {
                    switch( gun+1 ) {
//jsa friday
                         case 1:
                              if(option[4] != 0)
                                   playsound(S_WEAPON1 ,posx[p],posy[p],0,ST_NOUPDATE);
                              else
                                   playsound(S_WEAPON1 ,0,0,0,ST_IMMEDIATE);
                              break;
                         case 2:
                              if(option[4] != 0)
                                   playsound(S_WEAPON2 ,posx[p],posy[p],0,ST_NOUPDATE);
                              else
                                   playsound(S_WEAPON2 ,0,0,0,ST_IMMEDIATE);
                              break;
                         case 3:
                              if(option[4] != 0)
                                   playsound(S_WEAPON3 ,posx[p],posy[p],0,ST_NOUPDATE);
                              else
                                   playsound(S_WEAPON3 ,0,0,0,ST_IMMEDIATE);
                              break;
                         case 4:
                              if(option[4] != 0)
                                   playsound(S_WEAPON4 ,posx[p],posy[p],0,ST_NOUPDATE);
                              else
                                   playsound(S_WEAPON4 ,0,0,0,ST_IMMEDIATE);
                              break;
                         case 5:
                              if(option[4] != 0)
                                   playsound(S_WEAPON5 ,posx[p],posy[p],0,ST_NOUPDATE);
                              else
                                   playsound(S_WEAPON5 ,0,0,0,ST_IMMEDIATE);
                              break;
                         case 6:
                              if(option[4] != 0)
                                   playsound(S_WEAPON6 ,posx[p],posy[p],0,ST_NOUPDATE);
                              else
                                   playsound(S_WEAPON6 ,0,0,0,ST_IMMEDIATE);
                              break;
                         case 7:
                              if(option[4] != 0)
                                   playsound(S_WEAPON7 ,posx[p],posy[p],0,ST_NOUPDATE);
                              else
                                   playsound(S_WEAPON7 ,0,0,0,ST_IMMEDIATE);
                              break;
                         case 8:
                              playsound(S_WEAPON8 ,0,0,0,ST_IMMEDIATE);
                              break;
                         default:
                              break;

                    }
                    shootgun(p,posx[p],posy[p],posz[p],ang[p],horiz[p],
                              cursectnum[p],usegun);
                    if (option[4] != 0) {
                         sprptr[playersprite[p]]->picnum=JAKEATTACKPIC+1;
                         firepicdelay[p]=8;
                    }
               }
               if (seq-1 >= gunptr->endfirepic-gunptr->pic) {
                    fireseq[p]=fseq+1;
                    return;
               }
               if (firekey == 0) {
                    firedonetics[p]=1;
                    fireseq[p]=fseq;
                    return;
               }
               else {
                    firedonetics[p]=0;
               }
          }
          if (drawweap[p] != 0) {
               if (ammo || seq < fseq) {
                    seq++;
               }
               else {
                    if (firekey == 0) {
                         firedonetics[p]=1;
                    }
               }
          }
          else if (firedonetics[p] < 0) {
               seq--;
          }
          fireseq[p]=seq;
     }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebp
movl %edi, %r15d
cmpl $0x8, %edi
jb 0x10343
movswl %bp, %edx
leaq 0x7f0e0(%rip), %rdi     # 0x8f419
movl %r15d, %esi
xorl %eax, %eax
callq 0x2eb88
leaq 0xc162e(%rip), %rax     # 0xd1978
movb 0x4(%rax), %bl
movswq %bp, %r12
testb %bl, %bl
je 0x10387
leaq 0xd4234(%rip), %rax     # 0xe4590
cmpl $0x0, (%rax,%r12,4)
sets %dl
leaq 0x11f005(%rip), %rax    # 0x12f370
movzwl (%rax,%r12,2), %ecx
testw %cx, %cx
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x103d1
movw $0x3, (%rax,%r12,2)
leaq 0x11ef52(%rip), %rdx    # 0x12f2e0
movl (%rdx,%r12,4), %esi
leaq 0x11f017(%rip), %rax    # 0x12f3b0
testl %esi, %esi
je 0x10412
movslq (%rax,%r12,4), %rdi
cmpl %r15d, %edi
jne 0x1041b
leaq 0xd40e3(%rip), %rax     # 0xe4490
testb $0x8, 0x1(%rax,%r12,2)
je 0x10431
leaq 0x11f074(%rip), %rax    # 0x12f430
movl $0x1, (%rax,%r12,4)
movl $0x0, 0xc(%rsp)
jmp 0x1045b
testw %cx, %cx
jle 0x10593
movzwl %cx, %ecx
imull $0xcccd, %ecx, %ecx     # imm = 0xCCCD
shrl $0x14, %ecx
addl $0x3fb, %ecx            # imm = 0x3FB
leaq 0xd535d(%rip), %rdx     # 0xe5750
movswq (%rdx,%r12,2), %rdx
leaq 0x120e31(%rip), %rsi    # 0x131230
movq (%rsi,%rdx,8), %rdx
movw %cx, 0xe(%rdx)
addw $0x3, (%rax,%r12,2)
jmp 0x108d3
movl %r15d, (%rax,%r12,4)
jmp 0x108d3
leaq 0x11efce(%rip), %rax    # 0x12f3f0
cmpl $0x0, (%rax,%r12,4)
js 0x10431
movl $0x2, (%rax,%r12,4)
leaq 0xd4058(%rip), %rax     # 0xe4490
movb $0x1, %cl
movl %ecx, 0xc(%rsp)
testb $-0x80, (%rax,%r12,2)
je 0x1045b
leaq 0x11efa4(%rip), %rax    # 0x12f3f0
cmpl $0x1, (%rax,%r12,4)
jne 0x1045b
movl $0x2, (%rax,%r12,4)
leaq 0x11ef8e(%rip), %rax    # 0x12f3f0
movl (%rax,%r12,4), %r13d
cmpl $0x2, %r13d
jne 0x104a7
movl $0xffffffff, (%rax,%r12,4) # imm = 0xFFFFFFFF
leaq 0x11efb5(%rip), %rax    # 0x12f430
movl $0x0, (%rax,%r12,4)
leaq (%rdi,%rdi,8), %rax
leaq 0xc17c2(%rip), %rcx     # 0xd1c50
movswl 0x2(%rcx,%rax,2), %r14d
movswl (%rcx,%rax,2), %eax
subl %eax, %r14d
movl %r14d, (%rdx,%r12,4)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x104bf
leaq (%rdi,%rdi,8), %rax
leaq 0xc179e(%rip), %rcx     # 0xd1c50
movswl 0x2(%rcx,%rax,2), %r14d
movswl (%rcx,%rax,2), %eax
subl %eax, %r14d
leaq (%rdi,%rdi,8), %rax
leaq 0xc1786(%rip), %rcx     # 0xd1c50
leaq (%rcx,%rax,2), %r8
movl $0x4, %eax
cmpl %r14d, %esi
jle 0x104dd
movswl 0x10(%r8), %eax
leaq 0xd3fa4(%rip), %rcx     # 0xe4488
movl (%rcx), %ecx
leaq 0x11d153(%rip), %rdx    # 0x12d640
addl (%rdx,%r12,4), %eax
cmpl %eax, %ecx
jl 0x108d3
movq %r8, 0x18(%rsp)
movl %ecx, (%rdx,%r12,4)
movswl %bp, %ebp
movq %rdi, 0x20(%rsp)
movl %esi, 0x10(%rsp)
movl %ebp, %esi
callq 0xf2fa
movl 0x10(%rsp), %esi
cmpl %r14d, %esi
jle 0x105e7
testl %eax, %eax
leaq 0x11edb5(%rip), %rdx    # 0x12f2e0
je 0x10895
movl %eax, 0x14(%rsp)
movl %r14d, %eax
notl %eax
addl %esi, %eax
cltq
movq 0x18(%rsp), %rdi
cmpb $0x0, 0x7(%rdi,%rax)
je 0x10851
cmpl $0x7, %r15d
ja 0x107b1
movl %r15d, %eax
leaq 0x7ee52(%rip), %rcx     # 0x8f3b4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testb %bl, %bl
je 0x10786
leaq 0xd3f56(%rip), %rax     # 0xe44d0
movl (%rax,%r12,4), %esi
leaq 0xd3f8b(%rip), %rax     # 0xe4510
movl (%rax,%r12,4), %edx
movl $0x57, %edi
jmp 0x10767
leaq 0xd3ef6(%rip), %rax     # 0xe4490
movb 0x1(%rax,%r12,2), %dl
shrb $0x3, %dl
leaq 0x11ede7(%rip), %rax    # 0x12f390
movzwl (%rax,%r12,2), %ecx
testw %cx, %cx
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x105f3
leaq 0xd518b(%rip), %rcx     # 0xe5750
movswq (%rcx,%r12,2), %rcx
leaq 0x120c5f(%rip), %rdx    # 0x131230
movq (%rdx,%rcx,8), %rcx
movw $0x4ae, 0xe(%rcx)       # imm = 0x4AE
movw $0x10, (%rax,%r12,2)
jmp 0x10387
leaq 0x11ecf2(%rip), %rdx    # 0x12f2e0
jmp 0x10895
testw %cx, %cx
jle 0x10633
leal -0x1(%rcx), %edx
movw %dx, (%rax,%r12,2)
cmpw $0x1, %cx
jne 0x10387
movw $0x0, (%rax,%r12,2)
leaq 0xd5138(%rip), %rcx     # 0xe5750
movswq (%rcx,%r12,2), %rcx
leaq 0x120c0c(%rip), %rdx    # 0x131230
movq (%rdx,%rcx,8), %rcx
movw $0x3e7, 0xe(%rcx)       # imm = 0x3E7
movzwl (%rax,%r12,2), %ecx
testw %cx, %cx
jne 0x10387
leaq 0xd4efd(%rip), %rax     # 0xe5540
cmpb $0x0, (%rax,%r12)
jne 0x10387
leaq 0xd4f2b(%rip), %rax     # 0xe5580
cmpw $0x0, (%rax,%r12,2)
jne 0x10387
leaq 0xd50e8(%rip), %rax     # 0xe5750
movswq (%rax,%r12,2), %rax
leaq 0x120bbc(%rip), %rcx    # 0x131230
movq (%rcx,%rax,8), %rax
movw $0x3e2, 0xe(%rax)       # imm = 0x3E2
jmp 0x10387
testb %bl, %bl
je 0x10771
leaq 0xd3e3e(%rip), %rax     # 0xe44d0
movl (%rax,%r12,4), %esi
leaq 0xd3e73(%rip), %rax     # 0xe4510
movl (%rax,%r12,4), %edx
movl $0x5b, %edi
jmp 0x10767
testb %bl, %bl
je 0x10778
leaq 0xd3e16(%rip), %rax     # 0xe44d0
movl (%rax,%r12,4), %esi
leaq 0xd3e4b(%rip), %rax     # 0xe4510
movl (%rax,%r12,4), %edx
movl $0x59, %edi
jmp 0x10767
testb %bl, %bl
je 0x1077f
leaq 0xd3dee(%rip), %rax     # 0xe44d0
movl (%rax,%r12,4), %esi
leaq 0xd3e23(%rip), %rax     # 0xe4510
movl (%rax,%r12,4), %edx
movl $0x5a, %edi
jmp 0x10767
movl $0x5e, %edi
jmp 0x107a0
testb %bl, %bl
je 0x1078d
leaq 0xd3dbf(%rip), %rax     # 0xe44d0
movl (%rax,%r12,4), %esi
leaq 0xd3df4(%rip), %rax     # 0xe4510
movl (%rax,%r12,4), %edx
movl $0x58, %edi
jmp 0x10767
testb %bl, %bl
je 0x10794
leaq 0xd3d9e(%rip), %rax     # 0xe44d0
movl (%rax,%r12,4), %esi
leaq 0xd3dd3(%rip), %rax     # 0xe4510
movl (%rax,%r12,4), %edx
movl $0x5c, %edi
jmp 0x10767
testb %bl, %bl
je 0x1079b
leaq 0xd3d7d(%rip), %rax     # 0xe44d0
movl (%rax,%r12,4), %esi
leaq 0xd3db2(%rip), %rax     # 0xe4510
movl (%rax,%r12,4), %edx
movl $0x5d, %edi
xorl %ecx, %ecx
movl $0x4, %r8d
jmp 0x107ac
movl $0x5b, %edi
jmp 0x107a0
movl $0x59, %edi
jmp 0x107a0
movl $0x5a, %edi
jmp 0x107a0
movl $0x57, %edi
jmp 0x107a0
movl $0x58, %edi
jmp 0x107a0
movl $0x5c, %edi
jmp 0x107a0
movl $0x5d, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c370
leaq 0xd3d18(%rip), %rax     # 0xe44d0
movl (%rax,%r12,4), %esi
leaq 0xd3d4d(%rip), %rax     # 0xe4510
movl (%rax,%r12,4), %edx
leaq 0xd3d82(%rip), %rax     # 0xe4550
movl (%rax,%r12,4), %ecx
leaq 0xd3cd7(%rip), %rax     # 0xe44b0
movswl (%rax,%r12,2), %r8d
leaq 0xd507b(%rip), %rax     # 0xe5860
movl (%rax,%r12,4), %r9d
leaq 0xd4f30(%rip), %rax     # 0xe5720
movswl (%rax,%r12,2), %eax
movsbl 0x20(%rsp), %r10d
movl %ebp, %edi
pushq %r10
pushq %rax
callq 0xf600
addq $0x10, %rsp
leaq 0xc1168(%rip), %rax     # 0xd1978
cmpb $0x0, 0x4(%rax)
leaq 0x11eac5(%rip), %rdx    # 0x12f2e0
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %rdi
je 0x10851
leaq 0xd4f23(%rip), %rax     # 0xe5750
movswq (%rax,%r12,2), %rax
leaq 0x1209f7(%rip), %rcx    # 0x131230
movq (%rcx,%rax,8), %rax
movw $0x4af, 0xe(%rax)       # imm = 0x4AF
leaq 0x11eb46(%rip), %rax    # 0x12f390
movw $0x8, (%rax,%r12,2)
movswl 0x4(%rdi), %eax
movswl (%rdi), %ecx
subl %ecx, %eax
cmpl %eax, %esi
jle 0x10863
incl %r14d
jmp 0x10879
cmpb $0x0, 0xc(%rsp)
je 0x1087f
leaq 0x11eb7f(%rip), %rax    # 0x12f3f0
movl $0x1, (%rax,%r12,4)
movl %r14d, (%rdx,%r12,4)
jmp 0x108d3
leaq 0x11eb6a(%rip), %rax    # 0x12f3f0
movl $0x0, (%rax,%r12,4)
xorl %r13d, %r13d
movl 0x14(%rsp), %eax
leaq 0x11eb94(%rip), %rcx    # 0x12f430
cmpl $0x0, (%rcx,%r12,4)
je 0x108c4
cmpl %r14d, %esi
jl 0x108cd
testl %eax, %eax
jne 0x108cd
cmpb $0x0, 0xc(%rsp)
je 0x108cf
leaq 0x11eb36(%rip), %rax    # 0x12f3f0
movl $0x1, (%rax,%r12,4)
jmp 0x108cf
sarl $0x1f, %r13d
addl %r13d, %esi
jmp 0x108cf
incl %esi
movl %esi, (%rdx,%r12,4)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq