// File: /workspace/github_c_makefile_star2_O1/kieselsteini[P]PiXL-old/pixl.c
// Function: px_audio_mixer_callback
static void px_audio_mixer_callback(void *userdata, Uint8 *stream, int len) {
  Sint8 *out, value;
  AudioChannel *channel;
  float v;
  int i, j, waveform;

  (void)userdata;
  for (i = 0, out = (Sint8*)stream; i < len; ++i) {
    value = 0;
    for (j = 0; j < PX_AUDIO_CHANNELS; ++j) {
      channel = &channels[j];
      if (--channel->duration < 0) mml_parse_next(channel);
      if (channel->duration > channel->silence) waveform = channel->waveform;
      else waveform = PX_WAVEFORM_SILENCE;
      channel->t += 1.0f / mixing_frequency * channel->frequency;
      channel->t -= (int)channel->t;
      switch (waveform) {
      case PX_WAVEFORM_PULSE_12: value += channel->t <= 0.125f ? 4 : -4; break;
      case PX_WAVEFORM_PULSE_25: value += channel->t <= 0.25f ? 4 : -4; break;
      case PX_WAVEFORM_PULSE_50: value += channel->t <= 0.5f ? 4 : -4; break;
      case PX_WAVEFORM_SAWTOOTH: value += (Sint8)((-1.0f + channel->t * 2.0f) * 4.0f); break;
      case PX_WAVEFORM_TRIANLGE:
        if (channel->t < 0.25f) v = channel->t * 4.0f;
        else if (channel->t < 0.75f) v = 1.0f - ((channel->t - 0.25f) * 4.0f);
        else v = -1.0f + ((channel->t) - 0.75f) * 4.0f;
        value += (Sint8)(v * 8.0f);
        break;
      case PX_WAVEFORM_NOISE: value += audio_noise[(int)(channel->t * (float)PX_AUDIO_NOISE)]; break;
      }
    }
    *out++ = value;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, 0x8(%rsp)
testl %edx, %edx
jle 0x2ec1e
xorl %eax, %eax
leaq 0x110bff(%rip), %r12    # 0x13f510
leaq 0x35e8(%rip), %r13      # 0x31f00
leaq 0x36d1(%rip), %rbx      # 0x31ff0
movl %eax, 0xc(%rsp)
movq %rsi, 0x10(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
imulq $0x38, %rbp, %rax
leaq (%r12,%rax), %r15
movl 0x20(%rax,%r12), %ecx
leal -0x1(%rcx), %edx
movl %edx, 0x20(%rax,%r12)
testl %ecx, %ecx
jle 0x2ea9b
movl 0x20(%r15), %ecx
xorl %eax, %eax
cmpl 0x24(%r15), %ecx
jle 0x2e95a
movl 0x1c(%r15), %eax
movss 0x3baa(%rip), %xmm0     # 0x3250c
divss 0x111166(%rip), %xmm0   # 0x13fad0
mulss 0x18(%r15), %xmm0
addss 0x14(%r15), %xmm0
cvttps2dq %xmm0, %xmm1
cvtdq2ps %xmm1, %xmm1
subss %xmm1, %xmm0
movss %xmm0, 0x14(%r15)
decl %eax
cmpl $0x5, %eax
ja 0x2eba6
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
jmpq *%rax
movss 0x3b95(%rip), %xmm1     # 0x32538
jmp 0x2eb2a
movq %r15, %rdi
callq 0x2ecaa
movl %eax, 0x30(%r15)
jmp 0x2ea9b
movq %r15, %rdi
callq 0x2ecaa
movl %eax, 0x2c(%r15)
jmp 0x2ea9b
movq %r15, %rdi
callq 0x2ecaa
movl %eax, 0x28(%r15)
jmp 0x2ea9b
leaq 0x2(%rax), %rcx
movq %rcx, 0x8(%r15)
movzbl 0x1(%rax), %eax
cmpl $0x4d, %eax
jle 0x2ea52
addl $-0x4e, %eax
cmpl $0x26, %eax
ja 0x2ea9b
movabsq $0x100000001, %rcx      # imm = 0x100000001
btq %rax, %rcx
jb 0x2ea75
movabsq $0x2000000020, %rcx     # imm = 0x2000000020
btq %rax, %rcx
jb 0x2ea6b
movabsq $0x4000000040, %rcx     # imm = 0x4000000040
btq %rax, %rcx
jae 0x2ea9b
movl $0x5, 0x1c(%r15)
jmp 0x2ea9b
testl %ecx, %ecx
jne 0x2ea9b
cmpl $0x0, 0x10(%r15)
je 0x2ea7f
movq (%r15), %rax
movq %rax, 0x8(%r15)
jmp 0x2ea9b
decl 0x2c(%r15)
jmp 0x2ea9b
incl 0x2c(%r15)
jmp 0x2ea9b
cmpl $0x31, %eax
je 0x2ea89
cmpl $0x32, %eax
je 0x2ea93
cmpl $0x35, %eax
jne 0x2ea9b
movl $0x3, 0x1c(%r15)
jmp 0x2ea9b
movl $0x4, 0x1c(%r15)
jmp 0x2ea9b
movl $0x6, 0x1c(%r15)
jmp 0x2ea9b
movq %r15, %rdi
callq 0x2e6c3
jmp 0x2ea9b
movl $0x1, 0x1c(%r15)
jmp 0x2ea9b
movl $0x2, 0x1c(%r15)
cmpq $0x0, 0x8(%r15)
je 0x2e94a
movq %r15, %rdi
callq 0x2ec82
movq 0x8(%r15), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r15)
movzbl (%rax), %ecx
leal -0x3c(%rcx), %edx
cmpl $0x3b, %edx
ja 0x2ea32
movslq (%r13,%rdx,4), %rcx
addq %r13, %rcx
jmpq *%rcx
movq %r15, %rdi
callq 0x2ecfa
movl 0x20(%r15), %eax
movl %eax, 0x24(%r15)
jmp 0x2e94a
movss 0x3a24(%rip), %xmm1     # 0x32514
ucomiss %xmm0, %xmm1
jbe 0x2eb58
mulss 0x3a23(%rip), %xmm0     # 0x32520
jmp 0x2eb97
movss 0x3a2a(%rip), %xmm1     # 0x32534
jmp 0x2eb2a
addss %xmm0, %xmm0
addss 0x3a0c(%rip), %xmm0     # 0x32524
mulss 0x3a00(%rip), %xmm0     # 0x32520
jmp 0x2eb9f
movss 0x39ea(%rip), %xmm1     # 0x32514
ucomiss %xmm0, %xmm1
setae %al
shlb $0x3, %al
addb %r14b, %al
addb $-0x4, %al
movl %eax, %r14d
jmp 0x2eba6
mulss 0x39cb(%rip), %xmm0     # 0x32510
cvttss2si %xmm0, %eax
cltq
leaq 0x110b7e(%rip), %rcx    # 0x13f6d0
addb (%rax,%rcx), %r14b
jmp 0x2eba6
movss 0x39b8(%rip), %xmm1     # 0x32518
ucomiss %xmm0, %xmm1
jbe 0x2eb7f
addss 0x39bb(%rip), %xmm0     # 0x32528
mulss 0x39b7(%rip), %xmm0     # 0x3252c
addss 0x398f(%rip), %xmm0     # 0x3250c
jmp 0x2eb97
addss 0x3995(%rip), %xmm0     # 0x3251c
mulss 0x3991(%rip), %xmm0     # 0x32520
addss 0x398d(%rip), %xmm0     # 0x32524
mulss 0x3991(%rip), %xmm0     # 0x32530
cvttss2si %xmm0, %eax
addb %al, %r14b
incq %rbp
cmpq $0x8, %rbp
jne 0x2e92d
jmp 0x2ec03
movq %r15, %rdi
movl $0xb, %esi
jmp 0x2ebf9
movq %r15, %rdi
movl $0x8, %esi
jmp 0x2ebf9
movq %r15, %rdi
movl $0xd, %esi
jmp 0x2ebf9
movq %r15, %rdi
movl $0x6, %esi
jmp 0x2ebf9
movq %r15, %rdi
movl $0x4, %esi
jmp 0x2ebf9
movq %r15, %rdi
movl $0x9, %esi
jmp 0x2ebf9
movq %r15, %rdi
movl $0xf, %esi
callq 0x2edc0
jmp 0x2e94a
movq 0x10(%rsp), %rsi
movb %r14b, (%rsi)
incq %rsi
movl 0xc(%rsp), %eax
incl %eax
cmpl 0x8(%rsp), %eax
jne 0x2e91f
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq