// File: /workspace/github_c_makefile_star2_O1/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, 0x6947(%rip)      # 0x91c3
jne 0x28ac
movq 0x6953(%rip), %rdi      # 0x91d8
movl 0x691d(%rip), %ecx      # 0x91a8
imulq $0x10624dd3, %rcx, %rdx # imm = 0x10624DD3
shrq $0x26, %rdx
imull $0x3e8, %edx, %eax      # imm = 0x3E8
subl %eax, %ecx
leaq 0x34e8(%rip), %rsi      # 0x5d8d
xorl %eax, %eax
callq 0x10b0
movslq 0x8935(%rip), %rax      # 0xb1e8
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
leaq 0x893b(%rip), %r14      # 0xb200
movl 0x4(%r14,%rcx), %ebp
xorl %edi, %edi
cmpl 0x68d6(%rip), %ebp      # 0x91a8
setae %dil
leaq 0x34d9(%rip), %rsi      # 0x5db6
callq 0x1b7b
movl 0x68c0(%rip), %ecx      # 0x91a8
movl %ebp, %r8d
subl %ecx, %r8d
movl 0x68b8(%rip), %esi      # 0x91ac
addl %r8d, %esi
movabsq $0x4189374bc6a7f0, %rdx # imm = 0x4189374BC6A7F0
movq %rsi, %rax
mulq %rdx
imulq $0x10624dd3, %rsi, %rax # imm = 0x10624DD3
shrq $0x26, %rax
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movl %esi, %r9d
subl %eax, %r9d
movl %r9d, 0x6887(%rip)      # 0x91ac
cmpq %rsi, 0x6844(%rip)      # 0x9170
jae 0x296f
cmpl $0x3e8, %esi            # imm = 0x3E8
jae 0x2980
cmpb $0x1, 0x6886(%rip)      # 0x91c3
jne 0x29ee
movq 0x688e(%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 0x34d3(%rip), %rsi      # 0x5e39
xorl %eax, %eax
callq 0x10b0
jmp 0x29ee
cmpl $0x3e8, %esi            # imm = 0x3E8
jb 0x29f4
incq 0x683a(%rip)            # 0x91b8
jmp 0x29f4
movq %rdx, %rbx
movq %rdx, %rdi
callq 0x2745
cmpb $0x1, 0x6831(%rip)      # 0x91c3
jne 0x29ee
movq 0x683d(%rip), %rdi      # 0x91d8
movl 0x6807(%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 0x67d7(%rip), %r11d     # 0x91ac
leaq 0x3409(%rip), %rsi      # 0x5de5
movq %rbx, %r8
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x10b0
addq $0x10, %rsp
movl %ebp, 0x67b4(%rip)      # 0x91a8
xorl %ebx, %ebx
movl 0x87ec(%rip), %edi      # 0xb1e8
callq 0x2234
movl 0x87e1(%rip), %ecx      # 0xb1e8
leal 0x1(%rcx), %eax
cmpl $0x63, %ecx
cmovgel %ebx, %eax
movl %eax, 0x87d2(%rip)      # 0xb1e8
movl 0x87c8(%rip), %ecx      # 0xb1e4
leal -0x1(%rcx), %edx
movl %edx, 0x87bf(%rip)      # 0xb1e4
cmpl $0x2, %ecx
jl 0x2a46
cltq
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movl 0x6733(%rip), %eax      # 0x9170
addl %ebp, %eax
cmpl %eax, 0x4(%r14,%rcx)
jbe 0x29f6
cmpl $0x0, 0x669f(%rip)      # 0x90ec
jle 0x2b1d
leaq 0x67aa(%rip), %rbx      # 0x9204
leaq 0x3438(%rip), %r14      # 0x5e99
leaq 0x8718(%rip), %r15      # 0xb180
leaq 0x3243(%rip), %r12      # 0x5cb2
xorl %r13d, %r13d
cmpb $0x1, -0x3(%rbx)
jne 0x2b06
movb $0x0, 0x66dd(%rip)      # 0x9160
cmpb $0x1, 0x6736(%rip)      # 0x91c0
jne 0x2aaa
movl %r13d, %edi
orl $0x80, %edi
movq 0x6754(%rip), %rsi      # 0x91f0
callq 0x10a0
incq 0x66e0(%rip)            # 0x9188
jmp 0x2ad5
movq 0x673f(%rip), %rdi      # 0x91f0
movq 0x6620(%rip), %rdx      # 0x90d8
movl %r13d, %ecx
orl $0x80, %ecx
movq %r12, %rsi
xorl %eax, %eax
callq 0x10b0
movl $0x1, %edi
callq 0x1da7
cmpb $0x1, 0x66e7(%rip)      # 0x91c3
jne 0x2b00
movq 0x66f3(%rip), %rbp      # 0x91d8
movq %rbx, %rdi
callq 0x1e3b
movq %rbp, %rdi
movq %r14, %rsi
movl %r13d, %edx
movq %r15, %rcx
xorl %eax, %eax
callq 0x10b0
movw $0x0, -0x4(%rbx)
incq %r13
movslq 0x65dc(%rip), %rax      # 0x90ec
addq $0x1c, %rbx
cmpq %rax, %r13
jl 0x2a72
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq