// File: /workspace/github_c_makefile_star2_O2/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, 0x9daf(%rip)      # 0x12701
jne 0x8b8a
movslq 0x9e09(%rip), %rax      # 0x12768
leaq 0x49f2(%rip), %rcx      # 0xd358
movq (%rcx,%rax,8), %rax
movb 0x9d9c(%rip), %cl       # 0x1270c
shlq %cl, %rax
testq %rax, %rax
js 0x897f
cvtsi2ss %rax, %xmm1
jmp 0x8994
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movss 0x48ee(%rip), %xmm0     # 0xd298
divss %xmm1, %xmm0
leaq 0x9d4b(%rip), %rdi      # 0x12700
callq 0x8275
cmpw $0xe, 0x9d4a(%rip)      # 0x1270c
jb 0x89cb
movb $0x0, 0x9d35(%rip)      # 0x12700
movq 0x9d9e(%rip), %r15      # 0x12770
movss 0x9bc6(%rip), %xmm0     # 0x125a0
movss %xmm0, 0xc(%rsp)
movb 0x9bc4(%rip), %bpl      # 0x125ab
movq 0x9d92(%rip), %r12      # 0x12780
movss 0x9d92(%rip), %xmm0     # 0x12788
movss 0x9d7a(%rip), %xmm1     # 0x12778
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movaps %xmm1, 0x10(%rsp)
xorl %r13d, %r13d
leaq 0x9cf0(%rip), %rbx      # 0x12700
leaq 0x8(%rsp), %r14
cmpq %r13, %r15
jbe 0x8b7c
movq %rbx, %rdi
callq 0x83ad
cmpb $0x1, 0x9cd3(%rip)      # 0x12700
jne 0x8b73
movq %rbx, %rdi
callq 0x8350
andl $0x0, 0x8(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, (%rsp)
movss %xmm0, 0x4(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x83f3
testb %al, %al
je 0x8ada
movl 0x9d01(%rip), %eax      # 0x12764
xorl %ecx, %ecx
cmpl $0x1, 0x9cac(%rip)      # 0x12718
sete %cl
leal (%rcx,%rax,2), %ecx
movw %cx, 0x9ceb(%rip)       # 0x12764
movb 0x9ce7(%rip), %al       # 0x12766
movzwl %cx, %edx
shlb $0x3, %al
leal 0x6(%rax), %ecx
movl %edx, %esi
shrl %cl, %esi
orb $0x5, %al
movl %eax, %ecx
shrl %cl, %edx
xorl %esi, %edx
andl $0x1, %edx
negl %edx
orl $0x1, %edx
movl %edx, 0x9c76(%rip)      # 0x12718
movss 0x8(%rsp), %xmm0
movaps %xmm0, %xmm1
subss (%rsp), %xmm1
divss 0x9c5c(%rip), %xmm1     # 0x12714
cvtsi2ss %edx, %xmm2
mulss %xmm1, %xmm2
movss 0x4(%rsp), %xmm1
addss %xmm2, %xmm1
movss %xmm1, 0x4(%rsp)
movss %xmm0, (%rsp)
jmp 0x8a4e
movss 0x8(%rsp), %xmm0
subss (%rsp), %xmm0
divss 0x9c27(%rip), %xmm0     # 0x12714
cvtsi2ssl 0x9c23(%rip), %xmm1 # 0x12718
cvtsi2ssl 0x9c07(%rip), %xmm2 # 0x12704
mulss %xmm0, %xmm1
addss 0x4(%rsp), %xmm1
divss 0x4791(%rip), %xmm2     # 0xd2a0
mulss %xmm1, %xmm2
movaps %xmm2, %xmm0
subss 0x9c3a(%rip), %xmm0     # 0x12758
movaps %xmm0, %xmm1
mulss 0xc(%rsp), %xmm1
subss %xmm1, %xmm2
movss %xmm2, 0x9c25(%rip)     # 0x12758
testb $0x1, %bpl
jne 0x8b73
mulss 0x4763(%rip), %xmm0     # 0xd2a4
movzwl 0x9bba(%rip), %eax      # 0x12702
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 (%r12,%r13,4), %xmm1
addps %xmm0, %xmm1
movlps %xmm1, (%r12,%r13,4)
addq $0x2, %r13
jmp 0x8a15
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq