// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movl %esi, %ebp
movl %edi, %r15d
cmpl $0x8, %edi
jb 0x1033e
movswl %bp, %edx
leaq 0x7c0d1(%rip), %rdi     # 0x8c405
movl %r15d, %esi
xorl %eax, %eax
callq 0x2d800
leaq 0xbe633(%rip), %rax     # 0xce978
movb 0x4(%rax), %bl
movswq %bp, %r12
testb %bl, %bl
je 0x10490
leaq 0xd1235(%rip), %rax     # 0xe1590
cmpl $0x0, (%rax,%r12,4)
leaq 0x11c009(%rip), %rax    # 0x12c370
jns 0x10375
cmpw $0x0, (%rax,%r12,2)
je 0x1041a
movzwl (%rax,%r12,2), %ecx
testw %cx, %cx
jle 0x103b7
movzwl %cx, %ecx
imull $0xcccd, %ecx, %ecx     # imm = 0xCCCD
shrl $0x14, %ecx
addl $0x3fb, %ecx            # imm = 0x3FB
leaq 0xd23b8(%rip), %rdx     # 0xe2750
movswq (%rdx,%r12,2), %rdx
leaq 0x11de6c(%rip), %rsi    # 0x12e210
movq (%rsi,%rdx,8), %rdx
movw %cx, 0xe(%rdx)
addw $0x3, (%rax,%r12,2)
jmp 0x1087b
leaq 0xd10d2(%rip), %rax     # 0xe1490
testb $0x8, 0x1(%rax,%r12,2)
je 0x103d5
leaq 0x11bfc3(%rip), %rax    # 0x12c390
cmpw $0x0, (%rax,%r12,2)
je 0x10423
leaq 0x11bfb4(%rip), %rax    # 0x12c390
movzwl (%rax,%r12,2), %ecx
testw %cx, %cx
jle 0x10447
leal -0x1(%rcx), %edx
movw %dx, (%rax,%r12,2)
cmpw $0x1, %cx
jne 0x10447
movw $0x0, (%rax,%r12,2)
leaq 0xd234e(%rip), %rax     # 0xe2750
movswq (%rax,%r12,2), %rax
leaq 0x11de02(%rip), %rcx    # 0x12e210
movq (%rcx,%rax,8), %rax
movw $0x3e7, 0xe(%rax)       # imm = 0x3E7
jmp 0x10447
movw $0x3, (%rax,%r12,2)
jmp 0x10490
leaq 0xd2326(%rip), %rcx     # 0xe2750
movswq (%rcx,%r12,2), %rcx
leaq 0x11ddda(%rip), %rdx    # 0x12e210
movq (%rdx,%rcx,8), %rcx
movw $0x4ae, 0xe(%rcx)       # imm = 0x4AE
movw $0x10, (%rax,%r12,2)
leaq 0x11bf42(%rip), %rax    # 0x12c390
cmpw $0x0, (%rax,%r12,2)
jne 0x10490
leaq 0xd20e3(%rip), %rax     # 0xe2540
cmpb $0x0, (%rax,%r12)
jne 0x10490
leaq 0xd2115(%rip), %rax     # 0xe2580
cmpw $0x0, (%rax,%r12,2)
jne 0x10490
leaq 0xd22d6(%rip), %rax     # 0xe2750
movswq (%rax,%r12,2), %rax
leaq 0x11dd8a(%rip), %rcx    # 0x12e210
movq (%rcx,%rax,8), %rax
movw $0x3e2, 0xe(%rax)       # imm = 0x3E2
leaq 0x11be49(%rip), %rsi    # 0x12c2e0
movl (%rsi,%r12,4), %r14d
leaq 0x11bf0e(%rip), %rax    # 0x12c3b0
testl %r14d, %r14d
je 0x104d4
movslq (%rax,%r12,4), %rdi
cmpl %r15d, %edi
jne 0x104dd
leaq 0xd0fd9(%rip), %rax     # 0xe1490
movb $0x1, %cl
testb $0x8, 0x1(%rax,%r12,2)
je 0x104f5
leaq 0x11bf68(%rip), %rax    # 0x12c430
movl $0x1, (%rax,%r12,4)
xorl %ecx, %ecx
jmp 0x104f5
movl %r15d, (%rax,%r12,4)
jmp 0x1087b
leaq 0x11bf0c(%rip), %rax    # 0x12c3f0
movb $0x1, %cl
cmpl $0x0, (%rax,%r12,4)
js 0x104f5
movl $0x2, (%rax,%r12,4)
movl %ecx, (%rsp)
testb %cl, %cl
je 0x10520
leaq 0xd0f8d(%rip), %rax     # 0xe1490
testb $-0x80, (%rax,%r12,2)
je 0x10520
leaq 0x11bedf(%rip), %rax    # 0x12c3f0
cmpl $0x1, (%rax,%r12,4)
jne 0x10520
movl $0x2, (%rax,%r12,4)
leaq 0x11bec9(%rip), %rax    # 0x12c3f0
cmpl $0x2, (%rax,%r12,4)
jne 0x1055f
movl $0xffffffff, (%rax,%r12,4) # imm = 0xFFFFFFFF
leaq 0x11bef3(%rip), %rax    # 0x12c430
movl $0x0, (%rax,%r12,4)
leaq (%rdi,%rdi,8), %rax
leaq 0xbe700(%rip), %rcx     # 0xcec50
movswl 0x2(%rcx,%rax,2), %edx
movswl (%rcx,%rax,2), %eax
subl %eax, %edx
movl %edx, (%rsi,%r12,4)
leaq (%rdi,%rdi,8), %rax
leaq 0xbe6e6(%rip), %rcx     # 0xcec50
leaq (%rcx,%rax,2), %rsi
movswl 0x2(%rsi), %r13d
movswl (%rsi), %eax
subl %eax, %r13d
movl $0x4, %eax
cmpl %r13d, %r14d
jle 0x10587
movswl 0x10(%rsi), %eax
leaq 0xd0efa(%rip), %rcx     # 0xe1488
movl (%rcx), %ecx
leaq 0x11a0a9(%rip), %rdx    # 0x12a640
addl (%rdx,%r12,4), %eax
cmpl %eax, %ecx
jl 0x1087b
movq %rsi, 0x8(%rsp)
movl %ecx, (%rdx,%r12,4)
movswl %bp, %ebp
movq %rdi, 0x10(%rsp)
movl %ebp, %esi
callq 0xf2da
leaq 0x11be2e(%rip), %rsi    # 0x12c3f0
leaq 0x11bd17(%rip), %rdx    # 0x12c2e0
cmpl %r13d, %r14d
jle 0x10841
testl %eax, %eax
je 0x10841
movl %eax, 0x4(%rsp)
movl %r13d, %eax
notl %eax
addl %r14d, %eax
cltq
movq 0x8(%rsp), %rdi
cmpb $0x0, 0x7(%rdi,%rax)
je 0x1080e
cmpl $0x7, %r15d
ja 0x1076b
movl %r15d, %eax
leaq 0x7bd94(%rip), %rcx     # 0x8c3a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testb %bl, %bl
je 0x10740
leaq 0xd0eac(%rip), %rax     # 0xe14d0
movl (%rax,%r12,4), %esi
leaq 0xd0ee1(%rip), %rax     # 0xe1510
movl (%rax,%r12,4), %edx
movl $0x57, %edi
jmp 0x10721
testb %bl, %bl
je 0x1072b
leaq 0xd0e84(%rip), %rax     # 0xe14d0
movl (%rax,%r12,4), %esi
leaq 0xd0eb9(%rip), %rax     # 0xe1510
movl (%rax,%r12,4), %edx
movl $0x5b, %edi
jmp 0x10721
testb %bl, %bl
je 0x10732
leaq 0xd0e5c(%rip), %rax     # 0xe14d0
movl (%rax,%r12,4), %esi
leaq 0xd0e91(%rip), %rax     # 0xe1510
movl (%rax,%r12,4), %edx
movl $0x59, %edi
jmp 0x10721
testb %bl, %bl
je 0x10739
leaq 0xd0e34(%rip), %rax     # 0xe14d0
movl (%rax,%r12,4), %esi
leaq 0xd0e69(%rip), %rax     # 0xe1510
movl (%rax,%r12,4), %edx
movl $0x5a, %edi
jmp 0x10721
movl $0x5e, %edi
jmp 0x1075a
testb %bl, %bl
je 0x10747
leaq 0xd0e05(%rip), %rax     # 0xe14d0
movl (%rax,%r12,4), %esi
leaq 0xd0e3a(%rip), %rax     # 0xe1510
movl (%rax,%r12,4), %edx
movl $0x58, %edi
jmp 0x10721
testb %bl, %bl
je 0x1074e
leaq 0xd0de4(%rip), %rax     # 0xe14d0
movl (%rax,%r12,4), %esi
leaq 0xd0e19(%rip), %rax     # 0xe1510
movl (%rax,%r12,4), %edx
movl $0x5c, %edi
jmp 0x10721
testb %bl, %bl
je 0x10755
leaq 0xd0dc3(%rip), %rax     # 0xe14d0
movl (%rax,%r12,4), %esi
leaq 0xd0df8(%rip), %rax     # 0xe1510
movl (%rax,%r12,4), %edx
movl $0x5d, %edi
xorl %ecx, %ecx
movl $0x4, %r8d
jmp 0x10766
movl $0x5b, %edi
jmp 0x1075a
movl $0x59, %edi
jmp 0x1075a
movl $0x5a, %edi
jmp 0x1075a
movl $0x57, %edi
jmp 0x1075a
movl $0x58, %edi
jmp 0x1075a
movl $0x5c, %edi
jmp 0x1075a
movl $0x5d, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c1f1
leaq 0xd0d5e(%rip), %rax     # 0xe14d0
movl (%rax,%r12,4), %esi
leaq 0xd0d93(%rip), %rax     # 0xe1510
movl (%rax,%r12,4), %edx
leaq 0xd0dc8(%rip), %rax     # 0xe1550
movl (%rax,%r12,4), %ecx
leaq 0xd0d1d(%rip), %rax     # 0xe14b0
movswl (%rax,%r12,2), %r8d
leaq 0xd20c1(%rip), %rax     # 0xe2860
movl (%rax,%r12,4), %r9d
leaq 0xd1f76(%rip), %rax     # 0xe2720
movswl (%rax,%r12,2), %eax
movsbl 0x10(%rsp), %r10d
movl %ebp, %edi
pushq %r10
pushq %rax
callq 0xf5e4
addq $0x10, %rsp
leaq 0xbe1ae(%rip), %rax     # 0xce978
cmpb $0x0, 0x4(%rax)
leaq 0x11bb0b(%rip), %rdx    # 0x12c2e0
leaq 0x11bc14(%rip), %rsi    # 0x12c3f0
movq 0x8(%rsp), %rdi
je 0x1080e
leaq 0xd1f66(%rip), %rax     # 0xe2750
movswq (%rax,%r12,2), %rax
leaq 0x11da1a(%rip), %rcx    # 0x12e210
movq (%rcx,%rax,8), %rax
movw $0x4af, 0xe(%rax)       # imm = 0x4AF
leaq 0x11bb89(%rip), %rax    # 0x12c390
movw $0x8, (%rax,%r12,2)
movswl 0x4(%rdi), %eax
movswl (%rdi), %ecx
subl %ecx, %eax
cmpl %eax, %r14d
jle 0x10821
incl %r13d
jmp 0x1082f
cmpb $0x0, (%rsp)
je 0x10835
movl $0x1, (%rsi,%r12,4)
movl %r13d, (%rdx,%r12,4)
jmp 0x1087b
movl $0x0, (%rsi,%r12,4)
movl 0x4(%rsp), %eax
leaq 0x11bbe8(%rip), %rcx    # 0x12c430
cmpl $0x0, (%rcx,%r12,4)
je 0x10868
cmpl %r13d, %r14d
jl 0x10874
testl %eax, %eax
jne 0x10874
cmpb $0x0, (%rsp)
je 0x10877
movl $0x1, (%rsi,%r12,4)
jmp 0x10877
movl (%rsi,%r12,4), %eax
sarl $0x1f, %eax
addl %eax, %r14d
jmp 0x10877
incl %r14d
movl %r14d, (%rdx,%r12,4)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq