// File: /workspace/github_c_makefile_star2_O0/baines[P]MiniGBS/audio.c
// Function: audio_update
float audio_update(struct pollfd* fds, int nfds){
	static float* buf = NULL;
	const size_t bufsz = (pcm_period_size*2) * sizeof(float);

	if(!buf){
		buf = malloc(bufsz);
	}

	float* p = buf;
	float* end = buf + (bufsz/sizeof(float));

	if(!audio_output_ready(fds, nfds)) {
		return 0;
	}

	if(paused){
		memset(buf, 0, bufsz);
		goto out;
	}

	while(end - p){
		if(sample_ptr == sample_end){
			cpu_frame();

			memset(samples    , 0, nsamples * sizeof(float));
			memset(samples_tmp, 0, nsamples * sizeof(float));

			update_square(0);
			ui_osc_draw(0, samples, nsamples);

			for(size_t i = 0; i < nsamples; ++i) samples_tmp[i] += samples[i];
			memset(samples, 0, nsamples * sizeof(float));

			update_square(1);
			ui_osc_draw(1, samples, nsamples);

			for(size_t i = 0; i < nsamples; ++i) samples_tmp[i] += samples[i];
			memset(samples, 0, nsamples * sizeof(float));

			update_wave();
			ui_osc_draw(2, samples, nsamples);

			for(size_t i = 0; i < nsamples; ++i) samples_tmp[i] += samples[i];
			memset(samples, 0, nsamples * sizeof(float));

			update_noise();
			ui_osc_draw(3, samples, nsamples);

			for(size_t i = 0; i < nsamples; ++i) samples[i] += samples_tmp[i];

			for(size_t i = 0; i < nsamples; ++i){
				samples[i] *= cfg.volume;
			}

			sample_ptr = samples;
		}

		int n = MIN(end - p, sample_end - sample_ptr);
		memcpy(p, sample_ptr, n * sizeof(float));
		sample_ptr += n;
		p += n;
	}

out:
	audio_output_write(buf, pcm_period_size);

	if(paused) {
		return 0;
	}

	return (pcm_period_size * 1000.0f / FREQ);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movzwl 0xae97(%rip), %eax      # 0x16c80
shll %eax
cltq
shlq $0x2, %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, 0xae7b(%rip)      # 0x16c78
jne 0xbe0f
movq -0x20(%rbp), %rdi
callq 0x51b0
movq %rax, 0xae69(%rip)      # 0x16c78
movq 0xae62(%rip), %rax      # 0x16c78
movq %rax, -0x28(%rbp)
movq 0xae57(%rip), %rax      # 0x16c78
movq -0x20(%rbp), %rcx
shrq $0x2, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xd000
testb $0x1, %al
jne 0xbe51
xorps %xmm0, %xmm0
movss %xmm0, -0x4(%rbp)
jmp 0xc200
testb $0x1, 0xae18(%rip)      # 0x16c70
je 0xbe71
movq 0xae17(%rip), %rdi      # 0x16c78
movq -0x20(%rbp), %rdx
xorl %esi, %esi
callq 0x5080
jmp 0xc1b2
jmp 0xbe73
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
sarq $0x2, %rax
cmpq $0x0, %rax
je 0xc1b0
movq 0xadcd(%rip), %rax      # 0x16c60
cmpq 0xadce(%rip), %rax      # 0x16c68
jne 0xc10c
callq 0x5700
movq 0xada4(%rip), %rdi      # 0x16c50
movq 0xad8d(%rip), %rdx      # 0x16c40
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x5080
movq 0xadc3(%rip), %rdi      # 0x16c88
movq 0xad74(%rip), %rdx      # 0x16c40
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x5080
xorl %edi, %edi
callq 0xb360
movq 0xad6b(%rip), %rsi      # 0x16c50
movq 0xad54(%rip), %rdx      # 0x16c40
xorl %edi, %edi
callq 0xda10
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq 0xad3a(%rip), %rax      # 0x16c40
jae 0xbf3b
movq 0xad41(%rip), %rax      # 0x16c50
movq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq 0xad69(%rip), %rax      # 0x16c88
movq -0x38(%rbp), %rcx
addss (%rax,%rcx,4), %xmm0
movss %xmm0, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xbefb
movq 0xad0e(%rip), %rdi      # 0x16c50
movq 0xacf7(%rip), %rdx      # 0x16c40
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x5080
movl $0x1, %edi
callq 0xb360
movq 0xaceb(%rip), %rsi      # 0x16c50
movq 0xacd4(%rip), %rdx      # 0x16c40
movl $0x1, %edi
callq 0xda10
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq 0xacb7(%rip), %rax      # 0x16c40
jae 0xbfbe
movq 0xacbe(%rip), %rax      # 0x16c50
movq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq 0xace6(%rip), %rax      # 0x16c88
movq -0x40(%rbp), %rcx
addss (%rax,%rcx,4), %xmm0
movss %xmm0, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xbf7e
movq 0xac8b(%rip), %rdi      # 0x16c50
movq 0xac74(%rip), %rdx      # 0x16c40
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x5080
callq 0xb610
movq 0xac6d(%rip), %rsi      # 0x16c50
movq 0xac56(%rip), %rdx      # 0x16c40
movl $0x2, %edi
callq 0xda10
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq 0xac39(%rip), %rax      # 0x16c40
jae 0xc03c
movq 0xac40(%rip), %rax      # 0x16c50
movq -0x48(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq 0xac68(%rip), %rax      # 0x16c88
movq -0x48(%rbp), %rcx
addss (%rax,%rcx,4), %xmm0
movss %xmm0, (%rax,%rcx,4)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xbffc
movq 0xac0d(%rip), %rdi      # 0x16c50
movq 0xabf6(%rip), %rdx      # 0x16c40
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x5080
callq 0xb970
movq 0xabef(%rip), %rsi      # 0x16c50
movq 0xabd8(%rip), %rdx      # 0x16c40
movl $0x3, %edi
callq 0xda10
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq 0xabbb(%rip), %rax      # 0x16c40
jae 0xc0ba
movq 0xabfa(%rip), %rax      # 0x16c88
movq -0x50(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq 0xabb2(%rip), %rax      # 0x16c50
movq -0x50(%rbp), %rcx
addss (%rax,%rcx,4), %xmm0
movss %xmm0, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xc07a
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq 0xab73(%rip), %rax      # 0x16c40
jae 0xc0fe
leaq 0xa842(%rip), %rax      # 0x16918
movss 0x1c(%rax), %xmm0
movq 0xab6e(%rip), %rax      # 0x16c50
movq -0x58(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
movss %xmm0, (%rax,%rcx,4)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0xc0c2
movq 0xab4b(%rip), %rax      # 0x16c50
movq %rax, 0xab54(%rip)      # 0x16c60
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
sarq $0x2, %rax
movq %rax, -0x68(%rbp)
movq 0xab42(%rip), %rax      # 0x16c68
movq 0xab33(%rip), %rcx      # 0x16c60
subq %rcx, %rax
sarq $0x2, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x70(%rbp), %rax
jg 0xc14c
movq -0x68(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0xc154
movq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movl %eax, -0x5c(%rbp)
movq -0x28(%rbp), %rdi
movq 0xaaf2(%rip), %rsi      # 0x16c60
movslq -0x5c(%rbp), %rdx
shlq $0x2, %rdx
callq 0x55c0
movl -0x5c(%rbp), %ecx
movq 0xaadb(%rip), %rax      # 0x16c60
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0xaaca(%rip)      # 0x16c60
movl -0x5c(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0xbe73
jmp 0xc1b2
movq 0xaabf(%rip), %rdi      # 0x16c78
movzwl 0xaac0(%rip), %esi      # 0x16c80
callq 0xd040
testb $0x1, 0xaaa4(%rip)      # 0x16c70
je 0xc1d8
xorps %xmm0, %xmm0
movss %xmm0, -0x4(%rbp)
jmp 0xc200
movzwl 0xaaa1(%rip), %eax      # 0x16c80
cvtsi2ss %eax, %xmm0
movss 0x3e21(%rip), %xmm1     # 0x1000c
mulss %xmm1, %xmm0
movss 0x5689(%rip), %xmm1     # 0x11880
divss %xmm1, %xmm0
movss %xmm0, -0x4(%rbp)
movss -0x4(%rbp), %xmm0
addq $0x80, %rsp
popq %rbp
retq
nop