// File: /workspace/github_c_makefile_star2_O3/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, 0x11a0c(%rip)     # 0x1967c
jne 0x7f3c
cmpl $0x0, 0x11a0b(%rip)     # 0x19688
jle 0x7f52
movl $0x0, 0x4(%rsp)
movq 0x119ee(%rip), %r15     # 0x19680
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpw $0x0, 0x14(%r15)
je 0x7d43
movl 0x10(%r15), %eax
testl %eax, %eax
jne 0x7d43
movq 0x8(%r15), %rcx
movzbl (%rcx), %edi
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%r15)
movl %edi, %edx
notl %edx
testb $-0x10, %dl
jne 0x7d8a
cmpl $0xf0, %edi
je 0x7ce6
cmpl $0xff, %edi
je 0x7cf0
cmpl $0xf7, %edi
jne 0x7cf8
movq %r15, %rdi
callq 0x84a8
jmp 0x7cf8
movq %r15, %rdi
callq 0x8591
movzwl 0x14(%r15), %ecx
testw %cx, %cx
je 0x7d43
movq 0x8(%r15), %rdx
movzbl (%rdx), %eax
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%r15)
testb %al, %al
jns 0x7d36
andl $0x7f, %eax
addq $0x2, %rdx
movzbl -0x1(%rdx), %esi
movq %rdx, 0x8(%r15)
shll $0x7, %eax
movl %esi, %edi
andl $0x7f, %edi
orl %edi, %eax
incq %rdx
testb %sil, %sil
js 0x7d1c
movl %eax, 0x10(%r15)
testw %cx, %cx
jne 0x7caa
decl 0x10(%r15)
cmpl $0x0, 0x1195a(%rip)     # 0x196a8
je 0x7d5c
addq $0x178, %r15            # imm = 0x178
incl %r13d
jmp 0x7d78
callq 0x72a0
cmpl $0x0, 0x1190c(%rip)     # 0x19674
je 0x7f4b
xorl %r13d, %r13d
movq 0x11908(%rip), %r15     # 0x19680
cmpl 0x11909(%rip), %r13d    # 0x19688
jl 0x7c9a
jmp 0x7f52
testb %dil, %dil
js 0x7d9d
movswl 0x16(%r15), %edi
movq %rcx, 0x8(%r15)
movq %rcx, %rax
jmp 0x7da2
movw %di, 0x16(%r15)
movl %edi, %ebx
sarl $0x4, %ebx
movslq %ebx, %rcx
leaq -0x8(%rcx), %rdx
cmpq $0x6, %rdx
ja 0x7dd7
movzbl (%rax), %r14d
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r15)
movl $0x4f00, %edx           # imm = 0x4F00
btq %rcx, %rdx
jae 0x7dd7
movzbl 0x1(%rax), %ebp
addq $0x2, %rax
movq %rax, 0x8(%r15)
movl %edi, %r12d
andl $0xf, %r12d
movl %r12d, %eax
leaq 0x117b8(%rip), %rcx     # 0x195a0
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x7e38
movl %r14d, %esi
movl %ebp, %edx
callq *%rax
testl %eax, %eax
jne 0x7e38
movq 0x8(%r15), %rcx
movzbl (%rcx), %eax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r15)
testb %al, %al
jns 0x7e2f
andl $0x7f, %eax
addq $0x2, %rcx
movzbl -0x1(%rcx), %edx
movq %rcx, 0x8(%r15)
shll $0x7, %eax
movl %edx, %esi
andl $0x7f, %esi
orl %esi, %eax
incq %rcx
testb %dl, %dl
js 0x7e16
movl %eax, 0x10(%r15)
jmp 0x7c9a
addl $-0x8, %ebx
cmpl $0x6, %ebx
ja 0x7f00
leaq 0x2f6d(%rip), %rcx      # 0xadb8
movslq (%rcx,%rbx,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x1180d(%rip), %rax     # 0x19668
movq (%rax), %rax
jmp 0x7ef1
movq 0x117fe(%rip), %rax     # 0x19668
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x7f00
cmpb $0x0, 0x171(%r15)
jne 0x7f00
movl %r14d, %ecx
andl $0x7f, %ecx
leaq 0x11832(%rip), %rdx     # 0x196c0
movsbl (%rcx,%rdx), %esi
movl %r12d, %edi
jmp 0x7ee2
movq 0x117ca(%rip), %rax     # 0x19668
movq 0x10(%rax), %rax
jmp 0x7ef1
movq %r15, %rdi
movl 0x4(%rsp), %esi
movl %r12d, %edx
movl %r14d, %ecx
movl %ebp, %r8d
callq 0x86ca
movl %eax, 0x4(%rsp)
jmp 0x7f00
movq 0x117a2(%rip), %rax     # 0x19668
movq 0x8(%rax), %rax
jmp 0x7ef1
movq 0x11795(%rip), %rax     # 0x19668
movq 0x28(%rax), %rax
testq %rax, %rax
je 0x7f00
movl %r12d, %edi
movl %r14d, %esi
callq *%rax
jmp 0x7f00
movq 0x1177b(%rip), %rax     # 0x19668
movq 0x30(%rax), %rax
testq %rax, %rax
je 0x7f00
movl %r12d, %edi
movl %r14d, %esi
movl %ebp, %edx
callq *%rax
movq 0x8(%r15), %rcx
movzbl (%rcx), %eax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r15)
testb %al, %al
jns 0x7e2f
andl $0x7f, %eax
addq $0x2, %rcx
movzbl -0x1(%rcx), %edx
movq %rcx, 0x8(%r15)
shll $0x7, %eax
movl %edx, %esi
andl $0x7f, %esi
orl %esi, %eax
incq %rcx
testb %dl, %dl
js 0x7f1e
jmp 0x7e2f
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, 0x1172a(%rip)     # 0x1967c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8a0e