// File: /workspace/github_c_makefile_star2_O3/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, 0x6a16(%rip)      # 0x91c3
jne 0x27dd
movq 0x6a22(%rip), %rdi      # 0x91d8
movl 0x69ec(%rip), %ecx      # 0x91a8
imulq $0x10624dd3, %rcx, %rdx # imm = 0x10624DD3
shrq $0x26, %rdx
imull $0x3e8, %edx, %eax      # imm = 0x3E8
subl %eax, %ecx
leaq 0x35b7(%rip), %rsi      # 0x5d8d
xorl %eax, %eax
callq 0x10b0
movslq 0x8a04(%rip), %rax      # 0xb1e8
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
leaq 0x8a0a(%rip), %r14      # 0xb200
movl 0x4(%r14,%rcx), %ebp
xorl %edi, %edi
cmpl 0x69a5(%rip), %ebp      # 0x91a8
setae %dil
leaq 0x35a8(%rip), %rsi      # 0x5db6
callq 0x1af6
movl 0x698f(%rip), %ecx      # 0x91a8
movl %ebp, %r8d
subl %ecx, %r8d
movl 0x6987(%rip), %eax      # 0x91ac
addl %r8d, %eax
imulq $0x10624dd3, %rax, %rbx # imm = 0x10624DD3
shrq $0x26, %rbx
imull $0x3e8, %ebx, %edx      # imm = 0x3E8
movl %eax, %r9d
subl %edx, %r9d
movl %r9d, 0x6966(%rip)      # 0x91ac
cmpq %rax, 0x6923(%rip)      # 0x9170
jae 0x288f
cmpl $0x3e8, %eax            # imm = 0x3E8
jae 0x289f
cmpb $0x1, 0x6966(%rip)      # 0x91c3
jne 0x290a
movq 0x696e(%rip), %rdi      # 0x91d8
movl %ecx, %eax
imulq $0x10624dd3, %rax, %rdx # imm = 0x10624DD3
shrq $0x26, %rdx
imull $0x3e8, %edx, %eax      # imm = 0x3E8
subl %eax, %ecx
leaq 0x35b3(%rip), %rsi      # 0x5e39
xorl %eax, %eax
callq 0x10b0
jmp 0x290a
cmpl $0x3e8, %eax            # imm = 0x3E8
jb 0x2910
incq 0x691b(%rip)            # 0x91b8
jmp 0x2910
movq %rbx, %rdi
callq 0x2676
cmpb $0x1, 0x6915(%rip)      # 0x91c3
jne 0x290a
movq 0x6921(%rip), %rdi      # 0x91d8
movl 0x68eb(%rip), %ecx      # 0x91a8
imulq $0x10624dd3, %rcx, %rdx # imm = 0x10624DD3
shrq $0x26, %rdx
imull $0x3e8, %edx, %eax      # imm = 0x3E8
subl %eax, %ecx
movl %ebp, %eax
imulq $0x10624dd3, %rax, %r9  # imm = 0x10624DD3
shrq $0x26, %r9
imull $0x3e8, %r9d, %eax      # imm = 0x3E8
movl %ebp, %r10d
subl %eax, %r10d
movl 0x68bb(%rip), %r11d     # 0x91ac
leaq 0x34ed(%rip), %rsi      # 0x5de5
movq %rbx, %r8
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x10b0
addq $0x10, %rsp
movl %ebp, 0x6898(%rip)      # 0x91a8
movl 0x88d2(%rip), %edi      # 0xb1e8
xorl %ebx, %ebx
callq 0x2165
movl 0x88c5(%rip), %eax      # 0xb1e8
leal 0x1(%rax), %edi
cmpl $0x63, %eax
cmovgel %ebx, %edi
movl %edi, 0x88b6(%rip)      # 0xb1e8
movl 0x88ac(%rip), %eax      # 0xb1e4
leal -0x1(%rax), %ecx
movl %ecx, 0x88a3(%rip)      # 0xb1e4
cmpl $0x2, %eax
jl 0x2963
movslq %edi, %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movl 0x6816(%rip), %eax      # 0x9170
addl %ebp, %eax
cmpl %eax, 0x4(%r14,%rcx)
jbe 0x2918
movl 0x6783(%rip), %eax      # 0x90ec
testl %eax, %eax
jle 0x2a3d
leaq 0x688c(%rip), %rbx      # 0x9204
leaq 0x351a(%rip), %r14      # 0x5e99
leaq 0x87fa(%rip), %r15      # 0xb180
leaq 0x3325(%rip), %r12      # 0x5cb2
xorl %r13d, %r13d
cmpb $0x1, -0x3(%rbx)
jne 0x2a2a
movb $0x0, 0x67bf(%rip)      # 0x9160
cmpb $0x1, 0x6818(%rip)      # 0x91c0
jne 0x29c8
movl %r13d, %edi
orl $0x80, %edi
movq 0x6836(%rip), %rsi      # 0x91f0
callq 0x10a0
incq 0x67c2(%rip)            # 0x9188
jmp 0x29f3
movq 0x6821(%rip), %rdi      # 0x91f0
movq 0x6702(%rip), %rdx      # 0x90d8
movl %r13d, %ecx
orl $0x80, %ecx
movq %r12, %rsi
xorl %eax, %eax
callq 0x10b0
movl $0x1, %edi
callq 0x1d12
cmpb $0x1, 0x67c9(%rip)      # 0x91c3
jne 0x2a1e
movq 0x67d5(%rip), %rbp      # 0x91d8
movq %rbx, %rdi
callq 0x1da6
movq %rbp, %rdi
movq %r14, %rsi
movl %r13d, %edx
movq %r15, %rcx
xorl %eax, %eax
callq 0x10b0
movw $0x0, -0x4(%rbx)
movl 0x66c2(%rip), %eax      # 0x90ec
incq %r13
movslq %eax, %rcx
addq $0x1c, %rbx
cmpq %rcx, %r13
jl 0x2990
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq