// File: /workspace/github_c_makefile_star2_O3/jonof[P]jfaudiolib/src/multivoc.c
// Function: MV_Init
int MV_Init
   (
   int soundcard,
   int * MixRate,
   int Voices,
   int * numchannels,
   int * samplebits,
   void * initdata
   )

   {
   char *ptr;
   int  status;
   int  buffer;
   int  index;

   if ( MV_Installed )
      {
      MV_Shutdown();
      }

   MV_SetErrorCode( MV_Ok );

   MV_TotalMemory = Voices * sizeof( VoiceNode ) + sizeof( HARSH_CLIP_TABLE_8 ) + TotalBufferSize;
   ptr = (char *) malloc( MV_TotalMemory );
   if ( !ptr )
      {
      MV_SetErrorCode( MV_NoMem );
      return( MV_Error );
      }

   memset(ptr, 0, MV_TotalMemory);

   MV_Voices = ( VoiceNode * )ptr;
   ptr += Voices * sizeof( VoiceNode );

   MV_HarshClipTable = ptr;
   ptr += sizeof(HARSH_CLIP_TABLE_8);

   // Set number of voices before calculating volume table
   MV_MaxVoices = Voices;

   LL_Reset( (VoiceNode*) &VoiceList, next, prev );
   LL_Reset( (VoiceNode*) &VoicePool, next, prev );

   for( index = 0; index < Voices; index++ )
      {
      LL_Add( (VoiceNode*) &VoicePool, &MV_Voices[ index ], next, prev );
      }

   MV_SetReverseStereo( FALSE );

   ASS_PCMSoundDriver = soundcard;

   // Initialize the sound card
   status = SoundDriver_PCM_Init(MixRate, numchannels, samplebits, initdata);
   if ( status != MV_Ok ) {
      MV_SetErrorCode( MV_DriverError );
   }

   if ( MV_ErrorCode != MV_Ok )
      {
      status = MV_ErrorCode;

      free( MV_Voices );
      MV_Voices      = NULL;
      MV_HarshClipTable = NULL;
      MV_TotalMemory = 0;

      MV_SetErrorCode( status );
      return( MV_Error );
      }

   MV_Installed    = TRUE;
   MV_CallBackFunc = NULL;
   MV_RecordFunc   = NULL;
   MV_Recording    = FALSE;
   MV_ReverbLevel  = 0;
   MV_ReverbTable  = NULL;

   // Set the sampling rate
   MV_RequestedMixRate = *MixRate;

   // Set Mixer to play stereo digitized sound
   MV_SetMixMode( *numchannels, *samplebits );
   MV_ReverbDelay = MV_BufferSize * 3;

   // Make sure we don't cross a physical page
   MV_MixBuffer[ MV_NumberOfBuffers ] = ptr;
   for( buffer = 0; buffer < MV_NumberOfBuffers; buffer++ )
      {
      MV_MixBuffer[ buffer ] = ptr;
      ptr += MV_BufferSize;
      }

   // Calculate pan table
   MV_CalcPanTable();

   MV_SetVolume( MV_MaxTotalVolume );

   // Start the playback engine
   status = MV_StartPlayback();
   if ( status != MV_Ok )
      {
      // Preserve error code while we shutdown.
      status = MV_ErrorCode;
      MV_Shutdown();
      MV_SetErrorCode( status );
      return( MV_Error );
      }

   return( MV_Ok );
   }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, 0x10(%rsp)
movq %r8, %rbp
movq %rcx, %r12
movl %edx, %ebx
movq %rsi, %r14
movl %edi, 0x4(%rsp)
cmpl $0x0, 0xaee0(%rip)      # 0x102d0
je 0x53f7
callq 0x5681
movl $0x0, 0xaed3(%rip)      # 0x102d4
movslq %ebx, %r15
movabsq $0xa800000000, %rax     # imm = 0xA800000000
imulq %r15, %rax
movabsq $0x180000000000, %rsi   # imm = 0x180000000000
addq %rax, %rsi
sarq $0x20, %rsi
movl $0x1, %edi
callq 0x2150
testq %rax, %rax
je 0x54f3
movq %rax, %r13
imulq $0xa8, %r15, %rax
movq %r13, 0x140c1(%rip)     # 0x19508
movq %rax, 0x8(%rsp)
addq %r13, %rax
movq %rax, 0x140ba(%rip)     # 0x19510
leaq 0xae7b(%rip), %rax      # 0x102d8
movq %rax, 0xae7c(%rip)      # 0x102e0
movq %rax, 0xae6d(%rip)      # 0x102d8
leaq 0xaf16(%rip), %rax      # 0x10388
movq %rax, 0xaf17(%rip)      # 0x10390
movq %rax, 0xaf08(%rip)      # 0x10388
testl %r15d, %r15d
jle 0x54b4
movl %ebx, %ecx
movq %r13, %rsi
movq %rax, %rdx
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
movq %rsi, (%rdx)
movq %rsi, %rdx
addq $0xa8, %rsi
decq %rcx
jne 0x548d
addq $-0xa8, %rsi
movq %rsi, 0xaedc(%rip)      # 0x10390
movl $0x0, 0x12f82(%rip)     # 0x18440
leaq 0xad3b(%rip), %rax      # 0x10200
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq 0x10(%rsp), %rcx
callq 0x2cad
testl %eax, %eax
je 0x54fa
movl $0x3, 0xade8(%rip)      # 0x102d4
movl $0x3, %ebx
jmp 0x5504
movl $0x5, %ebx
jmp 0x5520
movl 0xadd4(%rip), %ebx      # 0x102d4
testl %ebx, %ebx
je 0x553a
movq 0x13ffd(%rip), %rdi     # 0x19508
callq 0x2270
xorl %eax, %eax
movq %rax, 0x13fef(%rip)     # 0x19508
movq %rax, 0x13ff0(%rip)     # 0x19510
movl %ebx, 0xadae(%rip)      # 0x102d4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
leaq (%rax,%r13), %rbx
addq $0x800, %rbx            # imm = 0x800
movl $0x1, 0xad7c(%rip)      # 0x102d0
xorl %eax, %eax
movq %rax, 0xae23(%rip)      # 0x10380
movl $0x0, 0x13ee9(%rip)     # 0x19450
movq %rax, 0x13eea(%rip)     # 0x19458
movl (%r14), %eax
movl %eax, 0x13f85(%rip)     # 0x194fc
movl (%r12), %edi
movl (%rbp), %esi
callq 0x40af
movl 0xac9b(%rip), %eax      # 0x10224
leal (%rax,%rax,2), %ecx
movl %ecx, 0x13ece(%rip)     # 0x19460
movl 0xac88(%rip), %ecx      # 0x10220
leaq 0x13ed1(%rip), %rdx     # 0x19470
movq %rbx, (%rdx,%rcx,8)
testl %ecx, %ecx
jle 0x55bd
shlq $0x3, %rcx
xorl %esi, %esi
movq %rbx, (%rsi,%rdx)
addq %rax, %rbx
addq $0x8, %rsi
cmpq %rsi, %rcx
jne 0x55ad
movl 0xac49(%rip), %ecx      # 0x1020c
testl %ecx, %ecx
js 0x5657
leaq 0x1(%rcx), %rsi
leaq 0x13dfb(%rip), %rdi     # 0x193d1
leaq 0x13674(%rip), %r8      # 0x18c51
xorl %r9d, %r9d
movl %ecx, %edx
subl %r9d, %edx
movl %edx, %eax
shll $0x8, %eax
subl %edx, %eax
cltd
idivl %ecx
xorl %edx, %edx
movq %rdi, %r10
xorl %r11d, %r11d
leal 0x7(%rdx), %ebx
testl %edx, %edx
cmovnsl %edx, %ebx
shrl $0x3, %ebx
movl %eax, %ebp
subl %ebx, %ebp
movb %bpl, -0x801(%r8,%r11)
movb %bpl, -0x781(%r10)
movb %al, -0x1(%r8,%r11)
movb %al, -0x1(%r10)
movb %al, -0x800(%r8,%r11)
movb %al, -0x780(%r10)
movb %bpl, (%r8,%r11)
movb %bpl, (%r10)
subq $-0x80, %r11
addq $-0x80, %r10
addl %eax, %edx
cmpq $0x480, %r11            # imm = 0x480
jne 0x55f7
incq %r9
addq $0x2, %rdi
addq $0x2, %r8
cmpq %rsi, %r9
jne 0x55e0
movl $0xff, %edi
callq 0x5324
callq 0x4137
testl %eax, %eax
je 0x567a
movl 0xac64(%rip), %ebx      # 0x102d4
callq 0x5681
jmp 0x5520
xorl %eax, %eax
jmp 0x552b