// File: /workspace/github_c_makefile_star2_O3/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 0x70ae(%rip), %eax      # 0x90ec
testl %eax, %eax
jle 0x2084
leaq 0x71cb(%rip), %rcx      # 0x9214
xorl %ebx, %ebx
cmpb $0x1, -0x14(%rcx)
jne 0x2074
movl -0x4(%rcx), %edx
cmpl 0xc(%rdi), %edx
jne 0x2074
movl -0x8(%rcx), %edx
cmpl 0x8(%rdi), %edx
jne 0x2074
movl -0xc(%rcx), %edx
cmpl 0x4(%rdi), %edx
jne 0x2074
movl (%rcx), %edx
cmpl 0x10(%rdi), %edx
je 0x211c
incq %rbx
addq $0x1c, %rcx
cmpq %rbx, %rax
jne 0x204b
movl %eax, %ebx
jmp 0x2086
xorl %ebx, %ebx
xorl %ecx, %ecx
cmpb $0x1, 0x713e(%rip)      # 0x91cd
jne 0x20d0
movslq 0x4(%rdi), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
leaq 0x731c(%rip), %rdx      # 0x93c0
movslq 0x20(%rcx,%rdx), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
leaq 0x7145(%rip), %rsi      # 0x9200
movb (%rsi,%rcx), %sil
movl %esi, %ecx
xorb $0x1, %cl
testb %sil, %sil
cmovel %edx, %ebx
je 0x2153
testl %eax, %eax
jle 0x2118
leaq 0x7125(%rip), %rdx      # 0x9200
xorl %ebx, %ebx
cmpb $0x0, (%rdx)
jne 0x20ea
movl 0x14(%rdx), %esi
cmpl 0x10(%rdi), %esi
je 0x2151
incq %rbx
addq $0x1c, %rdx
cmpq %rbx, %rax
jne 0x20dd
testl %eax, %eax
jle 0x2118
leaq 0x70ff(%rip), %rdx      # 0x9200
xorl %ebx, %ebx
cmpb $0x1, (%rdx)
jne 0x2151
incq %rbx
addq $0x1c, %rdx
cmpq %rbx, %rax
jne 0x2103
movl %eax, %ebx
jmp 0x2153
xorl %ebx, %ebx
jmp 0x2153
incl 0x702e(%rip)            # 0x9150
cmpb $0x0, 0x709a(%rip)      # 0x91c3
je 0x2151
movq 0x70a6(%rip), %r14      # 0x91d8
callq 0x1da6
leaq 0x3a76(%rip), %rsi      # 0x5bb4
leaq 0x903b(%rip), %rcx      # 0xb180
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x10b0
movb $0x1, %cl
testb %cl, %cl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq