// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/src/tektag.c
// Function: checkmapsndfx
void
checkmapsndfx(short p)
{

     int       i,s;
     int       dist;
     unsigned  int      effect;
     struct    sectoreffect   *septr;

     s=cursectnum[p];
     septr=septrlist[s];

     for( i=0; i<totalmapsndfx; i++ ) {
          switch(mapsndfxptr[i]->type) {
          case MAP_SFX_AMBIENT:
               dist=abs(posx[p]-mapsndfxptr[i]->x)+abs(posy[p]-mapsndfxptr[i]->y);
               if( (dist > AMBUPDATEDIST) && (mapsndfxptr[i]->id!=-1) ) {
                    stopsound(mapsndfxptr[i]->id);
                    mapsndfxptr[i]->id=-1;
               }
               else if( (dist < AMBUPDATEDIST) && (mapsndfxptr[i]->id==-1) )  {
                    mapsndfxptr[i]->id=playsound(mapsndfxptr[i]->snum, mapsndfxptr[i]->x,mapsndfxptr[i]->y, mapsndfxptr[i]->loops, ST_AMBUPDATE);
               }
               break;
          case MAP_SFX_SECTOR:
               if((cursectnum[p] != ocursectnum[p]) && (cursectnum[p] == mapsndfxptr[i]->sector) ) {
                   mapsndfxptr[i]->id=playsound(mapsndfxptr[i]->snum, mapsndfxptr[i]->x,mapsndfxptr[i]->y, mapsndfxptr[i]->loops, ST_UNIQUE);
               }
               break;
          default:
               break;
          }
     }

     if( !Bstrncasecmp("SUBWAY",boardfilename,6) ) {
          if( ambsubloop == -1 ) {
               ambsubloop=playsound(S_SUBSTATIONLOOP, 0, 0, -1, ST_IMMEDIATE);
          }
     }
     else {
          if( ambsubloop != -1 ) {
               stopsound(ambsubloop);
               ambsubloop=-1;
          }
     }

     if( septr != NULL ) {
          effect=septr->sectorflags;
          if( (effect&flags32[SOUNDON]) != 0 ) {
               for( i=0; i<totalmapsndfx; i++ ) {
                    if( mapsndfxptr[i]->type == MAP_SFX_TOGGLED ) {
                         if( sectptr[mapsndfxptr[i]->sector]->hitag == septr->hi ) {
                              if( mapsndfxptr[i]->id == -1 ) {
                                   mapsndfxptr[i]->id=playsound(mapsndfxptr[i]->snum, mapsndfxptr[i]->x,mapsndfxptr[i]->y, mapsndfxptr[i]->loops,ST_UNIQUE | ST_IMMEDIATE);;
                              }
                         }
                    }
               }
          }
          if( (effect&flags32[SOUNDOFF]) != 0 ) {
               for( i=0; i<totalmapsndfx; i++ ) {
                    if( mapsndfxptr[i]->type == MAP_SFX_TOGGLED ) {
                         if( sectptr[mapsndfxptr[i]->sector]->hitag == septr->hi ) {
                              if( mapsndfxptr[i]->id != -1 ) {
                                   stopsound(mapsndfxptr[i]->id);
                                   mapsndfxptr[i]->id=-1;
                              }
                         }
                    }
               }
          }
     }

//     ambupdateclock=totalclock;
     ambupdateclock=lockclock;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movslq %edi, %r14
leaq 0xb998d(%rip), %r15     # 0xe5720
movswq (%r15,%r14,2), %rax
leaq 0x2d4761(%rip), %rcx    # 0x300500
movq (%rcx,%rax,8), %rbx
cmpl $0x0, 0x294746(%rip)    # 0x2c04f0
jle 0x2be86
leaq 0x2f0029(%rip), %r12    # 0x31bde0
xorl %r13d, %r13d
leaq 0xb874f(%rip), %rbp     # 0xe4510
movq (%r12), %rax
movl 0x14(%rax), %ecx
cmpl $0x1, %ecx
je 0x2be1d
testl %ecx, %ecx
jne 0x2be6f
leaq 0xb86f4(%rip), %rcx     # 0xe44d0
movl (%rcx,%r14,4), %ecx
movl (%rax), %esi
movl 0x4(%rax), %edx
subl %esi, %ecx
movl %ecx, %edi
negl %edi
cmovsl %ecx, %edi
movl (%rbp,%r14,4), %r8d
subl %edx, %r8d
movl %r8d, %ecx
negl %ecx
cmovsl %r8d, %ecx
addl %edi, %ecx
cmpl $0xfa1, %ecx            # imm = 0xFA1
jb 0x2be49
movl 0x18(%rax), %edi
cmpl $-0x1, %edi
je 0x2be6f
callq 0x1c5b9
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2be68
movzwl (%r15,%r14,2), %ecx
leaq 0xb9957(%rip), %rdx     # 0xe5780
cmpw (%rdx,%r14,2), %cx
je 0x2be6f
cmpw 0x8(%rax), %cx
jne 0x2be6f
movl 0xc(%rax), %edi
movl (%rax), %esi
movl 0x4(%rax), %edx
movl 0x10(%rax), %ecx
movl $0x8, %r8d
jmp 0x2be63
cmpl $0xfa0, %ecx            # imm = 0xFA0
je 0x2be6f
cmpl $-0x1, 0x18(%rax)
jne 0x2be6f
movl 0xc(%rax), %edi
movl 0x10(%rax), %ecx
movl $0x60, %r8d
callq 0x1c370
movq (%r12), %rcx
movl %eax, 0x18(%rcx)
incq %r13
movslq 0x294677(%rip), %rax    # 0x2c04f0
addq $0x8, %r12
cmpq %rax, %r13
jl 0x2bdc1
leaq 0x64e4f(%rip), %rdi     # 0x90cdc
leaq 0xb997c(%rip), %rsi     # 0xe5810
movl $0x6, %edx
callq 0x8e40
movl 0xa6ae4(%rip), %edi     # 0xd2988
testl %eax, %eax
je 0x2beb9
cmpl $-0x1, %edi
je 0x2bedd
callq 0x1c5b9
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2bed7
cmpl $-0x1, %edi
jne 0x2bedd
movl $0x4a, %edi
xorl %esi, %esi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0x1, %r8d
callq 0x1c370
movl %eax, 0xa6aab(%rip)     # 0xd2988
testq %rbx, %rbx
je 0x2bfd3
movl (%rbx), %ebp
testl %ebp, 0xa6a36(%rip)     # 0xd2924
setne %cl
movl 0x2945f9(%rip), %eax    # 0x2c04f0
testl %eax, %eax
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2bf66
leaq 0x2efed6(%rip), %r14    # 0x31bde0
xorl %r15d, %r15d
leaq 0x1cd31c(%rip), %r12    # 0x1f9230
movq (%r14), %rcx
cmpl $0x2, 0x14(%rcx)
jne 0x2bf57
movswq 0x8(%rcx), %rdx
movq (%r12,%rdx,8), %rdx
movswl 0x24(%rdx), %edx
cmpl %edx, 0x8(%rbx)
jne 0x2bf57
cmpl $-0x1, 0x18(%rcx)
jne 0x2bf57
movl 0xc(%rcx), %edi
movl (%rcx), %esi
movl 0x4(%rcx), %edx
movl 0x10(%rcx), %ecx
movl $0x9, %r8d
callq 0x1c370
movq (%r14), %rcx
movl %eax, 0x18(%rcx)
movl 0x294599(%rip), %eax    # 0x2c04f0
incq %r15
movslq %eax, %rcx
addq $0x8, %r14
cmpq %rcx, %r15
jl 0x2bf14
testl %ebp, 0xa69bc(%rip)     # 0xd2928
setne %cl
testl %eax, %eax
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2bfd3
leaq 0x2efe5e(%rip), %r14    # 0x31bde0
xorl %r15d, %r15d
leaq 0x1cd2a4(%rip), %r12    # 0x1f9230
movq (%r14), %rcx
cmpl $0x2, 0x14(%rcx)
jne 0x2bfc4
movswq 0x8(%rcx), %rdx
movq (%r12,%rdx,8), %rdx
movswl 0x24(%rdx), %edx
cmpl %edx, 0x8(%rbx)
jne 0x2bfc4
movl 0x18(%rcx), %edi
cmpl $-0x1, %edi
je 0x2bfc4
callq 0x1c5b9
movq (%r14), %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movl 0x29452c(%rip), %eax    # 0x2c04f0
incq %r15
movslq %eax, %rcx
addq $0x8, %r14
cmpq %rcx, %r15
jl 0x2bf8c
leaq 0xb84ae(%rip), %rax     # 0xe4488
movl (%rax), %eax
movl %eax, 0x302b5e(%rip)    # 0x32eb40
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq