// File: /workspace/github_c_makefile_star2_O1/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, 0x11a64(%rip)     # 0x1967c
jne 0x7edd
cmpl $0x0, 0x11a63(%rip)     # 0x19688
jle 0x7ef3
movl $0x0, 0x4(%rsp)
movq 0x11a46(%rip), %r14     # 0x19680
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpw $0x0, 0x14(%r14)
je 0x7ce3
cmpl $0x0, 0x10(%r14)
jne 0x7ce3
movq 0x8(%r14), %rax
movzbl (%rax), %edi
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r14)
movl %edi, %ecx
notl %ecx
testb $-0x10, %cl
jne 0x7d2a
cmpl $0xf0, %edi
je 0x7c8d
cmpl $0xff, %edi
je 0x7c97
cmpl $0xf7, %edi
jne 0x7c9f
movq %r14, %rdi
callq 0x843a
jmp 0x7c9f
movq %r14, %rdi
callq 0x851b
cmpw $0x0, 0x14(%r14)
je 0x7c42
movq 0x8(%r14), %rcx
movzbl (%rcx), %eax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
testb %al, %al
jns 0x7cda
andl $0x7f, %eax
addq $0x2, %rcx
movzbl -0x1(%rcx), %edx
movq %rcx, 0x8(%r14)
shll $0x7, %eax
movl %edx, %esi
andl $0x7f, %esi
orl %esi, %eax
incq %rcx
testb %dl, %dl
js 0x7cc1
movl %eax, 0x10(%r14)
jmp 0x7c42
decl 0x10(%r14)
cmpl $0x0, 0x119ba(%rip)     # 0x196a8
je 0x7cfc
addq $0x178, %r14            # imm = 0x178
incl %r13d
jmp 0x7d18
callq 0x7210
cmpl $0x0, 0x1196c(%rip)     # 0x19674
je 0x7eec
xorl %r13d, %r13d
movq 0x11968(%rip), %r14     # 0x19680
cmpl 0x11969(%rip), %r13d    # 0x19688
jl 0x7c42
jmp 0x7ef3
testb %dil, %dil
js 0x7d3a
movswl 0x16(%r14), %edi
movq %rax, 0x8(%r14)
jmp 0x7d3f
movw %di, 0x16(%r14)
movl %edi, %ebx
sarl $0x4, %ebx
movslq %ebx, %rcx
leaq -0x8(%rcx), %rax
cmpq $0x6, %rax
ja 0x7d78
movq 0x8(%r14), %rax
movzbl (%rax), %r15d
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r14)
movl $0x4f00, %edx           # imm = 0x4F00
btq %rcx, %rdx
jae 0x7d78
movzbl 0x1(%rax), %ebp
addq $0x2, %rax
movq %rax, 0x8(%r14)
movl %edi, %r12d
andl $0xf, %r12d
movl %r12d, %eax
leaq 0x11817(%rip), %rcx     # 0x195a0
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x7dd9
movl %r15d, %esi
movl %ebp, %edx
callq *%rax
testl %eax, %eax
jne 0x7dd9
movq 0x8(%r14), %rcx
movzbl (%rcx), %eax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
testb %al, %al
jns 0x7cda
andl $0x7f, %eax
addq $0x2, %rcx
movzbl -0x1(%rcx), %edx
movq %rcx, 0x8(%r14)
shll $0x7, %eax
movl %edx, %esi
andl $0x7f, %esi
orl %esi, %eax
incq %rcx
testb %dl, %dl
js 0x7dbb
jmp 0x7cda
addl $-0x8, %ebx
cmpl $0x6, %ebx
ja 0x7ea1
leaq 0x2f5c(%rip), %rcx      # 0xad48
movslq (%rcx,%rbx,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x1186c(%rip), %rax     # 0x19668
movq (%rax), %rax
jmp 0x7e92
movq 0x1185d(%rip), %rax     # 0x19668
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x7ea1
cmpb $0x0, 0x171(%r14)
jne 0x7ea1
movl %r15d, %ecx
andl $0x7f, %ecx
leaq 0x11891(%rip), %rdx     # 0x196c0
movsbl (%rcx,%rdx), %esi
movl %r12d, %edi
jmp 0x7e83
movq 0x11829(%rip), %rax     # 0x19668
movq 0x10(%rax), %rax
jmp 0x7e92
movq %r14, %rdi
movl 0x4(%rsp), %esi
movl %r12d, %edx
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x865a
movl %eax, 0x4(%rsp)
jmp 0x7ea1
movq 0x11801(%rip), %rax     # 0x19668
movq 0x8(%rax), %rax
jmp 0x7e92
movq 0x117f4(%rip), %rax     # 0x19668
movq 0x28(%rax), %rax
testq %rax, %rax
je 0x7ea1
movl %r12d, %edi
movl %r15d, %esi
callq *%rax
jmp 0x7ea1
movq 0x117da(%rip), %rax     # 0x19668
movq 0x30(%rax), %rax
testq %rax, %rax
je 0x7ea1
movl %r12d, %edi
movl %r15d, %esi
movl %ebp, %edx
callq *%rax
movq 0x8(%r14), %rcx
movzbl (%rcx), %eax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
testb %al, %al
jns 0x7cda
andl $0x7f, %eax
addq $0x2, %rcx
movzbl -0x1(%rcx), %edx
movq %rcx, 0x8(%r14)
shll $0x7, %eax
movl %edx, %esi
andl $0x7f, %esi
orl %esi, %eax
incq %rcx
testb %dl, %dl
js 0x7ebf
jmp 0x7cda
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, 0x11789(%rip)     # 0x1967c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x89a0