// File: /workspace/github_c_makefile_star2_O2/LenShustek[P]miditones/miditones.c
// Function: pull_queue
void pull_queue(void) {
   if (loggen) fprintf(logfile, "    <-pull from queue at %lu.%03lu msec\n", output_usec / 1000, output_usec % 1000);
   timestamp oldtime = queue[queue_oldest_ndx].note.time_usec; // the oldest time
   assert(oldtime >= output_usec, "oldest queue entry goes backward in pull_queue");
   unsigned long delta_usec = (oldtime - output_usec) + output_deficit_usec;
   unsigned long delta_msec = delta_usec / 1000;
   output_deficit_usec = delta_usec % 1000;
   if (delta_usec > (unsigned long)delaymin_usec) { // if time has advanced beyond the merge threshold, output a delay
      if (delta_msec > 0) {
         generate_delay(delta_msec);
         if (loggen) fprintf(logfile, "      at %lu.%03lu msec, delay for %ld msec to %lu.%03lu msec; deficit is %lu usec\n",
                                output_usec / 1000, output_usec % 1000, delta_msec,
                                oldtime / 1000, oldtime % 1000, output_deficit_usec); }
      else if (loggen) fprintf(logfile, "      at %lu.%03lu msec, a delay of only %lu usec was skipped, and the deficit is now %lu usec\n",
                                  output_usec / 1000, output_usec % 1000, oldtime-output_usec, output_deficit_usec);
      output_usec = oldtime; }
   else if (delta_msec > 0) ++delays_saved;

   do {  // output and remove all entries at the same (oldest) time in the queue
      // or which are only delaymin newer
      remove_queue_entry(queue_oldest_ndx);
      if (++queue_oldest_ndx >= QUEUE_SIZE) queue_oldest_ndx = 0;
      --queue_numitems; }
   while (queue_numitems > 0 && queue[queue_oldest_ndx].note.time_usec <= oldtime + (timestamp)delaymin_usec);

   // do any "stop notes" still need to be generated?
   for (int tgnum = 0; tgnum < num_tonegens; ++tgnum) {
      struct tonegen_status *tg = &tonegen[tgnum];
      if (tg->stopnote_pending) { // got one
         last_output_was_delay = false;
         if (binaryoutput) {
            putc(CMD_STOPNOTE | tgnum, outfile);
            outfile_bytecount += 1; }
         else {
            fprintf(outfile, "%s%02X", hex, CMD_STOPNOTE | tgnum);
            outfile_items(1); }
         if (loggen) fprintf(logfile, "      stop tgen %d %s\n", tgnum, describe(&tg->note));
         tg->stopnote_pending = false;
         tg->playing = false; } } }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpb $0x1, 0x6b7e(%rip)      # 0x91c3
jne 0x266f
movq 0x6b8a(%rip), %rdi      # 0x91d8
movl 0x6b54(%rip), %eax      # 0x91a8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %edx, %ecx
leaq 0x3727(%rip), %rsi      # 0x5d8d
movl %eax, %edx
xorl %eax, %eax
callq 0x10b0
movslq 0x8b72(%rip), %rax      # 0xb1e8
imulq $0x1c, %rax, %rax
leaq 0x8b7f(%rip), %r15      # 0xb200
movl 0x4(%rax,%r15), %ebx
xorl %edi, %edi
cmpl 0x6b1a(%rip), %ebx      # 0x91a8
setae %dil
leaq 0x371d(%rip), %rsi      # 0x5db6
callq 0x19f1
movl 0x6b04(%rip), %ecx      # 0x91a8
movl %ebx, %r8d
subl %ecx, %r8d
movl 0x6afc(%rip), %esi      # 0x91ac
addl %r8d, %esi
movl $0x3e8, %edi            # imm = 0x3E8
movl %esi, %eax
xorl %edx, %edx
divl %edi
movl %edx, 0x6ae8(%rip)      # 0x91ac
cmpq %rsi, 0x6aa5(%rip)      # 0x9170
jae 0x270b
cmpl $0x3e8, %esi            # imm = 0x3E8
jae 0x271c
cmpb $0x1, 0x6ae7(%rip)      # 0x91c3
jne 0x2778
movl %edx, %r9d
movq 0x6aec(%rip), %rdi      # 0x91d8
movl $0x3e8, %esi            # imm = 0x3E8
movl %ecx, %eax
xorl %edx, %edx
divl %esi
movl %edx, %ecx
leaq 0x3739(%rip), %rsi      # 0x5e39
movl %eax, %edx
xorl %eax, %eax
callq 0x10b0
jmp 0x2778
cmpl $0x3e8, %esi            # imm = 0x3E8
jb 0x277e
incq 0x6a9e(%rip)            # 0x91b8
jmp 0x277e
movl %eax, %r14d
movq %r14, %rdi
callq 0x2501
cmpb $0x1, 0x6a95(%rip)      # 0x91c3
jne 0x2778
movq 0x6aa1(%rip), %rdi      # 0x91d8
movl 0x6a6b(%rip), %eax      # 0x91a8
movl $0x3e8, %esi            # imm = 0x3E8
xorl %edx, %edx
divl %esi
movl %edx, %ecx
movl %eax, %r8d
movl %ebx, %eax
xorl %edx, %edx
divl %esi
movl %edx, %r10d
movl 0x6a51(%rip), %r11d     # 0x91ac
leaq 0x3683(%rip), %rsi      # 0x5de5
movl %r8d, %edx
movq %r14, %r8
movl %eax, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x10b0
popq %rcx
popq %rdx
movl %ebx, 0x6a2a(%rip)      # 0x91a8
movl 0x8a64(%rip), %edi      # 0xb1e8
xorl %ebp, %ebp
callq 0x2016
movl 0x8a57(%rip), %eax      # 0xb1e8
leal 0x1(%rax), %edi
cmpl $0x63, %eax
cmovgel %ebp, %edi
movl %edi, 0x8a48(%rip)      # 0xb1e8
movl 0x8a3e(%rip), %eax      # 0xb1e4
leal -0x1(%rax), %ecx
movl %ecx, 0x8a35(%rip)      # 0xb1e4
cmpl $0x2, %eax
jl 0x27ca
movslq %edi, %rax
imulq $0x1c, %rax, %rax
movl 0x69af(%rip), %ecx      # 0x9170
addl %ebx, %ecx
cmpl %ecx, 0x4(%rax,%r15)
jbe 0x2786
leaq 0x6a33(%rip), %rbx      # 0x9204
leaq 0x89a8(%rip), %r15      # 0xb180
leaq 0x34d3(%rip), %r12      # 0x5cb2
pushq $0x1
popq %rbp
xorl %r13d, %r13d
movslq 0x6900(%rip), %rax      # 0x90ec
cmpq %rax, %r13
jge 0x2895
cmpb $0x1, -0x3(%rbx)
jne 0x2889
movb $0x0, 0x695a(%rip)      # 0x9160
cmpb $0x1, 0x69b3(%rip)      # 0x91c0
jne 0x282d
movl %r13d, %edi
orl $0x80, %edi
movq 0x69d1(%rip), %rsi      # 0x91f0
callq 0x10a0
incq 0x695d(%rip)            # 0x9188
jmp 0x2855
movq 0x69bc(%rip), %rdi      # 0x91f0
movq 0x689d(%rip), %rdx      # 0x90d8
movl %r13d, %ecx
orl $0x80, %ecx
movq %r12, %rsi
xorl %eax, %eax
callq 0x10b0
movl %ebp, %edi
callq 0x1c0a
cmpb $0x1, 0x6967(%rip)      # 0x91c3
jne 0x2884
movq 0x6973(%rip), %r14      # 0x91d8
movq %rbx, %rdi
callq 0x1c93
movq %r14, %rdi
leaq 0x3622(%rip), %rsi      # 0x5e99
movl %r13d, %edx
movq %r15, %rcx
xorl %eax, %eax
callq 0x10b0
andw $0x0, -0x4(%rbx)
incq %r13
addq $0x1c, %rbx
jmp 0x27e5
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq