// File: /workspace/github_c_makefile_star2_O3/baines[P]MiniGBS/audio.c
// Function: audio_get_vol
void audio_get_vol(uint8_t vol[static 8]){
	for(int i = 0; i < 4; ++i){
		vol[i*2+0] = chans[i].volume * chans[i].on_left;
		vol[i*2+1] = chans[i].volume * chans[i].on_right;
	}

	int ch3_hi = 0, ch3_lo = 0xf;
	for(uint8_t* p = mem + 0xFF30; p < mem + 0xFF40; ++p){
		uint8_t a = *p >> 4, b = *p & 0xF;
		ch3_lo = MIN(ch3_lo, MIN(a, b));
		ch3_hi = MAX(ch3_hi, MAX(a, b));
	}

	float ch3_v = (ch3_hi - ch3_lo) / 15.0f;

	if(vol[4]) vol[4] = 5*(4-vol[4]) * ch3_v;
	if(vol[5]) vol[5] = 5*(4-vol[5]) * ch3_v;
}

// Assembly:
leaq 0x811e(%rip), %rcx      # 0x115b4
xorl %edx, %edx
movb -0x2(%rcx), %al
mulb (%rcx)
movb %al, (%rdi,%rdx,2)
movb -0x1(%rcx), %al
mulb (%rcx)
movb %al, 0x1(%rdi,%rdx,2)
incq %rdx
addq $0x70, %rcx
cmpq $0x4, %rdx
jne 0x9498
leaq 0x7f83(%rip), %rax      # 0x11440
movq (%rax), %rax
movdqa 0x3e18(%rip), %xmm0     # 0xd2e0
pxor %xmm1, %xmm1
xorl %ecx, %ecx
movdqa 0x3e1a(%rip), %xmm3     # 0xd2f0
movdqa 0x3e22(%rip), %xmm4     # 0xd300
pxor %xmm2, %xmm2
movd 0xff30(%rax,%rcx), %xmm5
movdqa %xmm5, %xmm6
psrlw $0x4, %xmm6
pand %xmm3, %xmm6
pand %xmm4, %xmm5
punpcklbw %xmm1, %xmm6    # xmm6 = xmm6[0],xmm1[0],xmm6[1],xmm1[1],xmm6[2],xmm1[2],xmm6[3],xmm1[3],xmm6[4],xmm1[4],xmm6[5],xmm1[5],xmm6[6],xmm1[6],xmm6[7],xmm1[7]
punpcklwd %xmm1, %xmm6    # xmm6 = xmm6[0],xmm1[0],xmm6[1],xmm1[1],xmm6[2],xmm1[2],xmm6[3],xmm1[3]
punpcklbw %xmm1, %xmm5    # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1],xmm5[2],xmm1[2],xmm5[3],xmm1[3],xmm5[4],xmm1[4],xmm5[5],xmm1[5],xmm5[6],xmm1[6],xmm5[7],xmm1[7]
punpcklwd %xmm1, %xmm5    # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1],xmm5[2],xmm1[2],xmm5[3],xmm1[3]
movdqa %xmm5, %xmm7
pcmpgtd %xmm6, %xmm7
movdqa %xmm7, %xmm8
pandn %xmm5, %xmm8
movdqa %xmm7, %xmm9
pandn %xmm6, %xmm9
pand %xmm7, %xmm6
por %xmm8, %xmm6
movdqa %xmm6, %xmm8
pcmpgtd %xmm0, %xmm8
movdqa %xmm0, %xmm10
pand %xmm8, %xmm10
pandn %xmm6, %xmm8
movdqa %xmm8, %xmm0
por %xmm10, %xmm0
pand %xmm5, %xmm7
por %xmm9, %xmm7
movdqa %xmm2, %xmm5
pcmpgtd %xmm7, %xmm2
pand %xmm2, %xmm5
pandn %xmm7, %xmm2
por %xmm5, %xmm2
addq $0x4, %rcx
cmpq $0x10, %rcx
jne 0x94e2
pshufd $0xee, %xmm2, %xmm1     # xmm1 = xmm2[2,3,2,3]
movdqa %xmm2, %xmm3
pcmpgtd %xmm1, %xmm3
pand %xmm3, %xmm2
pandn %xmm1, %xmm3
por %xmm2, %xmm3
pshufd $0x55, %xmm3, %xmm1     # xmm1 = xmm3[1,1,1,1]
movdqa %xmm3, %xmm2
pcmpgtd %xmm1, %xmm2
pand %xmm2, %xmm3
pandn %xmm1, %xmm2
por %xmm3, %xmm2
movd %xmm2, %eax
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
movdqa %xmm1, %xmm2
pcmpgtd %xmm0, %xmm2
pand %xmm2, %xmm0
pandn %xmm1, %xmm2
por %xmm0, %xmm2
pshufd $0x55, %xmm2, %xmm0     # xmm0 = xmm2[1,1,1,1]
movdqa %xmm0, %xmm1
pcmpgtd %xmm2, %xmm1
pand %xmm1, %xmm2
pandn %xmm0, %xmm1
por %xmm2, %xmm1
movd %xmm1, %ecx
subl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x3ca4(%rip), %xmm0     # 0xd2a0
movzbl 0x4(%rdi), %eax
testl %eax, %eax
je 0x9620
movl $0x4, %ecx
subl %eax, %ecx
leal (%rcx,%rcx,4), %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %eax
movb %al, 0x4(%rdi)
movzbl 0x5(%rdi), %eax
testl %eax, %eax
je 0x9644
movl $0x4, %ecx
subl %eax, %ecx
leal (%rcx,%rcx,4), %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movb %al, 0x5(%rdi)
retq