// File: /workspace/github_c_makefile_star2_O2/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
movswl %bp, %r13d
cmpl $0x8, %edi
jb 0xf343
leaq 0x720e3(%rip), %rdi     # 0x81419
movl %r15d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x2acb8
leaq 0xb862e(%rip), %rax     # 0xc7978
movb 0x4(%rax), %r14b
movswq %bp, %r12
testb %r14b, %r14b
je 0xf389
leaq 0xcb232(%rip), %rax     # 0xda590
cmpl $0x0, (%rax,%r12,4)
sets %dl
leaq 0x116003(%rip), %rcx    # 0x125370
movzwl (%rcx,%r12,2), %eax
testw %ax, %ax
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xf3d3
movw $0x3, (%rcx,%r12,2)
leaq 0x115f50(%rip), %rdx    # 0x1252e0
movl (%rdx,%r12,4), %esi
leaq 0x116015(%rip), %rax    # 0x1253b0
testl %esi, %esi
je 0xf410
movslq (%rax,%r12,4), %rdi
cmpl %r15d, %edi
jne 0xf419
leaq 0xcb0e1(%rip), %rax     # 0xda490
testb $0x8, 0x1(%rax,%r12,2)
je 0xf42f
leaq 0x116072(%rip), %rax    # 0x125430
movl $0x1, (%rax,%r12,4)
movl $0x0, 0xc(%rsp)
jmp 0xf459
testw %ax, %ax
jle 0xf583
movw $0x14, %si
xorl %edx, %edx
divw %si
addl $0x3fb, %eax            # imm = 0x3FB
leaq 0xcc35f(%rip), %rdx     # 0xdb750
movswq (%rdx,%r12,2), %rdx
leaq 0x117e33(%rip), %rsi    # 0x127230
movq (%rsi,%rdx,8), %rdx
movw %ax, 0xe(%rdx)
addw $0x3, (%rcx,%r12,2)
jmp 0xf893
movl %r15d, (%rax,%r12,4)
jmp 0xf893
leaq 0x115fd0(%rip), %rax    # 0x1253f0
cmpl $0x0, (%rax,%r12,4)
js 0xf42f
movl $0x2, (%rax,%r12,4)
leaq 0xcb05a(%rip), %rax     # 0xda490
movb $0x1, %cl
movl %ecx, 0xc(%rsp)
testb $-0x80, (%rax,%r12,2)
je 0xf459
leaq 0x115fa6(%rip), %rax    # 0x1253f0
cmpl $0x1, (%rax,%r12,4)
jne 0xf459
movl $0x2, (%rax,%r12,4)
leaq 0x115f90(%rip), %rax    # 0x1253f0
movl (%rax,%r12,4), %ebx
leaq 0x115fc5(%rip), %rcx    # 0x125430
cmpl $0x2, %ebx
jne 0xf499
orl $-0x1, (%rax,%r12,4)
andl $0x0, (%rcx,%r12,4)
imulq $0x12, %rdi, %rax
leaq 0xb87cb(%rip), %rcx     # 0xc7c50
movswl 0x2(%rax,%rcx), %ebp
movswl (%rax,%rcx), %eax
subl %eax, %ebp
movl %ebp, (%rdx,%r12,4)
pushq $-0x1
popq %rbx
jmp 0xf4af
imulq $0x12, %rdi, %rax
leaq 0xb87ac(%rip), %rcx     # 0xc7c50
movswl 0x2(%rax,%rcx), %ebp
movswl (%rax,%rcx), %eax
subl %eax, %ebp
imulq $0x12, %rdi, %rax
leaq 0xb8796(%rip), %r8      # 0xc7c50
addq %rax, %r8
cmpl %ebp, %esi
jle 0xf4c8
movswl 0x10(%r8), %eax
jmp 0xf4cb
pushq $0x4
popq %rax
leaq 0xcafb6(%rip), %rcx     # 0xda488
movl (%rcx), %ecx
leaq 0x114165(%rip), %rdx    # 0x123640
addl (%rdx,%r12,4), %eax
cmpl %eax, %ecx
jl 0xf893
movq %r8, 0x18(%rsp)
movl %ecx, (%rdx,%r12,4)
movq %rdi, 0x20(%rsp)
movl %esi, 0x10(%rsp)
movl %r13d, %esi
callq 0xe3a7
movl 0x10(%rsp), %esi
cmpl %ebp, %esi
jle 0xf5d7
testl %eax, %eax
leaq 0x115dca(%rip), %rdx    # 0x1252e0
leaq 0x115f13(%rip), %rdi    # 0x125430
je 0xf85f
movl %eax, 0x14(%rsp)
movl %ebp, %eax
notl %eax
addl %esi, %eax
cltq
movq 0x18(%rsp), %r8
cmpb $0x0, 0x7(%r8,%rax)
je 0xf81e
cmpl $0x7, %r15d
ja 0xf778
movl %r15d, %eax
leaq 0x71e60(%rip), %rcx     # 0x813b4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testb %r14b, %r14b
je 0xf75a
leaq 0xcaf63(%rip), %rax     # 0xda4d0
movl (%rax,%r12,4), %esi
leaq 0xcaf98(%rip), %rax     # 0xda510
movl (%rax,%r12,4), %edx
pushq $0x57
jmp 0xf747
leaq 0xcaf06(%rip), %rax     # 0xda490
movb 0x1(%rax,%r12,2), %dl
shrb $0x3, %dl
leaq 0x115df7(%rip), %rax    # 0x125390
movzwl (%rax,%r12,2), %ecx
testw %cx, %cx
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xf5ea
leaq 0xcc19b(%rip), %rcx     # 0xdb750
movswq (%rcx,%r12,2), %rcx
leaq 0x117c6f(%rip), %rdx    # 0x127230
movq (%rdx,%rcx,8), %rcx
movw $0x4ae, 0xe(%rcx)       # imm = 0x4AE
movw $0x10, (%rax,%r12,2)
jmp 0xf389
leaq 0x115d02(%rip), %rdx    # 0x1252e0
leaq 0x115e4b(%rip), %rdi    # 0x125430
jmp 0xf85f
testw %cx, %cx
jle 0xf629
leal -0x1(%rcx), %edx
movw %dx, (%rax,%r12,2)
cmpw $0x1, %cx
jne 0xf389
andw $0x0, (%rax,%r12,2)
leaq 0xcc142(%rip), %rcx     # 0xdb750
movswq (%rcx,%r12,2), %rcx
leaq 0x117c16(%rip), %rdx    # 0x127230
movq (%rdx,%rcx,8), %rcx
movw $0x3e7, 0xe(%rcx)       # imm = 0x3E7
movzwl (%rax,%r12,2), %ecx
testw %cx, %cx
jne 0xf389
leaq 0xcbf07(%rip), %rax     # 0xdb540
cmpb $0x0, (%rax,%r12)
jne 0xf389
leaq 0xcbf35(%rip), %rax     # 0xdb580
cmpw $0x0, (%rax,%r12,2)
jne 0xf389
leaq 0xcc0f2(%rip), %rax     # 0xdb750
movswq (%rax,%r12,2), %rax
leaq 0x117bc6(%rip), %rcx    # 0x127230
movq (%rcx,%rax,8), %rax
movw $0x3e2, 0xe(%rax)       # imm = 0x3E2
jmp 0xf389
testb %r14b, %r14b
je 0xf74e
leaq 0xcae47(%rip), %rax     # 0xda4d0
movl (%rax,%r12,4), %esi
leaq 0xcae7c(%rip), %rax     # 0xda510
movl (%rax,%r12,4), %edx
pushq $0x5b
jmp 0xf747
testb %r14b, %r14b
je 0xf752
leaq 0xcae21(%rip), %rax     # 0xda4d0
movl (%rax,%r12,4), %esi
leaq 0xcae56(%rip), %rax     # 0xda510
movl (%rax,%r12,4), %edx
pushq $0x59
jmp 0xf747
testb %r14b, %r14b
je 0xf756
leaq 0xcadfb(%rip), %rax     # 0xda4d0
movl (%rax,%r12,4), %esi
leaq 0xcae30(%rip), %rax     # 0xda510
movl (%rax,%r12,4), %edx
pushq $0x5a
jmp 0xf747
pushq $0x5e
jmp 0xf768
testb %r14b, %r14b
je 0xf75e
leaq 0xcadd8(%rip), %rax     # 0xda4d0
movl (%rax,%r12,4), %esi
leaq 0xcae0d(%rip), %rax     # 0xda510
movl (%rax,%r12,4), %edx
pushq $0x58
jmp 0xf747
testb %r14b, %r14b
je 0xf762
leaq 0xcadb9(%rip), %rax     # 0xda4d0
movl (%rax,%r12,4), %esi
leaq 0xcadee(%rip), %rax     # 0xda510
movl (%rax,%r12,4), %edx
pushq $0x5c
jmp 0xf747
testb %r14b, %r14b
je 0xf766
leaq 0xcad9a(%rip), %rax     # 0xda4d0
movl (%rax,%r12,4), %esi
leaq 0xcadcf(%rip), %rax     # 0xda510
movl (%rax,%r12,4), %edx
pushq $0x5d
popq %rdi
pushq $0x4
popq %r8
jmp 0xf771
pushq $0x5b
jmp 0xf768
pushq $0x59
jmp 0xf768
pushq $0x5a
jmp 0xf768
pushq $0x57
jmp 0xf768
pushq $0x58
jmp 0xf768
pushq $0x5c
jmp 0xf768
pushq $0x5d
popq %rdi
pushq $0x1
popq %r8
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1ab2a
leaq 0xcad51(%rip), %rax     # 0xda4d0
movl (%rax,%r12,4), %esi
leaq 0xcad86(%rip), %rax     # 0xda510
movl (%rax,%r12,4), %edx
leaq 0xcadbb(%rip), %rax     # 0xda550
movl (%rax,%r12,4), %ecx
leaq 0xcad10(%rip), %rax     # 0xda4b0
movswl (%rax,%r12,2), %r8d
leaq 0xcc0b4(%rip), %rax     # 0xdb860
movl (%rax,%r12,4), %r9d
leaq 0xcbf69(%rip), %rax     # 0xdb720
movswl (%rax,%r12,2), %eax
movsbl 0x20(%rsp), %r10d
movl %r13d, %edi
pushq %r10
pushq %rax
callq 0xe65a
popq %rax
popq %rcx
leaq 0xb81a2(%rip), %rax     # 0xc7978
cmpb $0x0, 0x4(%rax)
leaq 0x115aff(%rip), %rdx    # 0x1252e0
movl 0x10(%rsp), %esi
leaq 0x115c44(%rip), %rdi    # 0x125430
movq 0x18(%rsp), %r8
je 0xf81e
leaq 0xcbf56(%rip), %rax     # 0xdb750
movswq (%rax,%r12,2), %rax
leaq 0x117a2a(%rip), %rcx    # 0x127230
movq (%rcx,%rax,8), %rax
movw $0x4af, 0xe(%rax)       # imm = 0x4AF
leaq 0x115b79(%rip), %rax    # 0x125390
movw $0x8, (%rax,%r12,2)
movswl 0x4(%r8), %eax
movswl (%r8), %ecx
subl %ecx, %eax
cmpl %eax, %esi
jle 0xf831
incl %ebp
jmp 0xf847
cmpb $0x0, 0xc(%rsp)
je 0xf84d
leaq 0x115bb1(%rip), %rax    # 0x1253f0
movl $0x1, (%rax,%r12,4)
movl %ebp, (%rdx,%r12,4)
jmp 0xf893
leaq 0x115b9c(%rip), %rax    # 0x1253f0
andl $0x0, (%rax,%r12,4)
xorl %ebx, %ebx
movl 0x14(%rsp), %eax
cmpl $0x0, (%rdi,%r12,4)
je 0xf886
cmpl %ebp, %esi
jl 0xf88d
testl %eax, %eax
jne 0xf88d
cmpb $0x0, 0xc(%rsp)
je 0xf88f
leaq 0x115b74(%rip), %rax    # 0x1253f0
movl $0x1, (%rax,%r12,4)
jmp 0xf88f
sarl $0x1f, %ebx
addl %ebx, %esi
jmp 0xf88f
incl %esi
movl %esi, (%rdx,%r12,4)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq