// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
movq %rdi, %r14
movl 0x700d(%rip), %ecx      # 0x90ec
testl %ecx, %ecx
jle 0x212b
leaq 0x712a(%rip), %rax      # 0x9214
xorl %ebx, %ebx
cmpb $0x1, -0x14(%rax)
jne 0x2119
movl -0x4(%rax), %edx
cmpl 0xc(%r14), %edx
jne 0x2119
movl -0x8(%rax), %edx
cmpl 0x8(%r14), %edx
jne 0x2119
movl -0xc(%rax), %edx
cmpl 0x4(%r14), %edx
jne 0x2119
movl (%rax), %edx
cmpl 0x10(%r14), %edx
je 0x21f5
incq %rbx
addq $0x1c, %rax
cmpq %rbx, %rcx
jne 0x20ec
xorl %eax, %eax
movl %ecx, %ebx
jmp 0x212f
xorl %ebx, %ebx
xorl %eax, %eax
testb %al, %al
jne 0x2178
cmpb $0x1, 0x7093(%rip)      # 0x91cd
jne 0x2178
movslq 0x4(%r14), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
leaq 0x7271(%rip), %rdx      # 0x93c0
movslq 0x20(%rcx,%rdx), %rcx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
leaq 0x709a(%rip), %rsi      # 0x9200
cmpb $0x0, (%rsi,%rdx)
cmovel %ecx, %ebx
movzbl %al, %ecx
movl $0x1, %eax
cmovnel %ecx, %eax
testb %al, %al
jne 0x21b3
movl 0x6f6a(%rip), %ecx      # 0x90ec
testl %ecx, %ecx
jle 0x21ad
leaq 0x7073(%rip), %rdx      # 0x9200
xorl %ebx, %ebx
cmpb $0x0, (%rdx)
jne 0x219d
movl 0x14(%rdx), %esi
cmpl 0x10(%r14), %esi
je 0x21b1
incq %rbx
addq $0x1c, %rdx
cmpq %rbx, %rcx
jne 0x218f
movl %ecx, %ebx
jmp 0x21b3
xorl %ebx, %ebx
jmp 0x21b3
movb $0x1, %al
testb %al, %al
jne 0x21e5
movl 0x6f2f(%rip), %ecx      # 0x90ec
testl %ecx, %ecx
jle 0x21df
leaq 0x7038(%rip), %rdx      # 0x9200
xorl %ebx, %ebx
cmpb $0x1, (%rdx)
jne 0x21e3
incq %rbx
addq $0x1c, %rdx
cmpq %rbx, %rcx
jne 0x21ca
movl %ecx, %ebx
jmp 0x21e5
xorl %ebx, %ebx
jmp 0x21e5
movb $0x1, %al
testb %al, %al
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %ebx, %eax
popq %rbx
popq %r14
popq %r15
retq
incl 0x6f55(%rip)            # 0x9150
cmpb $0x0, 0x6fc1(%rip)      # 0x91c3
je 0x222d
movq 0x6fcd(%rip), %r15      # 0x91d8
movq %r14, %rdi
callq 0x1e3b
leaq 0x399a(%rip), %rsi      # 0x5bb4
leaq 0x8f5f(%rip), %rcx      # 0xb180
movq %r15, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x10b0
movb $0x1, %al
jmp 0x212f