// File: /workspace/github_c_makefile_star2_O1/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 0xb7c3c(%rip), %r15     # 0xe2720
movswq (%r15,%r14,2), %rax
leaq 0x2d29f0(%rip), %rcx    # 0x2fd4e0
movq (%rcx,%rax,8), %rbx
cmpl $0x0, 0x2929d5(%rip)    # 0x2bd4d0
jle 0x2abd7
leaq 0x2ee2b8(%rip), %r12    # 0x318dc0
xorl %r13d, %r13d
leaq 0xb69fe(%rip), %rbp     # 0xe1510
movq (%r12), %rax
movl 0x14(%rax), %ecx
cmpl $0x1, %ecx
je 0x2ab6e
testl %ecx, %ecx
jne 0x2abc0
leaq 0xb69a3(%rip), %rcx     # 0xe14d0
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 0x2ab9a
movl 0x18(%rax), %edi
cmpl $-0x1, %edi
je 0x2ab9a
callq 0x1c457
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2abb9
movzwl (%r15,%r14,2), %ecx
leaq 0xb7c06(%rip), %rdx     # 0xe2780
cmpw (%rdx,%r14,2), %cx
je 0x2abc0
cmpw 0x8(%rax), %cx
jne 0x2abc0
movl 0xc(%rax), %edi
movl (%rax), %esi
movl 0x4(%rax), %edx
movl 0x10(%rax), %ecx
movl $0x8, %r8d
jmp 0x2abb4
cmpl $0xf9f, %ecx            # imm = 0xF9F
ja 0x2abc0
cmpl $-0x1, 0x18(%rax)
jne 0x2abc0
movl 0xc(%rax), %edi
movl 0x10(%rax), %ecx
movl $0x60, %r8d
callq 0x1c1f1
movq (%r12), %rcx
movl %eax, 0x18(%rcx)
incq %r13
movslq 0x292906(%rip), %rax    # 0x2bd4d0
addq $0x8, %r12
cmpq %rax, %r13
jl 0x2ab12
leaq 0x62f46(%rip), %rdi     # 0x8db24
leaq 0xb7c2b(%rip), %rsi     # 0xe2810
movl $0x6, %edx
callq 0x8e40
movl 0xa4d93(%rip), %edi     # 0xcf988
testl %eax, %eax
je 0x2ac0a
cmpl $-0x1, %edi
je 0x2ac2e
callq 0x1c457
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2ac28
cmpl $-0x1, %edi
jne 0x2ac2e
movl $0x4a, %edi
xorl %esi, %esi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0x1, %r8d
callq 0x1c1f1
movl %eax, 0xa4d5a(%rip)     # 0xcf988
testq %rbx, %rbx
je 0x2ad12
movl (%rbx), %ebp
testl %ebp, 0xa4ce5(%rip)     # 0xcf924
je 0x2acab
cmpl $0x0, 0x292888(%rip)    # 0x2bd4d0
jle 0x2acab
leaq 0x2ee16f(%rip), %r14    # 0x318dc0
xorl %r15d, %r15d
leaq 0x1cb5b5(%rip), %r12    # 0x1f6210
movq (%r14), %rax
cmpl $0x2, 0x14(%rax)
jne 0x2ac98
movswq 0x8(%rax), %rcx
movq (%r12,%rcx,8), %rcx
movswl 0x24(%rcx), %ecx
cmpl %ecx, 0x8(%rbx)
jne 0x2ac98
cmpl $-0x1, 0x18(%rax)
jne 0x2ac98
movl 0xc(%rax), %edi
movl (%rax), %esi
movl 0x4(%rax), %edx
movl 0x10(%rax), %ecx
movl $0x9, %r8d
callq 0x1c1f1
movq (%r14), %rcx
movl %eax, 0x18(%rcx)
incq %r15
movslq 0x29282e(%rip), %rax    # 0x2bd4d0
addq $0x8, %r14
cmpq %rax, %r15
jl 0x2ac5b
testl %ebp, 0xa4c77(%rip)     # 0xcf928
je 0x2ad12
cmpl $0x0, 0x292816(%rip)    # 0x2bd4d0
jle 0x2ad12
leaq 0x2ee0fd(%rip), %r14    # 0x318dc0
xorl %r15d, %r15d
leaq 0x1cb543(%rip), %r12    # 0x1f6210
movq (%r14), %rax
cmpl $0x2, 0x14(%rax)
jne 0x2acff
movswq 0x8(%rax), %rcx
movq (%r12,%rcx,8), %rcx
movswl 0x24(%rcx), %ecx
cmpl %ecx, 0x8(%rbx)
jne 0x2acff
movl 0x18(%rax), %edi
cmpl $-0x1, %edi
je 0x2acff
callq 0x1c457
movq (%r14), %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
incq %r15
movslq 0x2927c7(%rip), %rax    # 0x2bd4d0
addq $0x8, %r14
cmpq %rax, %r15
jl 0x2accd
leaq 0xb676f(%rip), %rax     # 0xe1488
movl (%rax), %eax
movl %eax, 0x300dff(%rip)    # 0x32bb20
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq