// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
leaq 0xb101(%rip), %rax      # 0x16a80
addq $0x150, %rax            # imm = 0x150
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
testb $0x1, 0x1(%rax)
jne 0xb998
jmp 0xbcc4
movups 0x5fc9(%rip), %xmm0     # 0x11968
movaps %xmm0, -0x20(%rbp)
movups 0x5fae(%rip), %xmm0     # 0x11958
movaps %xmm0, -0x30(%rbp)
movups 0x5f93(%rip), %xmm0     # 0x11948
movaps %xmm0, -0x40(%rbp)
movups 0x5f78(%rip), %xmm0     # 0x11938
movaps %xmm0, -0x50(%rbp)
movq -0x8(%rbp), %rcx
movslq 0x68(%rcx), %rax
movq -0x50(%rbp,%rax,8), %rax
movb 0xc(%rcx), %cl
shlq %cl, %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x68(%rbp)
testq %rax, %rax
movss %xmm0, -0x64(%rbp)
js 0xba0c
movss -0x68(%rbp), %xmm0
movss %xmm0, -0x64(%rbp)
movss -0x64(%rbp), %xmm1
movss 0x5e6f(%rip), %xmm0     # 0x11888
divss %xmm1, %xmm0
movss %xmm0, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movss -0xc(%rbp), %xmm0
callq 0xae20
movq -0x8(%rbp), %rax
movzwl 0xc(%rax), %eax
cmpl $0xe, %eax
jl 0xba44
movq -0x8(%rbp), %rax
movb $0x0, (%rax)
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
cmpq 0xb1ea(%rip), %rax      # 0x16c40
jae 0xbcc4
movq -0x8(%rbp), %rdi
callq 0xb0f0
movq -0x8(%rbp), %rax
testb $0x1, (%rax)
je 0xbcb4
movq -0x8(%rbp), %rdi
callq 0xafe0
xorps %xmm0, %xmm0
movss %xmm0, -0x58(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x5c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x60(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xb170
testb $0x1, %al
jne 0xbaa9
jmp 0xbb96
movq -0x8(%rbp), %rax
movzwl 0x64(%rax), %eax
shll %eax
movq -0x8(%rbp), %rcx
cmpl $0x1, 0x18(%rcx)
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x64(%rax)
movq -0x8(%rbp), %rax
testb $0x1, 0x66(%rax)
je 0xbb1b
movq -0x8(%rbp), %rax
movzwl 0x64(%rax), %eax
sarl $0xe, %eax
andl $0x1, %eax
movq -0x8(%rbp), %rcx
movzwl 0x64(%rcx), %ecx
sarl $0xd, %ecx
andl $0x1, %ecx
xorl %ecx, %eax
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0x1, %eax
testb $0x1, %dl
cmovnel %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x18(%rax)
jmp 0xbb59
movq -0x8(%rbp), %rax
movzwl 0x64(%rax), %eax
sarl $0x6, %eax
andl $0x1, %eax
movq -0x8(%rbp), %rcx
movzwl 0x64(%rcx), %ecx
sarl $0x5, %ecx
andl $0x1, %ecx
xorl %ecx, %eax
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0x1, %eax
testb $0x1, %dl
cmovnel %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x18(%rax)
movss -0x58(%rbp), %xmm0
subss -0x5c(%rbp), %xmm0
movq -0x8(%rbp), %rax
divss 0x14(%rax), %xmm0
movq -0x8(%rbp), %rax
cvtsi2ssl 0x18(%rax), %xmm2
movss -0x60(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x58(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
jmp 0xba93
movss -0x58(%rbp), %xmm0
subss -0x5c(%rbp), %xmm0
movq -0x8(%rbp), %rax
divss 0x14(%rax), %xmm0
movq -0x8(%rbp), %rax
cvtsi2ssl 0x18(%rax), %xmm2
movss -0x60(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movss -0x60(%rbp), %xmm0
movq -0x8(%rbp), %rax
cvtsi2ssl 0x4(%rax), %xmm1
movss 0x5cae(%rip), %xmm2     # 0x1188c
divss %xmm2, %xmm1
mulss %xmm1, %xmm0
callq 0xadc0
movss %xmm0, -0x60(%rbp)
movq -0x8(%rbp), %rax
leaq 0xae85(%rip), %rcx      # 0x16a80
subq %rcx, %rax
movl $0x70, %ecx
cqto
idivq %rcx
movq %rax, %rcx
leaq 0xae66(%rip), %rax      # 0x16a78
testb $0x1, (%rax,%rcx)
jne 0xbcb2
movss 0x5c6c(%rip), %xmm0     # 0x11890
mulss -0x60(%rbp), %xmm0
movq -0x8(%rbp), %rax
movb 0x2(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2ss %eax, %xmm1
mulss %xmm1, %xmm0
movss 0xb003(%rip), %xmm2     # 0x16c48
movq 0xb004(%rip), %rax      # 0x16c50
movl -0x54(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movss 0x5c21(%rip), %xmm0     # 0x11890
mulss -0x60(%rbp), %xmm0
movq -0x8(%rbp), %rax
movb 0x3(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2ss %eax, %xmm1
mulss %xmm1, %xmm0
movss 0xafc8(%rip), %xmm2     # 0x16c58
movq 0xafb9(%rip), %rax      # 0x16c50
movl -0x54(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
jmp 0xbcb4
jmp 0xbcb6
movl -0x54(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x54(%rbp)
jmp 0xba4b
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)