// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %r9, 0x18(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
movl %edx, %ebx
movq %rsi, %rbp
movl %edi, 0x4(%rsp)
cmpl $0x0, 0xaea9(%rip)      # 0x102d0
je 0x542e
callq 0x56c8
movl $0x0, 0xae9c(%rip)      # 0x102d4
movslq %ebx, %r12
movabsq $0xa800000000, %rax     # imm = 0xA800000000
imulq %r12, %rax
movabsq $0x180000000000, %r14   # imm = 0x180000000000
addq %rax, %r14
sarq $0x20, %r14
movq %r14, %rdi
callq 0x2280
testq %rax, %rax
je 0x5564
movq %rax, %r13
imulq $0xa8, %r12, %r15
movq %rax, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x20f0
movq %r13, 0x1407f(%rip)     # 0x19508
movq %r15, 0x8(%rsp)
leaq (%r15,%r13), %rax
movq %rax, 0x14077(%rip)     # 0x19510
leaq 0xae38(%rip), %rax      # 0x102d8
movq %rax, 0xae39(%rip)      # 0x102e0
movq %rax, 0xae2a(%rip)      # 0x102d8
leaq 0xaed3(%rip), %rax      # 0x10388
movq %rax, 0xaed4(%rip)      # 0x10390
movq %rax, 0xaec5(%rip)      # 0x10388
testl %r12d, %r12d
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %r15
jle 0x5501
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 0x54da
addq $-0xa8, %rsi
movq %rsi, 0xae8f(%rip)      # 0x10390
movl $0x0, 0x12f35(%rip)     # 0x18440
leaq 0xacee(%rip), %rax      # 0x10200
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
movq %rbp, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq 0x18(%rsp), %rcx
callq 0x2ca5
testl %eax, %eax
je 0x5539
movl $0x3, 0xad9b(%rip)      # 0x102d4
movl 0xad95(%rip), %ebx      # 0x102d4
testl %ebx, %ebx
je 0x556e
movq 0x13fbe(%rip), %rdi     # 0x19508
callq 0x2260
xorl %eax, %eax
movq %rax, 0x13fb0(%rip)     # 0x19508
movq %rax, 0x13fb1(%rip)     # 0x19510
jmp 0x56aa
movl $0x5, %ebx
jmp 0x56aa
movq 0x8(%rsp), %rax
leaq (%rax,%r13), %rbx
addq $0x800, %rbx            # imm = 0x800
movl $0x1, 0xad48(%rip)      # 0x102d0
xorl %eax, %eax
movq %rax, 0xadef(%rip)      # 0x10380
movl $0x0, 0x13eb5(%rip)     # 0x19450
movq %rax, 0x13eb6(%rip)     # 0x19458
movl (%rbp), %eax
movl %eax, 0x13f51(%rip)     # 0x194fc
movl (%r15), %edi
movl (%r14), %esi
callq 0x40af
movl 0xac68(%rip), %eax      # 0x10224
leal (%rax,%rax,2), %ecx
movl %ecx, 0x13e9b(%rip)     # 0x19460
movslq 0xac54(%rip), %rcx      # 0x10220
leaq 0x13e9d(%rip), %rdx     # 0x19470
movq %rbx, (%rdx,%rcx,8)
testq %rcx, %rcx
jle 0x55f2
shlq $0x3, %rcx
xorl %esi, %esi
movq %rbx, (%rsi,%rdx)
addq %rax, %rbx
addq $0x8, %rsi
cmpq %rsi, %rcx
jne 0x55e2
movl 0xac14(%rip), %ecx      # 0x1020c
testl %ecx, %ecx
js 0x568c
leaq 0x1(%rcx), %rsi
leaq 0x13dc6(%rip), %rdi     # 0x193d1
leaq 0x1363f(%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 0x562c
incq %r9
addq $0x2, %rdi
addq $0x2, %r8
cmpq %rsi, %r9
jne 0x5615
movl $0xff, %edi
callq 0x5357
callq 0x4149
testl %eax, %eax
je 0x56c4
movl 0xac2f(%rip), %ebx      # 0x102d4
callq 0x56c8
movl %ebx, 0xac24(%rip)      # 0x102d4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x56b5