// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movb $0x0, 0x1b(%rsp)
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x8adc(%rip), %eax      # 0xb0dc
jge 0x26df
movslq 0x1c(%rsp), %rcx
leaq 0x8d2e(%rip), %rax      # 0xb340
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
testb $0x1, (%rax)
je 0x26cd
movq 0x20(%rsp), %rax
movl 0x10(%rax), %eax
movq 0x28(%rsp), %rcx
cmpl 0xc(%rcx), %eax
jne 0x26cd
movq 0x20(%rsp), %rax
movl 0xc(%rax), %eax
movq 0x28(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x26cd
movq 0x20(%rsp), %rax
movl 0x8(%rax), %eax
movq 0x28(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x26cd
movq 0x20(%rsp), %rax
movl 0x14(%rax), %eax
movq 0x28(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x26cd
movl 0x8c12(%rip), %eax      # 0xb290
addl $0x1, %eax
movl %eax, 0x8c09(%rip)      # 0xb290
testb $0x1, 0x8c75(%rip)      # 0xb303
je 0x26c6
movq 0x8c81(%rip), %rax      # 0xb318
movq %rax, (%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rdi
callq 0x2260
movq (%rsp), %rdi
movl 0xc(%rsp), %edx
movq %rax, %rcx
leaq 0x56a9(%rip), %rsi      # 0x7d68
movb $0x0, %al
callq 0x10a0
movb $0x1, 0x1b(%rsp)
jmp 0x26df
jmp 0x26cf
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x25f6
testb $0x1, 0x1b(%rsp)
jne 0x2744
testb $0x1, 0x8c20(%rip)      # 0xb30d
je 0x2744
movq 0x28(%rsp), %rax
movslq 0x4(%rax), %rcx
leaq 0x8e01(%rip), %rax      # 0xb500
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movslq 0x20(%rax), %rcx
leaq 0x8c25(%rip), %rax      # 0xb340
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
testb $0x1, (%rax)
jne 0x2742
movq 0x10(%rsp), %rax
movl 0x20(%rax), %eax
movl %eax, 0x1c(%rsp)
movb $0x1, 0x1b(%rsp)
jmp 0x2744
testb $0x1, 0x1b(%rsp)
jne 0x27ab
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x897f(%rip), %eax      # 0xb0dc
jge 0x27a9
movslq 0x1c(%rsp), %rcx
leaq 0x8bd5(%rip), %rax      # 0xb340
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
testb $0x1, (%rax)
jne 0x279a
movq 0x20(%rsp), %rax
movl 0x14(%rax), %eax
movq 0x28(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x279a
movb $0x1, 0x1b(%rsp)
jmp 0x27a9
jmp 0x279c
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x2753
jmp 0x27ab
testb $0x1, 0x1b(%rsp)
jne 0x2800
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x8918(%rip), %eax      # 0xb0dc
jge 0x27fe
movslq 0x1c(%rsp), %rcx
leaq 0x8b6e(%rip), %rax      # 0xb340
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
testb $0x1, (%rax)
jne 0x27ef
movb $0x1, 0x1b(%rsp)
jmp 0x27fe
jmp 0x27f1
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x27ba
jmp 0x2800
testb $0x1, 0x1b(%rsp)
je 0x2811
movl 0x1c(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x2819
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)