// File: /workspace/github_c_makefile_star2_O1/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, 0x8922(%rip)      # 0x11701
jne 0x90cb
movslq 0x897c(%rip), %rax      # 0x11768
leaq 0x4505(%rip), %rcx      # 0xd2f8
movq (%rcx,%rax,8), %rax
movb 0x890f(%rip), %cl       # 0x1170c
shlq %cl, %rax
testq %rax, %rax
js 0x8e0c
cvtsi2ss %rax, %xmm1
jmp 0x8e21
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 $0x10, %rsp
movss 0x4433(%rip), %xmm0     # 0xd268
divss %xmm1, %xmm0
movaps %xmm0, %xmm1
divss 0x4418(%rip), %xmm1     # 0xd25c
movss %xmm1, 0x88c8(%rip)     # 0x11714
divss 0x440c(%rip), %xmm0     # 0xd260
callq 0x51f0
divss 0x8743(%rip), %xmm0     # 0x115a4
callq 0x50d0
cvttss2si %xmm0, %eax
cmpl $-0x2f, %eax
movl $0xffffffd0, %ecx       # imm = 0xFFFFFFD0
cmovgel %eax, %ecx
addl $0x30, %ecx
movl %ecx, 0x889e(%rip)      # 0x1171c
cmpw $0xe, 0x8886(%rip)      # 0x1170c
jb 0x8e8f
movb $0x0, 0x8871(%rip)      # 0x11700
movq 0x88da(%rip), %r14      # 0x11770
testq %r14, %r14
je 0x90bf
movss 0x86f9(%rip), %xmm0     # 0x115a0
movss %xmm0, 0xc(%rsp)
movb 0x86f7(%rip), %bpl      # 0x115ab
movss 0x88bc(%rip), %xmm0     # 0x11778
movss %xmm0, 0x8(%rsp)
movq 0x88b7(%rip), %r15      # 0x11780
movss 0x88b7(%rip), %xmm0     # 0x11788
movss %xmm0, 0x4(%rsp)
xorl %r12d, %r12d
leaq 0x881f(%rip), %rbx      # 0x11700
movq %rbx, %rdi
callq 0x863a
cmpb $0x1, 0x8810(%rip)      # 0x11700
jne 0x90b2
movq %rbx, %rdi
callq 0x85cd
movss 0x880e(%rip), %xmm0     # 0x11714
movss 0x8802(%rip), %xmm1     # 0x11710
addss %xmm0, %xmm1
movss 0x30f1(%rip), %xmm8     # 0xc00c
ucomiss %xmm8, %xmm1
movaps %xmm1, %xmm3
movss 0x4339(%rip), %xmm9     # 0xd264
addss %xmm9, %xmm3
movaps %xmm0, %xmm2
jbe 0x8f39
subss %xmm3, %xmm2
movaps %xmm8, %xmm3
cmpltss %xmm1, %xmm3
andnps %xmm1, %xmm3
xorps %xmm4, %xmm4
jbe 0x8ffd
movzwl 0x880f(%rip), %esi      # 0x11764
movzbl 0x880a(%rip), %edx      # 0x11766
cmpl $0x1, 0x87b5(%rip)      # 0x11718
sete %cl
leal 0x6(,%rdx,8), %eax
leal 0x5(,%rdx,8), %edx
xorps %xmm1, %xmm1
xorps %xmm5, %xmm5
movaps %xmm2, %xmm4
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
xorl %r8d, %edi
andl $0x1, %edi
sete %cl
negl %edi
orl $0x1, %edi
movaps %xmm0, %xmm6
subss %xmm2, %xmm6
addss %xmm3, %xmm6
ucomiss %xmm8, %xmm6
movaps %xmm6, %xmm3
addss %xmm9, %xmm3
movaps %xmm0, %xmm2
jbe 0x8fc3
subss %xmm3, %xmm2
movaps %xmm4, %xmm3
xorps %xmm7, %xmm7
cvtsi2ss %edi, %xmm7
subss %xmm5, %xmm3
divss %xmm0, %xmm3
mulss %xmm3, %xmm7
addss %xmm7, %xmm1
movaps %xmm8, %xmm3
cmpltss %xmm6, %xmm3
andnps %xmm6, %xmm3
movaps %xmm4, %xmm5
ja 0x8f7a
movw %si, 0x876f(%rip)       # 0x11764
movl %edi, 0x871d(%rip)      # 0x11718
jmp 0x9000
xorps %xmm1, %xmm1
subss %xmm4, %xmm2
movss %xmm3, 0x8704(%rip)     # 0x11710
xorps %xmm3, %xmm3
cvtsi2ssl 0x8701(%rip), %xmm3 # 0x11718
divss %xmm0, %xmm2
xorps %xmm4, %xmm4
cvtsi2ssl 0x86de(%rip), %xmm4 # 0x11704
mulss %xmm2, %xmm3
addss %xmm1, %xmm3
divss 0x423a(%rip), %xmm4     # 0xd270
mulss %xmm3, %xmm4
movaps %xmm4, %xmm0
subss 0x8713(%rip), %xmm0     # 0x11758
movaps %xmm0, %xmm1
mulss 0xc(%rsp), %xmm1
subss %xmm1, %xmm4
movss %xmm4, 0x86fe(%rip)     # 0x11758
testb $0x1, %bpl
jne 0x90b2
movsbl 0x869b(%rip), %eax      # 0x11702
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss 0x41fe(%rip), %xmm0     # 0xd274
mulss %xmm0, %xmm1
mulss 0x8(%rsp), %xmm1
addss (%r15,%r12,4), %xmm1
movss %xmm1, (%r15,%r12,4)
movsbl 0x8670(%rip), %eax      # 0x11703
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss %xmm0, %xmm1
mulss 0x4(%rsp), %xmm1
addss 0x4(%r15,%r12,4), %xmm1
movss %xmm1, 0x4(%r15,%r12,4)
addq $0x2, %r12
cmpq %r12, %r14
ja 0x8ee1
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq