// File: /workspace/github_c_makefile_star2_O2/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, %r15
leaq 0xb31f7(%rip), %r12     # 0xdb720
movswq (%r12,%r15,2), %rax
leaq 0x2cdfcb(%rip), %rcx    # 0x2f6500
movq (%rcx,%rax,8), %r14
leaq 0x2e98a0(%rip), %r13    # 0x311de0
xorl %ebp, %ebp
leaq 0xb1fc7(%rip), %rbx     # 0xda510
movslq 0x28dfa0(%rip), %rax    # 0x2b64f0
cmpq %rax, %rbp
jge 0x2860a
movq (%r13), %rax
movl 0x14(%rax), %ecx
cmpl $0x1, %ecx
je 0x285b2
testl %ecx, %ecx
jne 0x285fe
leaq 0xb1f5c(%rip), %rcx     # 0xda4d0
movl (%rcx,%r15,4), %ecx
movl (%rax), %esi
movl 0x4(%rax), %edx
subl %esi, %ecx
movl %ecx, %edi
negl %edi
cmovsl %ecx, %edi
movl (%rbx,%r15,4), %r8d
subl %edx, %r8d
movl %r8d, %ecx
negl %ecx
cmovsl %r8d, %ecx
addl %edi, %ecx
cmpl $0xfa1, %ecx            # imm = 0xFA1
jb 0x285da
movl 0x18(%rax), %edi
cmpl $-0x1, %edi
je 0x285fe
callq 0x1ad70
pushq $-0x1
popq %rax
jmp 0x285f7
movzwl (%r12,%r15,2), %ecx
leaq 0xb31c2(%rip), %rdx     # 0xdb780
cmpw (%rdx,%r15,2), %cx
je 0x285fe
cmpw 0x8(%rax), %cx
jne 0x285fe
movl 0xc(%rax), %edi
movl (%rax), %esi
movl 0x4(%rax), %edx
movl 0x10(%rax), %ecx
pushq $0x8
jmp 0x285f0
cmpl $0xfa0, %ecx            # imm = 0xFA0
je 0x285fe
cmpl $-0x1, 0x18(%rax)
jne 0x285fe
movl 0xc(%rax), %edi
movl 0x10(%rax), %ecx
pushq $0x60
popq %r8
callq 0x1ab2a
movq (%r13), %rcx
movl %eax, 0x18(%rcx)
incq %rbp
addq $0x8, %r13
jmp 0x28549
leaq 0x5a593(%rip), %rdi     # 0x82ba4
leaq 0xb31f8(%rip), %rsi     # 0xdb810
pushq $0x6
popq %rdx
callq 0x8e40
movl 0xa0362(%rip), %edi     # 0xc8988
testl %eax, %eax
je 0x28639
cmpl $-0x1, %edi
je 0x28657
callq 0x1ad70
pushq $-0x1
popq %rax
jmp 0x28651
cmpl $-0x1, %edi
jne 0x28657
pushq $0x4a
popq %rdi
pushq $-0x1
popq %rcx
pushq $0x1
popq %r8
xorl %esi, %esi
xorl %edx, %edx
callq 0x1ab2a
movl %eax, 0xa0331(%rip)     # 0xc8988
testq %r14, %r14
je 0x2873e
movl (%r14), %ebp
testl %ebp, 0xa02bb(%rip)     # 0xc8924
je 0x286d8
leaq 0x2e976e(%rip), %r15    # 0x311de0
movl 0x28de78(%rip), %eax    # 0x2b64f0
xorl %r12d, %r12d
leaq 0x1c6bae(%rip), %r13    # 0x1ef230
pushq $0x9
popq %rbx
movslq %eax, %rcx
cmpq %rcx, %r12
jge 0x286d8
movq (%r15), %rcx
cmpl $0x2, 0x14(%rcx)
jne 0x286cf
movswq 0x8(%rcx), %rdx
movq (%r13,%rdx,8), %rdx
movswl 0x24(%rdx), %edx
cmpl %edx, 0x8(%r14)
jne 0x286cf
cmpl $-0x1, 0x18(%rcx)
jne 0x286cf
movl 0xc(%rcx), %edi
movl (%rcx), %esi
movl 0x4(%rcx), %edx
movl 0x10(%rcx), %ecx
movl %ebx, %r8d
callq 0x1ab2a
movq (%r15), %rcx
movl %eax, 0x18(%rcx)
movl 0x28de21(%rip), %eax    # 0x2b64f0
incq %r12
addq $0x8, %r15
jmp 0x28685
testl %ebp, 0xa024a(%rip)     # 0xc8928
je 0x2873e
leaq 0x2e96f9(%rip), %rbx    # 0x311de0
movl 0x28de03(%rip), %eax    # 0x2b64f0
xorl %r15d, %r15d
leaq 0x1c6b39(%rip), %r12    # 0x1ef230
movslq %eax, %rcx
cmpq %rcx, %r15
jge 0x2873e
movq (%rbx), %rcx
cmpl $0x2, 0x14(%rcx)
jne 0x28735
movswq 0x8(%rcx), %rdx
movq (%r12,%rdx,8), %rdx
movswl 0x24(%rdx), %edx
cmpl %edx, 0x8(%r14)
jne 0x28735
movl 0x18(%rcx), %edi
cmpl $-0x1, %edi
je 0x28735
callq 0x1ad70
movq (%rbx), %rax
orl $-0x1, 0x18(%rax)
movl 0x28ddbb(%rip), %eax    # 0x2b64f0
incq %r15
addq $0x8, %rbx
jmp 0x286f7
leaq 0xb1d43(%rip), %rax     # 0xda488
movl (%rax), %eax
movl %eax, 0x2fc3f3(%rip)    # 0x324b40
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq