// File: /workspace/github_c_makefile_star2_O0/LenShustek[P]miditones/miditones.c
// Function: remove_queue_entry
void remove_queue_entry(int ndx) { // remove the oldest queue entry
   struct queue_entry *q = &queue[ndx];
   if (q->delete) return; // if marked for deletion, just ignore it
   if (q->cmd == CMD_STOPNOTE) {
      if (loggen) fprintf(logfile, "      dequeue stopnote for %s\n", describe(&q->note));
      // find the tone generator playing this note, and record a pending stop
      int tgnum;
      for (tgnum = 0; tgnum < num_tonegens; ++tgnum) {
         struct tonegen_status *tg = &tonegen[tgnum];
         if (tg->playing
               && tg->note.note == q->note.note
               && tg->note.channel == q->note.channel) {  // found the note
            tg->stopnote_pending = true; // "stop note needed unless another start note follows"
            tg->playing = false; // free the tg to be reallocated, but note the stop time in case
            tg->note.time_usec = q->note.time_usec;  // the tg doesn't get used and we generate it
            if (loggen) fprintf(logfile, "      pending stop tgen %d %s\n", tgnum, describe(&q->note));
            break; } }
      if (tgnum >= num_tonegens) {
         // If we exited the loop without finding the generator playing this note, presumably it never started
         // because there weren't any free tone generators. Is there some assertion we can use to verify that?
         ++stopnotes_without_playnotes;
         if (loggen) fprintf(logfile, "      *** stopnote without playnote, %s\n", describe(&q->note)); } }

   else { // CMD_PLAYNOTE
      assert(q->cmd == CMD_PLAYNOTE, "bad cmd in remove_queue_entry");
      if (loggen) fprintf(logfile, "      dequeue playnote for %s\n", describe(&q->note));
      int tgnum = find_idle_tgen(&q->note);
      struct tonegen_status *tg = &tonegen[tgnum];
      if (tgnum >= 0) { // we found a tone generator we can use
         if (tgnum + 1 > num_tonegens_used) num_tonegens_used = tgnum + 1;
         if (tg->note.instrument != q->note.instrument) { // it's a new instrument for this generator
            tg->note.instrument = q->note.instrument;
            ++instrument_changes;
            if (loggen) fprintf(logfile, "      tgen %d changed to instrument %d\n", tgnum, tg->note.instrument);
            if (instrumentoutput) { // output a "change instrument" command
               if (binaryoutput) {
                  putc(CMD_INSTRUMENT | tgnum, outfile);
                  putc(tg->note.instrument, outfile);
                  outfile_bytecount += 2; }
               else if (asm_output) {
                  fprintf(outfile, "%s%02X", hex, CMD_INSTRUMENT | tgnum);
                  outfile_items(1);
                  fprintf(outfile, "%3d", tg->note.instrument);
                  outfile_items(1); }
               else {
                  fprintf(outfile, "0x%02X,%d", CMD_INSTRUMENT | tgnum, tg->note.instrument);
                  outfile_items(2); } } }
         if (loggen) fprintf(logfile, "      play tgen %d %s\n", tgnum, describe(&q->note));
         tg->playing = true;
         tg->stopnote_pending = false; // don't bother to issue "stop note"
         tg->note = q->note;  // structure copy of note info
         track[tg->note.track].preferred_tonegen = tgnum;
         ++note_on_commands;
         last_output_was_delay = false;
         if (binaryoutput) {
            putc(CMD_PLAYNOTE | tgnum, outfile);
            putc(tg->note.note, outfile);
            outfile_bytecount += 2;
            if (volume_output) {
               putc(tg->note.volume, outfile);
               outfile_bytecount +=1; } }
         else if (asm_output) {
            fprintf(outfile, "%s%02X", hex, CMD_PLAYNOTE | tgnum);
            outfile_items(1);
            fprintf(outfile, "%3d", tg->note.note);
            outfile_items(1);
            if (volume_output) {
               fprintf(outfile, "%3d", tg->note.volume);
               outfile_items(1); } }
         else {
            if (volume_output == 0) {
               fprintf(outfile, "0x%02X,%d", CMD_PLAYNOTE | tgnum, tg->note.note);
               outfile_items(2); }
            else {
               fprintf(outfile, "0x%02X,%d,%d", CMD_PLAYNOTE | tgnum, tg->note.note, tg->note.volume);
               outfile_items(3); } } }
      else {
         if (loggen) fprintf(logfile, "  *** at %lu.%03lu msec no free generator; skipping %s\n",
                                output_usec / 1000, output_usec % 1000, describe(&q->note));
         if (showskipped) printf("  *** no free generator %s\n",
                                    describe(&q->note)); ++notes_skipped; } } }

// Assembly:
subq $0x78, %rsp
movl %edi, 0x74(%rsp)
movslq 0x74(%rsp), %rcx
leaq 0xaafc(%rip), %rax      # 0xd340
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rax
cmpb $0x0, 0x1(%rax)
je 0x2860
jmp 0x2ebd
movq 0x68(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x80, %eax
jne 0x29e3
testb $0x1, 0x8a89(%rip)      # 0xb303
je 0x28ac
movq 0x8a95(%rip), %rax      # 0xb318
movq %rax, 0x40(%rsp)
movq 0x68(%rsp), %rdi
addq $0x4, %rdi
callq 0x2260
movq 0x40(%rsp), %rdi
movq %rax, %rdx
leaq 0x54f5(%rip), %rsi      # 0x7d9a
movb $0x0, %al
callq 0x10a0
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
cmpl 0x881e(%rip), %eax      # 0xb0dc
jge 0x2988
movslq 0x64(%rsp), %rcx
leaq 0x8a70(%rip), %rax      # 0xb340
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rax
testb $0x1, (%rax)
je 0x2976
movq 0x58(%rsp), %rax
movl 0x10(%rax), %eax
movq 0x68(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x2976
movq 0x58(%rsp), %rax
movl 0xc(%rax), %eax
movq 0x68(%rsp), %rcx
cmpl 0xc(%rcx), %eax
jne 0x2976
movq 0x58(%rsp), %rax
movb $0x1, 0x1(%rax)
movq 0x58(%rsp), %rax
movb $0x0, (%rax)
movq 0x68(%rsp), %rax
movl 0x4(%rax), %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0x4(%rax)
testb $0x1, 0x89cd(%rip)      # 0xb303
je 0x2974
movq 0x89d9(%rip), %rax      # 0xb318
movq %rax, 0x30(%rsp)
movl 0x64(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x68(%rsp), %rdi
addq $0x4, %rdi
callq 0x2260
movq 0x30(%rsp), %rdi
movl 0x3c(%rsp), %edx
movq %rax, %rcx
leaq 0x544c(%rip), %rsi      # 0x7db9
movb $0x0, %al
callq 0x10a0
jmp 0x2988
jmp 0x2978
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x28b4
movl 0x64(%rsp), %eax
cmpl 0x874a(%rip), %eax      # 0xb0dc
jl 0x29de
movl 0x88f2(%rip), %eax      # 0xb28c
addl $0x1, %eax
movl %eax, 0x88e9(%rip)      # 0xb28c
testb $0x1, 0x8959(%rip)      # 0xb303
je 0x29dc
movq 0x8965(%rip), %rax      # 0xb318
movq %rax, 0x28(%rsp)
movq 0x68(%rsp), %rdi
addq $0x4, %rdi
callq 0x2260
movq 0x28(%rsp), %rdi
movq %rax, %rdx
leaq 0x5403(%rip), %rsi      # 0x7dd8
movb $0x0, %al
callq 0x10a0
jmp 0x29de
jmp 0x2ebd
movq 0x68(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x90, %eax
sete %al
movzbl %al, %edi
andl $0x1, %edi
leaq 0x5401(%rip), %rsi      # 0x7e01
callq 0x1c70
testb $0x1, 0x88f7(%rip)      # 0xb303
je 0x2a3e
movq 0x8903(%rip), %rax      # 0xb318
movq %rax, 0x20(%rsp)
movq 0x68(%rsp), %rdi
addq $0x4, %rdi
callq 0x2260
movq 0x20(%rsp), %rdi
movq %rax, %rdx
leaq 0x53e8(%rip), %rsi      # 0x7e1f
movb $0x0, %al
callq 0x10a0
movq 0x68(%rsp), %rdi
addq $0x4, %rdi
callq 0x25e0
movl %eax, 0x54(%rsp)
movslq 0x54(%rsp), %rcx
leaq 0x88e4(%rip), %rax      # 0xb340
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x48(%rsp)
cmpl $0x0, 0x54(%rsp)
jl 0x2e1f
movl 0x54(%rsp), %eax
addl $0x1, %eax
cmpl 0x87f8(%rip), %eax      # 0xb278
jle 0x2a8f
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x87e9(%rip)      # 0xb278
movq 0x48(%rsp), %rax
movl 0x14(%rax), %eax
movq 0x68(%rsp), %rcx
cmpl 0x14(%rcx), %eax
je 0x2bde
movq 0x68(%rsp), %rax
movl 0x14(%rax), %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x14(%rax)
movl 0x87c1(%rip), %eax      # 0xb27c
addl $0x1, %eax
movl %eax, 0x87b8(%rip)      # 0xb27c
testb $0x1, 0x8838(%rip)      # 0xb303
je 0x2aee
movq 0x8844(%rip), %rdi      # 0xb318
movl 0x54(%rsp), %edx
movq 0x48(%rsp), %rax
movl 0x14(%rax), %ecx
leaq 0x5357(%rip), %rsi      # 0x7e3e
movb $0x0, %al
callq 0x10a0
testb $0x1, 0x880f(%rip)      # 0xb304
je 0x2bdc
testb $0x1, 0x87fe(%rip)      # 0xb300
je 0x2b45
movl 0x54(%rsp), %edi
orl $0xc0, %edi
movq 0x881b(%rip), %rsi      # 0xb330
callq 0x1090
movq 0x48(%rsp), %rax
movl 0x14(%rax), %edi
movq 0x8807(%rip), %rsi      # 0xb330
callq 0x1090
movq 0x8793(%rip), %rax      # 0xb2c8
addq $0x2, %rax
movq %rax, 0x8788(%rip)      # 0xb2c8
jmp 0x2bda
testb $0x1, 0x87be(%rip)      # 0xb30a
je 0x2ba7
movq 0x87db(%rip), %rdi      # 0xb330
movq 0x856c(%rip), %rdx      # 0xb0c8
movl 0x54(%rsp), %ecx
orl $0xc0, %ecx
leaq 0x52f9(%rip), %rsi      # 0x7e66
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x21c0
movq 0x87ab(%rip), %rdi      # 0xb330
movq 0x48(%rsp), %rax
movl 0x14(%rax), %edx
leaq 0x52d9(%rip), %rsi      # 0x7e6d
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x21c0
jmp 0x2bd8
movq 0x8782(%rip), %rdi      # 0xb330
movl 0x54(%rsp), %edx
orl $0xc0, %edx
movq 0x48(%rsp), %rax
movl 0x14(%rax), %ecx
leaq 0x52aa(%rip), %rsi      # 0x7e71
movb $0x0, %al
callq 0x10a0
movl $0x2, %edi
callq 0x21c0
jmp 0x2bda
jmp 0x2bdc
jmp 0x2bde
testb $0x1, 0x871e(%rip)      # 0xb303
je 0x2c23
movq 0x872a(%rip), %rax      # 0xb318
movq %rax, 0x10(%rsp)
movl 0x54(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x68(%rsp), %rdi
addq $0x4, %rdi
callq 0x2260
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %edx
movq %rax, %rcx
leaq 0x525f(%rip), %rsi      # 0x7e7b
movb $0x0, %al
callq 0x10a0
movq 0x48(%rsp), %rax
movb $0x1, (%rax)
movq 0x48(%rsp), %rax
movb $0x0, 0x1(%rax)
movq 0x48(%rsp), %rax
movq 0x68(%rsp), %rcx
movq 0x4(%rcx), %rdx
movq %rdx, 0x4(%rax)
movq 0xc(%rcx), %rdx
movq %rdx, 0xc(%rax)
movq 0x14(%rcx), %rcx
movq %rcx, 0x14(%rax)
movl 0x54(%rsp), %ecx
movq 0x48(%rsp), %rax
movslq 0x8(%rax), %rdx
leaq 0x8896(%rip), %rax      # 0xb500
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x20(%rax)
movl 0x8606(%rip), %eax      # 0xb280
addl $0x1, %eax
movl %eax, 0x85fd(%rip)      # 0xb280
movb $0x0, 0x8616(%rip)      # 0xb2a0
testb $0x1, 0x866f(%rip)      # 0xb300
je 0x2d03
movl 0x54(%rsp), %edi
orl $0x90, %edi
movq 0x868c(%rip), %rsi      # 0xb330
callq 0x1090
movq 0x48(%rsp), %rax
movl 0x10(%rax), %edi
movq 0x8678(%rip), %rsi      # 0xb330
callq 0x1090
movq 0x8604(%rip), %rax      # 0xb2c8
addq $0x2, %rax
movq %rax, 0x85f9(%rip)      # 0xb2c8
testb $0x1, 0x8635(%rip)      # 0xb30b
je 0x2cfe
movq 0x48(%rsp), %rax
movl 0x18(%rax), %edi
movq 0x8649(%rip), %rsi      # 0xb330
callq 0x1090
movq 0x85d5(%rip), %rax      # 0xb2c8
addq $0x1, %rax
movq %rax, 0x85ca(%rip)      # 0xb2c8
jmp 0x2e1a
testb $0x1, 0x8600(%rip)      # 0xb30a
je 0x2d99
movq 0x8619(%rip), %rdi      # 0xb330
movq 0x83aa(%rip), %rdx      # 0xb0c8
movl 0x54(%rsp), %ecx
orl $0x90, %ecx
leaq 0x5137(%rip), %rsi      # 0x7e66
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x21c0
movq 0x85e9(%rip), %rdi      # 0xb330
movq 0x48(%rsp), %rax
movl 0x10(%rax), %edx
leaq 0x5117(%rip), %rsi      # 0x7e6d
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x21c0
testb $0x1, 0x859d(%rip)      # 0xb30b
je 0x2d97
movq 0x85b9(%rip), %rdi      # 0xb330
movq 0x48(%rsp), %rax
movl 0x18(%rax), %edx
leaq 0x50e7(%rip), %rsi      # 0x7e6d
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x21c0
jmp 0x2e18
movb 0x856c(%rip), %al       # 0xb30b
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2ddc
movq 0x8580(%rip), %rdi      # 0xb330
movl 0x54(%rsp), %edx
orl $0x90, %edx
movq 0x48(%rsp), %rax
movl 0x10(%rax), %ecx
leaq 0x50a8(%rip), %rsi      # 0x7e71
movb $0x0, %al
callq 0x10a0
movl $0x2, %edi
callq 0x21c0
jmp 0x2e16
movq 0x854d(%rip), %rdi      # 0xb330
movl 0x54(%rsp), %edx
orl $0x90, %edx
movq 0x48(%rsp), %rax
movl 0x10(%rax), %ecx
movq 0x48(%rsp), %rax
movl 0x18(%rax), %r8d
leaq 0x508d(%rip), %rsi      # 0x7e92
movb $0x0, %al
callq 0x10a0
movl $0x3, %edi
callq 0x21c0
jmp 0x2e18
jmp 0x2e1a
jmp 0x2ebb
testb $0x1, 0x84dd(%rip)      # 0xb303
je 0x2e84
movq 0x84e9(%rip), %rax      # 0xb318
movq %rax, (%rsp)
movl 0x84af(%rip), %eax      # 0xb2e8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, 0x8(%rsp)
movl 0x849c(%rip), %eax      # 0xb2e8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %edx, 0xc(%rsp)
movq 0x68(%rsp), %rdi
addq $0x4, %rdi
callq 0x2260
movq (%rsp), %rdi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
movq %rax, %r8
leaq 0x5022(%rip), %rsi      # 0x7e9f
movb $0x0, %al
callq 0x10a0
testb $0x1, 0x8484(%rip)      # 0xb30f
je 0x2eac
movq 0x68(%rsp), %rdi
addq $0x4, %rdi
callq 0x2260
movq %rax, %rsi
leaq 0x5032(%rip), %rdi      # 0x7ed7
movb $0x0, %al
callq 0x1070
movl 0x83d2(%rip), %eax      # 0xb284
addl $0x1, %eax
movl %eax, 0x83c9(%rip)      # 0xb284
jmp 0x2ebd
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)