// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpb $0x1, 0x111d5(%rip)     # 0x1868c
jne 0x76d5
xorl %r13d, %r13d
movq 0x111c9(%rip), %rbx     # 0x18690
xorl %ebp, %ebp
xorl %r14d, %r14d
movl $0x0, 0x4(%rsp)
cmpl 0x111bd(%rip), %r13d    # 0x18698
jge 0x76eb
cmpw $0x0, 0x14(%rbx)
movl 0x10(%rbx), %eax
je 0x769c
testl %eax, %eax
jne 0x769c
movq 0x8(%rbx), %rcx
movzbl (%rcx), %edi
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%rbx)
movl %edi, %edx
notl %edx
testb $-0x10, %dl
jne 0x754d
cmpl $0xf0, %edi
je 0x7527
cmpl $0xff, %edi
je 0x7531
cmpl $0xf7, %edi
jne 0x7539
movq %rbx, %rdi
callq 0x7ba4
jmp 0x7539
movq %rbx, %rdi
callq 0x7c3f
cmpw $0x0, 0x14(%rbx)
je 0x74e1
movq %rbx, %rdi
callq 0x7b70
movl %eax, 0x10(%rbx)
jmp 0x74e1
testb %dil, %dil
js 0x755f
movswl 0x16(%rbx), %edi
movq %rcx, 0x8(%rbx)
movq %rcx, %rax
jmp 0x7563
movw %di, 0x16(%rbx)
movl %edi, %r15d
sarl $0x4, %r15d
movslq %r15d, %rcx
leaq -0x8(%rcx), %rdx
cmpq $0x6, %rdx
ja 0x759a
movzbl (%rax), %ebp
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%rbx)
movl $0x4f00, %edx           # imm = 0x4F00
btq %rcx, %rdx
jae 0x759a
movzbl 0x1(%rax), %r14d
addq $0x2, %rax
movq %rax, 0x8(%rbx)
movl %edi, %r12d
andl $0xf, %r12d
movl %r12d, %eax
leaq 0x11005(%rip), %rcx     # 0x185b0
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x75bf
movl %ebp, %esi
movl %r14d, %edx
callq *%rax
testl %eax, %eax
je 0x7540
addl $-0x8, %r15d
cmpl $0x6, %r15d
ja 0x7540
leaq 0x2744(%rip), %rcx      # 0x9d18
movslq (%rcx,%r15,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x11094(%rip), %rax     # 0x18678
movq (%rax), %rax
jmp 0x7684
movq 0x11085(%rip), %rax     # 0x18678
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x7540
cmpb $0x0, 0x171(%rbx)
jne 0x7540
movl %ebp, %ecx
andl $0x7f, %ecx
leaq 0x110b7(%rip), %rdx     # 0x186d0
movsbl (%rcx,%rdx), %esi
movl %r12d, %edi
jmp 0x7672
movq 0x1104f(%rip), %rax     # 0x18678
movq 0x10(%rax), %rax
jmp 0x7684
movq %rbx, %rdi
movl 0x4(%rsp), %esi
movl %r12d, %edx
movl %ebp, %ecx
movl %r14d, %r8d
callq 0x7d1d
movl %eax, 0x4(%rsp)
jmp 0x7540
movq 0x11025(%rip), %rax     # 0x18678
movq 0x8(%rax), %rax
jmp 0x7684
movq 0x11018(%rip), %rax     # 0x18678
movq 0x28(%rax), %rax
testq %rax, %rax
je 0x7540
movl %r12d, %edi
movl %ebp, %esi
callq *%rax
jmp 0x7540
movq 0x10ff8(%rip), %rax     # 0x18678
movq 0x30(%rax), %rax
testq %rax, %rax
je 0x7540
movl %r12d, %edi
movl %ebp, %esi
movl %r14d, %edx
callq *%rax
jmp 0x7540
decl %eax
movl %eax, 0x10(%rbx)
addq $0x178, %rbx            # imm = 0x178
incl %r13d
cmpl $0x0, 0x11006(%rip)     # 0x186b8
jne 0x74d4
callq 0x6cac
cmpl $0x0, 0x10fc0(%rip)     # 0x18684
je 0x76e4
movq 0x10fc3(%rip), %rbx     # 0x18690
xorl %r13d, %r13d
jmp 0x74d4
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, 0x10fa1(%rip)     # 0x1868c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8032