// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %r9, (%rsp)
movq %r8, %r15
movq %rcx, %r12
movl %edx, %ebx
movq %rsi, %r13
movl %edi, %ebp
cmpl $0x0, 0xa22e(%rip)      # 0xf2e0
je 0x50b9
callq 0x5329
andl $0x0, 0xa224(%rip)      # 0xf2e4
movslq %ebx, %r14
movabsq $0xa800000000, %rax     # imm = 0xA800000000
imulq %r14, %rax
movabsq $0x180000000000, %rsi   # imm = 0x180000000000
addq %rax, %rsi
sarq $0x20, %rsi
pushq $0x1
popq %rdi
callq 0x2150
pushq $-0x1
popq %rcx
testq %rax, %rax
je 0x519e
imulq $0xa8, %r14, %rbx
movq %rax, 0x13414(%rip)     # 0x18518
addq %rax, %rbx
movq %rbx, 0x13412(%rip)     # 0x18520
leaq 0xa1d3(%rip), %rcx      # 0xf2e8
movq %rcx, 0xa1d4(%rip)      # 0xf2f0
movq %rcx, 0xa1c5(%rip)      # 0xf2e8
leaq 0xa26e(%rip), %rcx      # 0xf398
movq %rcx, 0xa26f(%rip)      # 0xf3a0
movq %rcx, 0xa260(%rip)      # 0xf398
xorl %edx, %edx
testl %r14d, %r14d
cmovgl %r14d, %edx
movq %rcx, %rsi
subq $0x1, %rdx
jb 0x5169
movq %rax, %rdi
movq %rcx, (%rax)
movq %rsi, 0x8(%rax)
movq %rax, (%rsi)
movq %rax, 0xa242(%rip)      # 0xf3a0
addq $0xa8, %rax
movq %rdi, %rsi
jmp 0x5144
andl $0x0, 0x122e0(%rip)     # 0x17450
leaq 0xa099(%rip), %rax      # 0xf210
movl %ebp, (%rax)
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq (%rsp), %rcx
callq 0x2c2f
testl %eax, %eax
je 0x51a3
movl $0x3, 0xa14b(%rip)      # 0xf2e4
pushq $0x3
popq %rbp
jmp 0x51ad
pushq $0x5
popq %rbp
jmp 0x51cc
movl 0xa13b(%rip), %ebp      # 0xf2e4
testl %ebp, %ebp
je 0x51e3
movq 0x13364(%rip), %rdi     # 0x18518
callq 0x2280
andq $0x0, 0x13357(%rip)     # 0x18518
andq $0x0, 0x13357(%rip)     # 0x18520
pushq $-0x1
popq %rcx
movl %ebp, 0xa112(%rip)      # 0xf2e4
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andq $0x0, 0xa1a5(%rip)      # 0xf390
addq $0x800, %rbx            # imm = 0x800
andl $0x0, 0x13267(%rip)     # 0x18460
movl $0x1, 0xa0dd(%rip)      # 0xf2e0
andq $0x0, 0x1325d(%rip)     # 0x18468
movl (%r13), %eax
movl %eax, 0x132f7(%rip)     # 0x1850c
movl (%r12), %edi
movl (%r15), %esi
callq 0x3eb5
movl 0xa00d(%rip), %eax      # 0xf234
leal (%rax,%rax,2), %ecx
movl %ecx, 0x13240(%rip)     # 0x18470
movl 0x9ffa(%rip), %edi      # 0xf230
leaq 0x13243(%rip), %rcx     # 0x18480
movq %rbx, (%rcx,%rdi,8)
xorl %edx, %edx
testl %edi, %edi
movl $0x0, %esi
cmovgl %edi, %esi
shlq $0x3, %rsi
cmpq %rdx, %rsi
je 0x5263
movq %rbx, (%rdx,%rcx)
addq %rax, %rbx
addq $0x8, %rdx
jmp 0x5251
movl 0x9fb3(%rip), %edi      # 0xf21c
testl %edi, %edi
pushq $-0x1
popq %rax
cmovnsl %edi, %eax
movslq %eax, %r8
incq %r8
leaq 0x13163(%rip), %r9      # 0x183e1
leaq 0x129dc(%rip), %r10     # 0x17c61
xorl %r11d, %r11d
pushq $-0x8
popq %rbx
cmpq %r8, %r11
je 0x52ff
movl %edi, %eax
subl %r11d, %eax
imull $0xff, %eax, %eax
cltd
idivl %edi
movl %eax, %ecx
xorl %esi, %esi
xorl %r14d, %r14d
movq %r9, %r15
cmpq $0x480, %r14            # imm = 0x480
je 0x52f2
movl %esi, %eax
cltd
idivl %ebx
addl %ecx, %eax
movb %al, -0x801(%r10,%r14)
movb %al, -0x781(%r15)
movb %cl, -0x1(%r10,%r14)
movb %cl, -0x1(%r15)
movb %cl, -0x800(%r10,%r14)
movb %cl, -0x780(%r15)
movb %al, (%r10,%r14)
movb %al, (%r15)
addq $-0x80, %r15
subq $-0x80, %r14
addl %ecx, %esi
jmp 0x52a8
incq %r11
addq $0x2, %r9
addq $0x2, %r10
jmp 0x528b
movl $0xff, %edi
callq 0x4ff2
callq 0x3f3b
testl %eax, %eax
je 0x5322
movl 0x9fcc(%rip), %ebp      # 0xf2e4
callq 0x5329
jmp 0x51c9
xorl %ecx, %ecx
jmp 0x51d2