// File: /workspace/github_c_makefile_star2_O0/jonof[P]jfaudiolib/src/midi.c
// Function: MIDI_ServiceRoutine
static void _MIDI_ServiceRoutine
   (
   void
   )

   {
   int   event;
   int   channel;
   int   command;
   track *Track;
   int   tracknum;
   int   status;
   int   c1 = 0;
   int   c2 = 0;
   int   TimeSet = FALSE;

   if ( !_MIDI_SongActive )
      {
      return;
      }

   Track = _MIDI_TrackPtr;
   tracknum = 0;
   while( tracknum < _MIDI_NumTracks )
      {
      while ( ( Track->active ) && ( Track->delay == 0 ) )
         {
         GET_NEXT_EVENT( Track, event );

         if ( GET_MIDI_COMMAND( event ) == MIDI_SPECIAL )
            {
            switch( event )
               {
               case MIDI_SYSEX :
               case MIDI_SYSEX_CONTINUE :
                  _MIDI_SysEx( Track );
                  break;

               case MIDI_META_EVENT :
                  _MIDI_MetaEvent( Track );
                  break;
               }

            if ( Track->active )
               {
               Track->delay = _MIDI_ReadDelta( Track );
               }

            continue;
            }

         if ( event & MIDI_RUNNING_STATUS )
            {
            Track->RunningStatus = event;
            }
         else
            {
            event = Track->RunningStatus;
            Track->pos--;
            }

         channel = GET_MIDI_CHANNEL( event );
         command = GET_MIDI_COMMAND( event );

         if ( _MIDI_CommandLengths[ command ] > 0 )
            {
            GET_NEXT_EVENT( Track, c1 );
            if ( _MIDI_CommandLengths[ command ] > 1 )
               {
               GET_NEXT_EVENT( Track, c2 );
               }
            }

         if ( _MIDI_RerouteFunctions[ channel ] != NULL )
            {
            status = _MIDI_RerouteFunctions[ channel ]( event, c1, c2 );

            if ( status == MIDI_DONT_PLAY )
               {
               Track->delay = _MIDI_ReadDelta( Track );
               continue;
               }
            }

         switch ( command )
            {
            case MIDI_NOTE_OFF :
               if ( _MIDI_Funcs->NoteOff )
                  {
                  _MIDI_Funcs->NoteOff( channel, c1, c2 );
                  }
               break;

            case MIDI_NOTE_ON :
               if ( _MIDI_Funcs->NoteOn )
                  {
                  _MIDI_Funcs->NoteOn( channel, c1, c2 );
                  }
               break;

            case MIDI_POLY_AFTER_TCH :
               if ( _MIDI_Funcs->PolyAftertouch )
                  {
                  _MIDI_Funcs->PolyAftertouch( channel, c1, c2 );
                  }
               break;

            case MIDI_CONTROL_CHANGE :
               TimeSet = _MIDI_InterpretControllerInfo( Track, TimeSet,
                  channel, c1, c2 );
               break;

            case MIDI_PROGRAM_CHANGE :
               if ( ( _MIDI_Funcs->ProgramChange ) &&
                  ( !Track->EMIDI_ProgramChange ) )
                  {
                  _MIDI_Funcs->ProgramChange( channel, MIDI_PatchMap[ c1 & 0x7f ] );
                  }
               break;

            case MIDI_AFTER_TOUCH :
               if ( _MIDI_Funcs->ChannelAftertouch )
                  {
                  _MIDI_Funcs->ChannelAftertouch( channel, c1 );
                  }
               break;

            case MIDI_PITCH_BEND :
               if ( _MIDI_Funcs->PitchBend )
                  {
                  _MIDI_Funcs->PitchBend( channel, c1, c2 );
                  }
               break;

            default :
               break;
            }

         Track->delay = _MIDI_ReadDelta( Track );
         }

      Track->delay--;
      Track++;
      tracknum++;

      if ( _MIDI_ActiveTracks == 0 )
         {
         _MIDI_ResetTracks();
         if ( _MIDI_Loop )
            {
            tracknum = 0;
            Track = _MIDI_TrackPtr;
            }
         else
            {
            _MIDI_SongActive = FALSE;
            break;
            }
         }
      }

   _MIDI_AdvanceTick();
   }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x0, 0x13028(%rip)     # 0x1f0bc
jne 0xc09b
jmp 0xc432
movq 0x1301e(%rip), %rax     # 0x1f0c0
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x13012(%rip), %eax     # 0x1f0c8
jge 0xc42d
jmp 0xc0be
movq -0x18(%rbp), %rax
movswl 0x14(%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x2d(%rbp)
je 0xc0de
movq -0x18(%rbp), %rax
cmpl $0x0, 0x10(%rax)
sete %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
testb $0x1, %al
jne 0xc0ea
jmp 0xc3cb
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movzbl (%rax), %eax
movl %eax, -0x4(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movl -0x4(%rbp), %eax
sarl $0x4, %eax
cmpl $0xf, %eax
jne 0xc170
movl -0x4(%rbp), %eax
movl %eax, -0x34(%rbp)
subl $0xf0, %eax
je 0xc13a
jmp 0xc122
movl -0x34(%rbp), %eax
subl $0xf7, %eax
je 0xc13a
jmp 0xc12e
movl -0x34(%rbp), %eax
subl $0xff, %eax
je 0xc145
jmp 0xc14e
movq -0x18(%rbp), %rdi
callq 0xcb70
jmp 0xc14e
movq -0x18(%rbp), %rdi
callq 0xcc30
movq -0x18(%rbp), %rax
cmpw $0x0, 0x14(%rax)
je 0xc16b
movq -0x18(%rbp), %rdi
callq 0xcaf0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0xc0be
movl -0x4(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xc18d
movl -0x4(%rbp), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x16(%rax)
jmp 0xc1a8
movq -0x18(%rbp), %rax
movswl 0x16(%rax), %eax
movl %eax, -0x4(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movl -0x4(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x8(%rbp)
movl -0x4(%rbp), %eax
sarl $0x4, %eax
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0x387b(%rip), %rax      # 0xfa40
cmpl $0x0, (%rax,%rcx,4)
jle 0xc21a
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movzbl (%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movslq -0xc(%rbp), %rcx
leaq 0x384c(%rip), %rax      # 0xfa40
cmpl $0x1, (%rax,%rcx,4)
jle 0xc218
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movzbl (%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
jmp 0xc21a
movslq -0x8(%rbp), %rcx
leaq 0x12dbb(%rip), %rax     # 0x1efe0
cmpq $0x0, (%rax,%rcx,8)
je 0xc268
movslq -0x8(%rbp), %rcx
leaq 0x12da9(%rip), %rax     # 0x1efe0
movq (%rax,%rcx,8), %rax
movl -0x4(%rbp), %edi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
callq *%rax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0xc266
movq -0x18(%rbp), %rdi
callq 0xcaf0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0xc0be
jmp 0xc268
movl -0xc(%rbp), %eax
addl $-0x8, %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x6, %eax
ja 0xc3b2
movq -0x40(%rbp), %rax
leaq 0x35a0(%rip), %rcx      # 0xf828
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x12e10(%rip), %rax     # 0x1f0a8
cmpq $0x0, (%rax)
je 0xc2b3
movq 0x12e03(%rip), %rax     # 0x1f0a8
movq (%rax), %rax
movl -0x8(%rbp), %edi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
callq *%rax
jmp 0xc3b4
movq 0x12de9(%rip), %rax     # 0x1f0a8
cmpq $0x0, 0x8(%rax)
je 0xc2dc
movq 0x12ddb(%rip), %rax     # 0x1f0a8
movq 0x8(%rax), %rax
movl -0x8(%rbp), %edi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
callq *%rax
jmp 0xc3b4
movq 0x12dc0(%rip), %rax     # 0x1f0a8
cmpq $0x0, 0x10(%rax)
je 0xc305
movq 0x12db2(%rip), %rax     # 0x1f0a8
movq 0x10(%rax), %rax
movl -0x8(%rbp), %edi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
callq *%rax
jmp 0xc3b4
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x8(%rbp), %edx
movl -0x24(%rbp), %ecx
movl -0x28(%rbp), %r8d
callq 0xcdb0
movl %eax, -0x2c(%rbp)
jmp 0xc3b4
movq 0x12d79(%rip), %rax     # 0x1f0a8
cmpq $0x0, 0x20(%rax)
je 0xc367
movq -0x18(%rbp), %rax
cmpb $0x0, 0x171(%rax)
jne 0xc367
movq 0x12d5e(%rip), %rax     # 0x1f0a8
movq 0x20(%rax), %rax
movl -0x8(%rbp), %edi
movl -0x24(%rbp), %ecx
andl $0x7f, %ecx
movslq %ecx, %rdx
leaq 0x12d9f(%rip), %rcx     # 0x1f100
movsbl (%rcx,%rdx), %esi
callq *%rax
jmp 0xc3b4
movq 0x12d38(%rip), %rax     # 0x1f0a8
cmpq $0x0, 0x28(%rax)
je 0xc38a
movq 0x12d2a(%rip), %rax     # 0x1f0a8
movq 0x28(%rax), %rax
movl -0x8(%rbp), %edi
movl -0x24(%rbp), %esi
callq *%rax
jmp 0xc3b4
movq 0x12d15(%rip), %rax     # 0x1f0a8
cmpq $0x0, 0x30(%rax)
je 0xc3b0
movq 0x12d07(%rip), %rax     # 0x1f0a8
movq 0x30(%rax), %rax
movl -0x8(%rbp), %edi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
callq *%rax
jmp 0xc3b4
jmp 0xc3b4
movq -0x18(%rbp), %rdi
callq 0xcaf0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0xc0be
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
addq $0x178, %rax            # imm = 0x178
movq %rax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, 0x12cf6(%rip)     # 0x1f0ec
jne 0xc428
callq 0xb260
cmpl $0x0, 0x12cb0(%rip)     # 0x1f0b4
je 0xc41a
movl $0x0, -0x1c(%rbp)
movq 0x12cac(%rip), %rax     # 0x1f0c0
movq %rax, -0x18(%rbp)
jmp 0xc426
movl $0x0, 0x12c98(%rip)     # 0x1f0bc
jmp 0xc42d
jmp 0xc428
jmp 0xc0ad
callq 0xd370
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)