// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/src/tektag.c
// Function: tektagcode
void
tektagcode(void)
{
     int            floorz,hi,i,j,k,lo,oldang,p,r,s,tics;
     int           dax,dax2,day,day2,endwall,startwall;
     unsigned int  effect;
     sectortype     *sect;
     struct    sectoreffect   *septr;

     for( p=connecthead; p >= 0; p=connectpoint2[p] ) {
          tekanimweap((syncbits[p]>>13)&15,p);
          tekhealstun(p);
     }

     for( i=0; i < numdoors; i++ ) {
          movedoors(i);
     }

     if( option[4] == 0 ) {
          for( i=0; i < secnt; i++ ) {
               s=sexref[i];
              if (s < 0 || s >= numsectors) {
                   crashgame("tag1402: Invalid sector effect index (%d,e=%d)",s,i);
              }
               sect=sectptr[s];
               septr=septrlist[s];
               if( septr->triggerable != 0 ) {
                    continue;
               }
               effect=septr->sectorflags;
               if( (effect&flags32[WPANNING]) != 0 ) {
                    oldang=septr->ang;
                    tics=TICSPERFRAME;
                    startwall=sect->wallptr;
                    endwall=startwall+sect->wallnum-1;
                    dax=(tics*septr->cos)>>15;
                    day=(tics*septr->sin)>>13;
                    for( j=startwall; j <= endwall; j++ ) {
                         wallptr[j]->xpanning+=(unsigned char)dax;
                         wallptr[j]->ypanning-=(unsigned char)day;
                    }
               }
               if( (effect&flags32[FPANNING]) != 0 ) {
                    tics=TICSPERFRAME;
                    dax=(tics*septr->cos);
                    day=(tics*septr->sin);
                    j=headspritesect[s];
                    while( j != -1 ) {
                         k=nextspritesect[j];
                         if( sprptr[j]->owner < MAXSPRITES ) {
                              dax2=dax>>10;
                              day2=day>>10;
                              movesprite(j,dax2,day2,0,4<<8,4<<8,0);
                         }
                         j=k;
                    }
                    for( p=connecthead; p >= 0; p=connectpoint2[p] ) {
                         if( cursectnum[p] == s ) {
                              if( posz[p] >= (sect->floorz-(42<<8)) ) {
                                   clipmove(&posx[p],&posy[p],&posz[p],
                                            &cursectnum[p],dax<<4,day<<4,128L,4<<8,4<<8,CLIPMASK0);
                                   setsprite(playersprite[p],posx[p],posy[p],posz[p]+(42<<8));
                                   revolvedoorstat[p]=1;
                              }
                         }
                    }
                    dax>>=12;
                    day>>=12;
                    sect->floorxpanning-=(unsigned char)dax;
                    sect->floorypanning+=(unsigned char)day;
               }
               if( (effect&flags32[CPANNING]) != 0 ) {
                    tics=TICSPERFRAME;
                    dax=(tics*septr->cos)>>12;
                    day=(tics*septr->sin)>>12;
                    sect->ceilingxpanning-=(unsigned char)dax;
                    sect->ceilingypanning+=(unsigned char)day;
               }
               if( (septr->delay-=TICSPERFRAME) > 0 ) {
                    continue;
               }
               // negative overflow here without this - jeffy
               if( septr->delay < 0 ) {
                    septr->delay=0;
               }
               septr->delay+=septr->delayreset;
               if( (effect&flags32[PULSELIGHT]) != 0 ) {
                    sect->ceilingshade+=septr->animate;
                    if( septr->hi > septr->lo ) {
                         hi=septr->hi;
                         lo=septr->lo;
                    }
                    else {
                         hi=septr->lo;
                         lo=septr->hi;
                    }
                    if( septr->animate < 0 ) {
                         if( sect->ceilingshade <= lo ) {
                              septr->animate=abs(septr->animate);
                         }
                    }
                    else {
                         if( sect->ceilingshade >= hi ) {
                              septr->animate=-septr->animate;
                         }
                    }
                    sect->floorshade=sect->ceilingshade;
                    startwall=sect->wallptr;
                    endwall=startwall+sect->wallnum-1;
                    for( j=startwall; j <= endwall; j++ ) {
                         wallptr[j]->shade=sect->ceilingshade;
                    }
               }
               else if( (effect&flags32[FLICKERLIGHT]) != 0 ) {
                   r=krand_intercept("TAG 1491");
                    if( r < 16384 ) {
                         sect->ceilingshade=septr->hi;
                    }
                    else if( r > 16384 ) {
                         sect->ceilingshade=septr->lo;
                    }
                    sect->floorshade=sect->ceilingshade;
                    startwall=sect->wallptr;
                    endwall=startwall+sect->wallnum-1;
                    for( j=startwall; j <= endwall; j++ ) {
                         wallptr[j]->shade=sect->ceilingshade;
                    }
               }
               else if( (effect&flags32[FLICKERDELAY]) != 0 ) {
                    if( sect->ceilingshade == septr->lo ) {
                         sect->ceilingshade=septr->hi;
                    }
                    else {
                         sect->ceilingshade=septr->lo;
                         septr->delay>>=2;
                    }
                    sect->floorshade=sect->ceilingshade;
                    startwall=sect->wallptr;
                    endwall=startwall+sect->wallnum-1;
                    for( j=startwall; j <= endwall; j++ ) {
                         wallptr[j]->shade=sect->ceilingshade;
                    }
               }
               else if( (effect&flags32[BLINKDELAY]) != 0 ) {
                    if( sect->ceilingshade == septr->lo ) {
                         sect->ceilingshade=septr->hi;
                    }
                    else {
                         sect->ceilingshade=septr->lo;
                    }
                    sect->floorshade=sect->ceilingshade;
                    startwall=sect->wallptr;
                    endwall=startwall+sect->wallnum-1;
                    for( j=startwall; j <= endwall; j++ ) {
                         wallptr[j]->shade=sect->ceilingshade;
                    }
               }
               if( (effect&flags32[KILLSECTOR]) != 0 ) {
                    floorz=sectptr[s]->floorz;
                    for( p=connecthead ; p >= 0 ; p=connectpoint2[p] ) {
                         if( cursectnum[p] == s ) {
                              // matrix specific check here
                              if( (klabs(posz[p] - floorz) < 10240) || (mission == 7) ) {
                                   if( (k=fdxref[s]) != -1 ) {
                                        if( floordoorptr[k]->state != DOORCLOSED ) {
                                             changehealth(p,-septr->damage);
                                             changescore(p,-10);
                                        }
                                   }
                                   else {
                                        if( septr->delay == septr->delayreset ) {
                                             changehealth(p,-septr->damage);
                                             changescore(p,-10);
                                        }
                                   }
                              }
                         }
                    }
               }
          }
     }

     if( option[4] == 0 ) {
          for( i=0; i < sprelevcnt; i++ ) {
               movesprelevs(i);
          }
          for( i=0; i < numfloordoors; i++ ) {
               movefloordoor(i);
          }
          for( i=0; i < numvehicles; i++ ) {
               movevehicles(i);
          }
     }

     tekdoanimpic();
     tekdodelayfuncs();
     if( (lockclock-ambupdateclock) > 120 ) {
          checkmapsndfx(screenpeek);
     }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x77bc67(%rip), %rax    # 0x7a5b30
movl (%rax), %eax
testl %eax, %eax
js 0x29f01
leaq 0xba5ba(%rip), %r14     # 0xe4490
leaq 0x77bc63(%rip), %r15    # 0x7a5b40
movl %eax, %r12d
movzwl (%r14,%r12,2), %edi
shrl $0xd, %edi
movswl %ax, %ebx
movl %ebx, %esi
callq 0x10317
movl %ebx, %edi
callq 0xa7a9
movl (%r15,%r12,4), %eax
testl %eax, %eax
jns 0x29edd
cmpl $0x0, 0x2f8508(%rip)    # 0x322410
jle 0x29f1d
xorl %ebx, %ebx
movl %ebx, %edi
callq 0x2bff1
incl %ebx
cmpl 0x2f84f5(%rip), %ebx    # 0x322410
jl 0x29f0c
leaq 0xa7a54(%rip), %rax     # 0xd1978
cmpb $0x0, 0x4(%rax)
je 0x29f74
callq 0x2de11
callq 0x2dee7
leaq 0xba54d(%rip), %rax     # 0xe4488
movl (%rax), %eax
subl 0x304bfd(%rip), %eax    # 0x32eb40
cmpl $0x79, %eax
jl 0x29f65
leaq 0xba50f(%rip), %rax     # 0xe445e
movswl (%rax), %edi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2bd7e
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x296579(%rip)    # 0x2c04f4
jle 0x2a4dc
leaq 0x296578(%rip), %r13    # 0x2c0500
leaq 0xbb791(%rip), %rbx     # 0xe5720
xorl %r15d, %r15d
movslq (%r13,%r15,4), %r12
testq %r12, %r12
js 0x29fab
leaq 0x556e3d(%rip), %rax    # 0x580de0
movswl (%rax), %eax
cmpl %eax, %r12d
jl 0x29fbf
leaq 0x66cde(%rip), %rdi     # 0x90c90
movl %r12d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x2eb88
leaq 0x2d653a(%rip), %rax    # 0x300500
movq (%rax,%r12,8), %rcx
cmpl $0x0, 0x1c(%rcx)
jne 0x2a4b8
leaq 0x1cf255(%rip), %rax    # 0x1f9230
movq (%rax,%r12,8), %rax
movq %rax, (%rsp)
movq %rcx, 0x8(%rsp)
movl (%rcx), %ebp
testl %ebp, 0xa890c(%rip)     # 0xd28fc
leaq 0x1d7239(%rip), %r8     # 0x201230
je 0x2a040
movq (%rsp), %rax
movswq 0x2(%rax), %rax
testq %rax, %rax
jle 0x2a040
movq (%rsp), %rcx
movswq (%rcx), %rcx
addq %rcx, %rax
movq 0x8(%rsp), %rsi
movl 0x30(%rsi), %edx
movl 0x34(%rsi), %esi
leal (%rdx,%rdx,2), %edx
shrl $0xd, %edx
leal (%rsi,%rsi,2), %esi
shrl $0xf, %esi
movq (%r8,%rcx,8), %rdi
addb %sil, 0x18(%rdi)
movq (%r8,%rcx,8), %rdi
subb %dl, 0x19(%rdi)
incq %rcx
cmpq %rax, %rcx
jl 0x2a029
testl %ebp, 0xa88ba(%rip)     # 0xd2900
movq 0x8(%rsp), %rdx
je 0x2a204
movl %ebp, 0x20(%rsp)
movl 0x30(%rdx), %ecx
movl 0x34(%rdx), %r14d
leal (%r14,%r14,2), %eax
movl %eax, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
leal (%rcx,%rcx,2), %eax
movl %eax, 0x14(%rsp)
leaq 0x533319(%rip), %rax    # 0x55d390
movzwl (%rax,%r12,2), %eax
cmpw $-0x1, %ax
je 0x2a0e1
movl 0x10(%rsp), %ebp
sarl $0xa, %ebp
movl 0x14(%rsp), %r13d
sarl $0xa, %r13d
movswq %ax, %rcx
leaq 0x53d303(%rip), %rdx    # 0x5673a0
movzwl (%rdx,%rcx,2), %ebx
leaq 0x107188(%rip), %rdx    # 0x131230
movq (%rdx,%rcx,8), %rcx
cmpw $0x3fff, 0x1e(%rcx)     # imm = 0x3FFF
jg 0x2a0d9
subq $0x8, %rsp
movswl %ax, %edi
movl %ebp, %esi
movl %r13d, %edx
xorl %ecx, %ecx
movl $0x400, %r8d            # imm = 0x400
movl $0x400, %r9d            # imm = 0x400
pushq $0x0
callq 0x1d136
addq $0x10, %rsp
movl %ebx, %eax
cmpw $-0x1, %bx
jne 0x2a092
leaq 0x77ba48(%rip), %rax    # 0x7a5b30
movl (%rax), %eax
testl %eax, %eax
leaq 0xbb62d(%rip), %rbx     # 0xe5720
movq (%rsp), %rdx
js 0x2a1e0
shll $0x4, %r14d
leal (%r14,%r14,2), %ecx
movl %ecx, 0x24(%rsp)
movq 0x18(%rsp), %rcx
shll $0x4, %ecx
leal (%rcx,%rcx,2), %ecx
movl %ecx, 0x18(%rsp)
movl %eax, %r13d
movswl (%rbx,%r13,2), %eax
cmpl %eax, %r12d
jne 0x2a1cd
movl 0x8(%rdx), %eax
movl $0xffffd600, %ecx       # imm = 0xFFFFD600
addl %ecx, %eax
leaq 0xba416(%rip), %rcx     # 0xe4550
cmpl %eax, (%rcx,%r13,4)
jl 0x2a1cd
leaq (%rbx,%r13,2), %rcx
leaq 0xba401(%rip), %rax     # 0xe4550
leaq (%rax,%r13,4), %rbx
leaq 0xba376(%rip), %rax     # 0xe44d0
leaq (%rax,%r13,4), %r14
leaq 0xba3ab(%rip), %rax     # 0xe4510
leaq (%rax,%r13,4), %rbp
movq %r14, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movl 0x24(%rsp), %r8d
movl 0x18(%rsp), %r9d
pushq $0x10001                # imm = 0x10001
movl $0x400, %eax            # imm = 0x400
pushq %rax
pushq %rax
pushq $0x80
callq 0x4acdd
addq $0x20, %rsp
leaq 0xbb5b3(%rip), %rax     # 0xe5750
movswl (%rax,%r13,2), %edi
movl (%r14), %esi
movl (%rbp), %edx
movl (%rbx), %ecx
leaq 0xbb56f(%rip), %rbx     # 0xe5720
movl $0x2a00, %eax           # imm = 0x2A00
addl %eax, %ecx
callq 0x48ab4
movq (%rsp), %rdx
leaq 0xbb578(%rip), %rax     # 0xe5740
movb $0x1, (%rax,%r13)
leaq 0x77b96c(%rip), %rax    # 0x7a5b40
movl (%rax,%r13,4), %eax
testl %eax, %eax
jns 0x2a118
movl 0x10(%rsp), %eax
shrl $0xc, %eax
subb %al, 0x1e(%rdx)
movl 0x14(%rsp), %eax
shrl $0xc, %eax
addb %al, 0x1f(%rdx)
leaq 0x296305(%rip), %r13    # 0x2c0500
movq 0x8(%rsp), %rdx
movl 0x20(%rsp), %ebp
testl %ebp, 0xa86fa(%rip)     # 0xd2904
je 0x2a228
movl 0x30(%rdx), %eax
movl 0x34(%rdx), %ecx
leal (%rcx,%rcx,2), %ecx
shrl $0xc, %ecx
leal (%rax,%rax,2), %eax
movq (%rsp), %rsi
subb %cl, 0x16(%rsi)
shrl $0xc, %eax
addb %al, 0x17(%rsi)
movl 0x10(%rdx), %eax
leal -0x3(%rax), %ecx
movl %ecx, 0x10(%rdx)
cmpl $0x3, %eax
jg 0x2a4b8
movl 0x14(%rdx), %eax
movl %eax, 0x10(%rdx)
testl %ebp, 0xa86aa(%rip)     # 0xd28f0
je 0x2a2b9
movq (%rsp), %rax
movb 0x14(%rax), %sil
addb 0x4(%rdx), %sil
movb %sil, 0x14(%rax)
movl 0x4(%rdx), %eax
movq %rdx, %rcx
movl 0x8(%rdx), %edx
movl 0xc(%rcx), %ecx
movsbl %sil, %esi
testl %eax, %eax
js 0x2a2e9
cmpl %ecx, %edx
cmovgl %edx, %ecx
cmpl %esi, %ecx
leaq 0x1d6fb6(%rip), %rdi    # 0x201230
jg 0x2a286
negl %eax
movq 0x8(%rsp), %rcx
movl %eax, 0x4(%rcx)
movq (%rsp), %rdx
movb 0x14(%rdx), %al
movb %al, 0x1c(%rdx)
movswq 0x2(%rdx), %rcx
testq %rcx, %rcx
jle 0x2a3e4
movswq (%rdx), %rdx
addq %rdx, %rcx
movq (%rdi,%rdx,8), %rsi
movb %al, 0x14(%rsi)
incq %rdx
cmpq %rcx, %rdx
jl 0x2a2a5
jmp 0x2a3e4
testl %ebp, 0xa8635(%rip)     # 0xd28f4
je 0x2a2fb
leaq 0x669f7(%rip), %rdi     # 0x90cbf
callq 0x2d112
cmpl $0x3fff, %eax           # imm = 0x3FFF
leaq 0x1d6f57(%rip), %rdi    # 0x201230
jg 0x2a328
movq 0x8(%rsp), %rax
movb 0x8(%rax), %al
movq (%rsp), %rdx
jmp 0x2a340
cmpl %ecx, %edx
cmovll %edx, %ecx
cmpl %esi, %ecx
leaq 0x1d6f39(%rip), %rdi    # 0x201230
jge 0x2a27c
jmp 0x2a286
testl %ebp, 0xa8607(%rip)     # 0xd2908
leaq 0x1d6f28(%rip), %rdi    # 0x201230
je 0x2a36c
movq (%rsp), %rsi
movsbl 0x14(%rsi), %ecx
movl 0xc(%rdx), %eax
cmpl %ecx, %eax
jne 0x2a3b7
movb 0x8(%rdx), %al
movb %al, 0x14(%rsi)
jmp 0x2a3c1
cmpl $0x4000, %eax           # imm = 0x4000
movq 0x8(%rsp), %rax
movq (%rsp), %rdx
jne 0x2a33d
movb 0x14(%rdx), %al
jmp 0x2a343
movb 0xc(%rax), %al
movb %al, 0x14(%rdx)
movb %al, 0x1c(%rdx)
movswq 0x2(%rdx), %rcx
testq %rcx, %rcx
jle 0x2a3e4
movswq (%rdx), %rdx
addq %rdx, %rcx
movq (%rdi,%rdx,8), %rsi
movb %al, 0x14(%rsi)
incq %rdx
cmpq %rcx, %rdx
jl 0x2a35b
jmp 0x2a3e4
testl %ebp, 0xa859a(%rip)     # 0xd290c
movq (%rsp), %rax
je 0x2a3e4
movsbl 0x14(%rax), %ecx
movq 0x8(%rsp), %rdx
movl 0xc(%rdx), %eax
cmpl %ecx, %eax
jne 0x2a38b
movl 0x8(%rdx), %eax
movq (%rsp), %rdx
movb %al, 0x14(%rdx)
movb %al, 0x1c(%rdx)
movswq 0x2(%rdx), %rcx
testq %rcx, %rcx
jle 0x2a3e4
movswq (%rdx), %rdx
addq %rdx, %rcx
movq (%rdi,%rdx,8), %rsi
movb %al, 0x14(%rsi)
incq %rdx
cmpq %rcx, %rdx
jl 0x2a3a6
jmp 0x2a3e4
movb %al, 0x14(%rsi)
sarl $0x2, 0x10(%rdx)
movb 0x14(%rsi), %al
movb %al, 0x1c(%rsi)
movswq 0x2(%rsi), %rcx
testq %rcx, %rcx
jle 0x2a3e4
movswq (%rsi), %rdx
addq %rdx, %rcx
movq (%rdi,%rdx,8), %rsi
movb %al, 0x14(%rsi)
incq %rdx
cmpq %rcx, %rdx
jl 0x2a3d5
testl %ebp, 0xa852e(%rip)     # 0xd2918
movq 0x8(%rsp), %rdx
je 0x2a4b8
leaq 0x77b734(%rip), %rax    # 0x7a5b30
movl (%rax), %eax
testl %eax, %eax
js 0x2a4b8
leaq 0x1cee23(%rip), %rcx    # 0x1f9230
movq (%rcx,%r12,8), %rcx
movl 0x8(%rcx), %ebp
movl %eax, %r14d
movswl (%rbx,%r14,2), %eax
cmpl %eax, %r12d
jne 0x2a499
leaq 0xba128(%rip), %rax     # 0xe4550
movl (%rax,%r14,4), %eax
subl %ebp, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x2800, %ecx           # imm = 0x2800
jb 0x2a449
leaq 0x1050cc(%rip), %rax    # 0x12f510
cmpl $0x7, (%rax)
jne 0x2a499
leaq 0x2eb520(%rip), %rax    # 0x315970
movslq (%rax,%r12,4), %rax
cmpq $-0x1, %rax
je 0x2a4ae
leaq 0x2ef7cf(%rip), %rcx    # 0x319c30
movq (%rcx,%rax,8), %rax
cmpl $0x0, (%rax)
je 0x2a499
movzwl 0x38(%rdx), %eax
xorl %ecx, %ecx
subw %ax, %cx
movswl %cx, %esi
movswl %r14w, %ebx
movl %ebx, %edi
callq 0xa5e8
movl %ebx, %edi
leaq 0xbb296(%rip), %rbx     # 0xe5720
movl $0xfffffff6, %esi       # imm = 0xFFFFFFF6
callq 0xa723
movq 0x8(%rsp), %rdx
leaq 0x77b6a0(%rip), %rax    # 0x7a5b40
movl (%rax,%r14,4), %eax
testl %eax, %eax
jns 0x2a414
jmp 0x2a4b8
movl 0x10(%rdx), %eax
cmpl 0x14(%rdx), %eax
je 0x2a46a
jmp 0x2a499
incq %r15
movslq 0x296032(%rip), %rax    # 0x2c04f4
cmpq %rax, %r15
jl 0x29f92
leaq 0xa74a6(%rip), %rax     # 0xd1978
cmpb $0x0, 0x4(%rax)
jne 0x29f2a
cmpl $0x0, 0x303f3d(%rip)    # 0x32e420
jle 0x2a4f8
xorl %ebx, %ebx
movl %ebx, %edi
callq 0x2d174
incl %ebx
cmpl 0x303f2a(%rip), %ebx    # 0x32e420
jl 0x2a4e7
cmpl $0x0, 0x2eb461(%rip)    # 0x315960
jle 0x2a514
xorl %ebx, %ebx
movl %ebx, %edi
callq 0x2d336
incl %ebx
cmpl 0x2eb44e(%rip), %ebx    # 0x315960
jl 0x2a503
cmpl $0x0, 0x2f19c5(%rip)    # 0x31bee0
jle 0x29f2a
xorl %ebx, %ebx
movl %ebx, %edi
callq 0x2d5b8
incl %ebx
cmpl 0x2f19ae(%rip), %ebx    # 0x31bee0
jl 0x2a523
jmp 0x29f2a