// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
testb $0x1, 0x82b8(%rip)      # 0xb303
je 0x308a
movq 0x82c4(%rip), %rdi      # 0xb318
movl 0x828e(%rip), %eax      # 0xb2e8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, 0x2c(%rsp)
movl 0x827b(%rip), %eax      # 0xb2e8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %edx, %ecx
movl 0x2c(%rsp), %edx
leaq 0x4ebe(%rip), %rsi      # 0x7f41
movb $0x0, %al
callq 0x10a0
movslq 0xa297(%rip), %rcx      # 0xd328
leaq 0xa2a8(%rip), %rax      # 0xd340
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x8238(%rip), %eax      # 0xb2e8
setae %al
movzbl %al, %edi
andl $0x1, %edi
leaq 0x4eaa(%rip), %rsi      # 0x7f6a
callq 0x1c70
movl 0x54(%rsp), %eax
subl 0x8219(%rip), %eax      # 0xb2e8
addl 0x8217(%rip), %eax      # 0xb2ec
movl %eax, %eax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movl %edx, %eax
movl %eax, 0x81e5(%rip)      # 0xb2ec
movq 0x48(%rsp), %rax
cmpq 0x819d(%rip), %rax      # 0xb2b0
jbe 0x3211
cmpq $0x0, 0x40(%rsp)
jbe 0x31aa
movq 0x40(%rsp), %rdi
callq 0x2ed0
testb $0x1, 0x81cd(%rip)      # 0xb303
je 0x31a8
movq 0x81d9(%rip), %rdi      # 0xb318
movl 0x81a3(%rip), %eax      # 0xb2e8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, 0x28(%rsp)
movl 0x8190(%rip), %eax      # 0xb2e8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %edx, %ecx
movq 0x40(%rsp), %r8
movl 0x54(%rsp), %eax
movl $0x3e8, %esi            # imm = 0x3E8
xorl %edx, %edx
divl %esi
movl %eax, %r9d
movl 0x54(%rsp), %eax
movl $0x3e8, %esi            # imm = 0x3E8
xorl %edx, %edx
divl %esi
movl %edx, %r10d
movl 0x28(%rsp), %edx
movl 0x815a(%rip), %eax      # 0xb2ec
leaq 0x4e00(%rip), %rsi      # 0x7f99
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x10a0
jmp 0x3205
testb $0x1, 0x8152(%rip)      # 0xb303
je 0x3203
movq 0x815e(%rip), %rdi      # 0xb318
movl 0x8128(%rip), %eax      # 0xb2e8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, 0x24(%rsp)
movl 0x8115(%rip), %eax      # 0xb2e8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %edx, %ecx
movl 0x24(%rsp), %edx
movl 0x54(%rsp), %r8d
subl 0x80fa(%rip), %r8d      # 0xb2e8
movl 0x80f7(%rip), %r9d      # 0xb2ec
leaq 0x4df1(%rip), %rsi      # 0x7fed
movb $0x0, %al
callq 0x10a0
jmp 0x3205
movl 0x54(%rsp), %eax
movl %eax, 0x80d9(%rip)      # 0xb2e8
jmp 0x322d
cmpq $0x0, 0x40(%rsp)
jbe 0x322b
movq 0x80d8(%rip), %rax      # 0xb2f8
addq $0x1, %rax
movq %rax, 0x80cd(%rip)      # 0xb2f8
jmp 0x322d
jmp 0x322f
movl 0xa0f3(%rip), %edi      # 0xd328
callq 0x2830
movl 0xa0e8(%rip), %eax      # 0xd328
addl $0x1, %eax
movl %eax, 0xa0df(%rip)      # 0xd328
cmpl $0x64, %eax
jl 0x3258
movl $0x0, 0xa0d0(%rip)      # 0xd328
movl 0xa0c6(%rip), %eax      # 0xd324
addl $-0x1, %eax
movl %eax, 0xa0bd(%rip)      # 0xd324
xorl %eax, %eax
cmpl $0x0, 0xa0b4(%rip)      # 0xd324
movb %al, 0x23(%rsp)
jle 0x32a4
movslq 0xa0ab(%rip), %rcx      # 0xd328
leaq 0xa0bc(%rip), %rax      # 0xd340
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl 0x54(%rsp), %ecx
movq 0x8017(%rip), %rdx      # 0xb2b0
addl %edx, %ecx
cmpl %ecx, %eax
setbe %al
movb %al, 0x23(%rsp)
movb 0x23(%rsp), %al
testb $0x1, %al
jne 0x322f
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x7e1e(%rip), %eax      # 0xb0dc
jge 0x33bd
movslq 0x3c(%rsp), %rcx
leaq 0x8070(%rip), %rax      # 0xb340
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
testb $0x1, 0x1(%rax)
je 0x33ab
movb $0x0, 0x7fae(%rip)      # 0xb2a0
testb $0x1, 0x8007(%rip)      # 0xb300
je 0x3325
movl 0x3c(%rsp), %edi
orl $0x80, %edi
movq 0x8024(%rip), %rsi      # 0xb330
callq 0x1090
movq 0x7fb0(%rip), %rax      # 0xb2c8
addq $0x1, %rax
movq %rax, 0x7fa5(%rip)      # 0xb2c8
jmp 0x3355
movq 0x8004(%rip), %rdi      # 0xb330
movq 0x7d95(%rip), %rdx      # 0xb0c8
movl 0x3c(%rsp), %ecx
orl $0x80, %ecx
leaq 0x4b22(%rip), %rsi      # 0x7e66
movb $0x0, %al
callq 0x10a0
movl $0x1, %edi
callq 0x21c0
testb $0x1, 0x7fa7(%rip)      # 0xb303
je 0x339a
movq 0x7fb3(%rip), %rax      # 0xb318
movq %rax, 0x10(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x30(%rsp), %rdi
addq $0x4, %rdi
callq 0x2260
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %edx
movq %rax, %rcx
leaq 0x4cba(%rip), %rsi      # 0x804d
movb $0x0, %al
callq 0x10a0
movq 0x30(%rsp), %rax
movb $0x0, 0x1(%rax)
movq 0x30(%rsp), %rax
movb $0x0, (%rax)
jmp 0x33ad
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x32b4
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)