// File: /workspace/github_c_makefile_star2_O0/jonof[P]jfaudiolib/src/multivoc.c
// Function: MV_AllocVoice
VoiceNode *MV_AllocVoice
   (
   int priority
   )

   {
   VoiceNode   *voice;
   VoiceNode   *node;
   int          flags;

//return( NULL );
   if ( MV_Recording )
      {
      return( NULL );
      }

   flags = DisableInterrupts();

   // Check if we have any free voices
   if ( LL_Empty( &VoicePool, next, prev ) )
      {
      // check if we have a higher priority than a voice that is playing.
      voice = VoiceList.next;
      for( node = voice->next; node != &VoiceList; node = node->next )
         {
         if ( node->priority < voice->priority )
            {
            voice = node;
            }
         }

      if ( priority >= voice->priority )
         {
         MV_Kill( voice->handle );
         }
      }

   // Check if any voices are in the voice pool
   if ( LL_Empty( &VoicePool, next, prev ) )
      {
      // No free voices
      RestoreInterrupts( flags );
      return( NULL );
      }

   voice = VoicePool.next;
   LL_Remove( voice, next, prev );
   RestoreInterrupts( flags );

   // Find a free voice handle
   do
      {
      MV_VoiceHandle++;
      if ( MV_VoiceHandle < MV_MinVoiceHandle )
         {
         MV_VoiceHandle = MV_MinVoiceHandle;
         }
      }
   while( MV_VoicePlaying( MV_VoiceHandle ) );

   voice->handle = MV_VoiceHandle;

   return( voice );
   }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0xc(%rbp)
cmpl $0x0, 0x11246(%rip)     # 0x15d48
je 0x4b11
movq $0x0, -0x8(%rbp)
jmp 0x4c76
callq 0x4640
movl %eax, -0x24(%rbp)
movq 0x11230(%rip), %rax     # 0x15d50
leaq 0x11229(%rip), %rcx     # 0x15d50
cmpq %rcx, %rax
jne 0x4ba3
movq 0x11225(%rip), %rax     # 0x15d58
leaq 0x11216(%rip), %rcx     # 0x15d50
cmpq %rcx, %rax
jne 0x4ba3
movq 0x11152(%rip), %rax     # 0x15c98
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
leaq 0x1113c(%rip), %rax     # 0x15c98
cmpq %rax, -0x20(%rbp)
je 0x4b89
movq -0x20(%rbp), %rax
movl 0x7c(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x7c(%rcx), %eax
jge 0x4b7a
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x4b7c
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x4b55
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x7c(%rcx), %eax
jl 0x4ba1
movq -0x18(%rbp), %rax
movl 0x78(%rax), %edi
callq 0x4880
jmp 0x4ba3
movq 0x111a6(%rip), %rax     # 0x15d50
leaq 0x1119f(%rip), %rcx     # 0x15d50
cmpq %rcx, %rax
jne 0x4bde
movq 0x1119b(%rip), %rax     # 0x15d58
leaq 0x1118c(%rip), %rcx     # 0x15d50
cmpq %rcx, %rax
jne 0x4bde
movl -0x24(%rbp), %edi
callq 0x4680
movq $0x0, -0x8(%rbp)
jmp 0x4c76
movq 0x1116b(%rip), %rax     # 0x15d50
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x24(%rbp), %edi
callq 0x4680
movl 0x10aed(%rip), %eax     # 0x15720
addl $0x1, %eax
movl %eax, 0x10ae4(%rip)     # 0x15720
cmpl $0x1, 0x10add(%rip)     # 0x15720
jge 0x4c4f
movl $0x1, 0x10ad1(%rip)     # 0x15720
jmp 0x4c51
movl 0x10ac9(%rip), %edi     # 0x15720
callq 0x46b0
cmpl $0x0, %eax
jne 0x4c2d
movl 0x10ab9(%rip), %ecx     # 0x15720
movq -0x18(%rbp), %rax
movl %ecx, 0x78(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq