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

	set_note_freq(c, 4194304.0f / (float)((2048 - c->freq) << 5));
	c->freq_inc *= 8.0f;

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

		if(c->enabled){
			update_env(c);
			if(!ch2) update_sweep(c);

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

			while(update_freq(c, &pos)){
				c->duty_counter = (c->duty_counter + 1) & 7;
				sample += ((pos - prev_pos) / c->freq_inc) * (float)c->val;
				c->val = (c->duty & (1 << c->duty_counter)) ? 1 : -1;
				prev_pos = pos;
			}
			sample += ((pos - prev_pos) / c->freq_inc) * (float)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 $0x20, %rsp
movb %dil, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
leaq 0xb6fe(%rip), %rax      # 0x16a80
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
testb $0x1, 0x1(%rax)
jne 0xb39c
jmp 0xb5fb
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movzwl 0xc(%rax), %ecx
movl $0x800, %eax            # imm = 0x800
subl %ecx, %eax
shll $0x5, %eax
cvtsi2ss %eax, %xmm1
movss 0x64ca(%rip), %xmm0     # 0x11888
divss %xmm1, %xmm0
callq 0xae20
movq -0x10(%rbp), %rax
movss 0x64b1(%rip), %xmm0     # 0x11884
mulss 0x14(%rax), %xmm0
movss %xmm0, 0x14(%rax)
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rax
cmpq 0xb851(%rip), %rax      # 0x16c40
jae 0xb5fb
movq -0x10(%rbp), %rdi
callq 0xb0f0
movq -0x10(%rbp), %rax
testb $0x1, (%rax)
je 0xb5eb
movq -0x10(%rbp), %rdi
callq 0xafe0
testb $0x1, -0x1(%rbp)
jne 0xb423
movq -0x10(%rbp), %rdi
callq 0xb220
xorps %xmm0, %xmm0
movss %xmm0, -0x18(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x20(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0xb170
testb $0x1, %al
jne 0xb44e
jmp 0xb4cd
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
addl $0x1, %ecx
andl $0x7, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x60(%rax)
movss -0x18(%rbp), %xmm0
subss -0x1c(%rbp), %xmm0
movq -0x10(%rbp), %rax
divss 0x14(%rax), %xmm0
movq -0x10(%rbp), %rax
cvtsi2ssl 0x18(%rax), %xmm2
movss -0x20(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %edx
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
andl %eax, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0x1, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movss -0x18(%rbp), %xmm0
movss %xmm0, -0x1c(%rbp)
jmp 0xb43b
movss -0x18(%rbp), %xmm0
subss -0x1c(%rbp), %xmm0
movq -0x10(%rbp), %rax
divss 0x14(%rax), %xmm0
movq -0x10(%rbp), %rax
cvtsi2ssl 0x18(%rax), %xmm2
movss -0x20(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movss -0x20(%rbp), %xmm0
movq -0x10(%rbp), %rax
cvtsi2ssl 0x4(%rax), %xmm1
movss 0x6377(%rip), %xmm2     # 0x1188c
divss %xmm2, %xmm1
mulss %xmm1, %xmm0
callq 0xadc0
movss %xmm0, -0x20(%rbp)
movq -0x10(%rbp), %rax
leaq 0xb54e(%rip), %rcx      # 0x16a80
subq %rcx, %rax
movl $0x70, %ecx
cqto
idivq %rcx
movq %rax, %rcx
leaq 0xb52f(%rip), %rax      # 0x16a78
testb $0x1, (%rax,%rcx)
jne 0xb5e9
movss 0x6335(%rip), %xmm0     # 0x11890
mulss -0x20(%rbp), %xmm0
movq -0x10(%rbp), %rax
movb 0x2(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2ss %eax, %xmm1
mulss %xmm1, %xmm0
movss 0xb6cc(%rip), %xmm2     # 0x16c48
movq 0xb6cd(%rip), %rax      # 0x16c50
movl -0x14(%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 0x62ea(%rip), %xmm0     # 0x11890
mulss -0x20(%rbp), %xmm0
movq -0x10(%rbp), %rax
movb 0x3(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2ss %eax, %xmm1
mulss %xmm1, %xmm0
movss 0xb691(%rip), %xmm2     # 0x16c58
movq 0xb682(%rip), %rax      # 0x16c50
movl -0x14(%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 0xb5eb
jmp 0xb5ed
movl -0x14(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x14(%rbp)
jmp 0xb3e4
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)