// File: /workspace/github_c_makefile_star2_O3/baines[P]MiniGBS/audio.c
// Function: update_noise
void update_noise(void){
	struct chan* c = chans + 3;
	if(!c->powered) return;

	float freq = 4194304.0f / (float)((size_t[]){ 8, 16, 32, 48, 64, 80, 96, 112 }[c->lfsr_div] << (size_t)c->freq);
	set_note_freq(c, freq);

	if(c->freq >= 14){
		c->enabled = false;
	}

	for(int i = 0; i < nsamples; i+=2){
		update_len(c);

		if(c->enabled){
			update_env(c);

			float pos = 0.0f;
			float prev_pos = 0.0f;
			float sample = 0.0f;

			while(update_freq(c, &pos)){
				c->lfsr_reg = (c->lfsr_reg << 1) | (c->val == 1);

				if(c->lfsr_wide){
					c->val = !(((c->lfsr_reg >> 14) & 1) ^ ((c->lfsr_reg >> 13) & 1)) ? 1 : -1;
				} else {
					c->val = !(((c->lfsr_reg >> 6 ) & 1) ^ ((c->lfsr_reg >> 5 ) & 1)) ? 1 : -1;
				}
				sample += ((pos - prev_pos) / c->freq_inc) * c->val;
				prev_pos = pos;
			}
			sample += ((pos - prev_pos) / c->freq_inc) * c->val;
			sample = hipass(c, sample * (c->volume / 15.0f));

			if(!muted[c-chans]){
				samples[i+0] += sample * 0.25f * c->on_left * vol_l;
				samples[i+1] += sample * 0.25f * c->on_right * vol_r;
			}
		}
	}
}

// Assembly:
cmpb $0x1, 0x8a43(%rip)      # 0x11701
jne 0x8f5c
movslq 0x8a9d(%rip), %rax      # 0x11768
leaq 0x46b6(%rip), %rcx      # 0xd388
movq (%rcx,%rax,8), %rax
movb 0x8a30(%rip), %cl       # 0x1170c
shlq %cl, %rax
testq %rax, %rax
js 0x8ceb
cvtsi2ss %rax, %xmm1
jmp 0x8d00
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movss 0x4584(%rip), %xmm0     # 0xd298
divss %xmm1, %xmm0
movaps %xmm0, %xmm1
divss 0x4569(%rip), %xmm1     # 0xd28c
movss %xmm1, 0x89e9(%rip)     # 0x11714
divss 0x455d(%rip), %xmm0     # 0xd290
callq 0x51f0
divss 0x8864(%rip), %xmm0     # 0x115a4
callq 0x50d0
cvttss2si %xmm0, %eax
cmpl $-0x2f, %eax
movl $0xffffffd0, %ecx       # imm = 0xFFFFFFD0
cmovgel %eax, %ecx
addl $0x30, %ecx
movl %ecx, 0x89bf(%rip)      # 0x1171c
cmpw $0xe, 0x89a7(%rip)      # 0x1170c
jb 0x8d6e
movb $0x0, 0x8992(%rip)      # 0x11700
movq 0x89fb(%rip), %r14      # 0x11770
testq %r14, %r14
je 0x8f50
movss 0x881a(%rip), %xmm0     # 0x115a0
movss %xmm0, 0xc(%rsp)
movb 0x8818(%rip), %bpl      # 0x115ab
movq 0x89e6(%rip), %r15      # 0x11780
movss 0x89e6(%rip), %xmm0     # 0x11788
movss 0x89ce(%rip), %xmm1     # 0x11778
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movaps %xmm1, 0x10(%rsp)
xorl %r12d, %r12d
leaq 0x8944(%rip), %rbx      # 0x11700
movq %rbx, %rdi
callq 0x8587
cmpb $0x1, 0x8935(%rip)      # 0x11700
jne 0x8f43
movq %rbx, %rdi
callq 0x851d
movss 0x8933(%rip), %xmm0     # 0x11714
movss 0x8927(%rip), %xmm2     # 0x11710
addss %xmm0, %xmm2
movss 0x3267(%rip), %xmm5     # 0xc05c
ucomiss %xmm5, %xmm2
movl 0x891a(%rip), %eax      # 0x11718
jbe 0x8ea4
movzwl 0x8959(%rip), %esi      # 0x11764
movzbl 0x8954(%rip), %edx      # 0x11766
cmpl $0x1, %eax
sete %cl
leal 0x6(,%rdx,8), %eax
leal 0x5(,%rdx,8), %edx
xorps %xmm1, %xmm1
xorps %xmm3, %xmm3
movss 0x4460(%rip), %xmm6     # 0xd294
xorps %xmm7, %xmm7
movaps %xmm3, %xmm4
addss %xmm6, %xmm2
movzbl %cl, %ecx
andl $0x1, %ecx
leal (%rcx,%rsi,2), %esi
movzwl %si, %edi
movl %edi, %r8d
movl %eax, %ecx
shrl %cl, %r8d
movl %edx, %ecx
shrl %cl, %edi
movaps %xmm0, %xmm3
subss %xmm2, %xmm3
xorl %r8d, %edi
andl $0x1, %edi
sete %cl
negl %edi
orl $0x1, %edi
movaps %xmm3, %xmm2
subss %xmm4, %xmm2
xorps %xmm4, %xmm4
cvtsi2ss %edi, %xmm4
divss %xmm0, %xmm2
mulss %xmm4, %xmm2
addss %xmm2, %xmm1
movaps %xmm0, %xmm2
subss %xmm3, %xmm2
ucomiss %xmm5, %xmm2
addss %xmm7, %xmm2
ja 0x8e37
movw %si, 0x88c8(%rip)       # 0x11764
movl %edi, 0x8876(%rip)      # 0x11718
jmp 0x8eb1
xorps %xmm4, %xmm4
cvtsi2ss %eax, %xmm4
xorps %xmm3, %xmm3
xorps %xmm1, %xmm1
movss %xmm2, 0x8857(%rip)     # 0x11710
movaps %xmm0, %xmm2
subss %xmm3, %xmm2
divss %xmm0, %xmm2
xorps %xmm3, %xmm3
cvtsi2ssl 0x8835(%rip), %xmm3 # 0x11704
mulss %xmm4, %xmm2
addss %xmm1, %xmm2
divss 0x43c1(%rip), %xmm3     # 0xd2a0
mulss %xmm2, %xmm3
movaps %xmm3, %xmm0
subss 0x886a(%rip), %xmm0     # 0x11758
movaps %xmm0, %xmm1
mulss 0xc(%rsp), %xmm1
subss %xmm1, %xmm3
movss %xmm3, 0x8855(%rip)     # 0x11758
testb $0x1, %bpl
jne 0x8f43
mulss 0x4393(%rip), %xmm0     # 0xd2a4
movzwl 0x87ea(%rip), %eax      # 0x11702
movd %eax, %xmm1
xorps %xmm2, %xmm2
punpcklbw %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3],xmm1[4],xmm2[4],xmm1[5],xmm2[5],xmm1[6],xmm2[6],xmm1[7],xmm2[7]
punpcklwd %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3]
cvtdq2ps %xmm1, %xmm1
unpcklps %xmm0, %xmm0            # xmm0 = xmm0[0,0,1,1]
mulps %xmm1, %xmm0
mulps 0x10(%rsp), %xmm0
movsd (%r15,%r12,4), %xmm1
addps %xmm0, %xmm1
movlps %xmm1, (%r15,%r12,4)
addq $0x2, %r12
cmpq %r12, %r14
ja 0x8dbc
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq