// File: /workspace/github_c_makefile_star2_O2/LenShustek[P]miditones/miditones.c
// Function: find_idle_tgen
int find_idle_tgen(struct noteinfo *np) { // returns -1 if there isn't one
   struct tonegen_status *tg;
   int tgnum;
   bool foundgen = false;
   for (tgnum = 0; tgnum < num_tonegens; ++tgnum) { // first, is this note already playing on this channel?
      tg = &tonegen[tgnum];
      if (tg->playing
            && tg->note.note == np->note && tg->note.channel == np->channel
            && tg->note.track == np->track && tg->note.instrument == np->instrument) {
         // this must be the start of the sustain phase of a playing note
         ++playnotes_without_stopnotes;
         if (loggen) fprintf(logfile, "      *** playnote without stopnote, tgen %d, %s\n",
                                tgnum, describe(np));
         foundgen = true;
         break; } }
   if (!foundgen && strategy2) { // try to use the same tone generator that this track used last time
      struct track_status *trk = &track[np->track];
      tg = &tonegen[trk->preferred_tonegen];
      if (!tg->playing) {
         tgnum = trk->preferred_tonegen;
         foundgen = true; } }
   if (!foundgen)    // if not, then try for a free tone generator that had been playing the same instrument we need
      for (tgnum = 0; tgnum < num_tonegens; ++tgnum) {
         tg = &tonegen[tgnum];
         if (!tg->playing && tg->note.instrument == np->instrument) {
            foundgen = true;
            break; } }
   if (!foundgen)    // if not, then try for any free tone generator
      for (tgnum = 0; tgnum < num_tonegens; ++tgnum) {
         tg = &tonegen[tgnum];
         if (!tg->playing) {
            foundgen = true;
            break; } }
   if (foundgen) return tgnum;
   return -1; }

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl 0x71e1(%rip), %eax      # 0x90ec
xorl %ebx, %ebx
testl %eax, %eax
cmovlel %ebx, %eax
leaq 0x72fb(%rip), %rcx      # 0x9214
cmpq %rbx, %rax
je 0x1f50
cmpb $0x1, -0x14(%rcx)
jne 0x1f47
movl -0x4(%rcx), %edx
cmpl 0xc(%rdi), %edx
jne 0x1f47
movl -0x8(%rcx), %edx
cmpl 0x8(%rdi), %edx
jne 0x1f47
movl -0xc(%rcx), %edx
cmpl 0x4(%rdi), %edx
jne 0x1f47
movl (%rcx), %edx
cmpl 0x10(%rdi), %edx
je 0x1fcf
incq %rbx
addq $0x1c, %rcx
jmp 0x1f19
cmpb $0x1, 0x7276(%rip)      # 0x91cd
jne 0x1f89
movslq 0x4(%rdi), %rcx
imulq $0x30, %rcx, %rcx
leaq 0x7458(%rip), %rdx      # 0x93c0
movslq 0x20(%rcx,%rdx), %rbx
imulq $0x1c, %rbx, %rcx
leaq 0x7288(%rip), %rdx      # 0x9200
movb (%rcx,%rdx), %dl
movl %edx, %ecx
xorb $0x1, %cl
testb %dl, %dl
cmovnel %eax, %ebx
jne 0x1f8b
jmp 0x2006
xorl %ecx, %ecx
leaq 0x726e(%rip), %rdx      # 0x9200
xorl %ebx, %ebx
cmpq %rbx, %rax
je 0x1faf
cmpb $0x0, (%rdx)
jne 0x1fa6
movl 0x14(%rdx), %esi
cmpl 0x10(%rdi), %esi
je 0x2004
incq %rbx
addq $0x1c, %rdx
jmp 0x1f94
leaq 0x724a(%rip), %rdx      # 0x9200
xorl %ebx, %ebx
cmpq %rbx, %rax
je 0x1fcb
cmpb $0x1, (%rdx)
jne 0x2004
incq %rbx
addq $0x1c, %rdx
jmp 0x1fb8
movl %eax, %ebx
jmp 0x2006
incl 0x717b(%rip)            # 0x9150
cmpb $0x0, 0x71e7(%rip)      # 0x91c3
je 0x2004
movq 0x71f3(%rip), %r14      # 0x91d8
callq 0x1c93
leaq 0x3bc3(%rip), %rsi      # 0x5bb4
leaq 0x9188(%rip), %rcx      # 0xb180
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x10b0
movb $0x1, %cl
testb %cl, %cl
pushq $-0x1
popq %rax
cmovnel %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq