#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, float);
float sin(int);
float sqrt(float);
int main() {
  int i = 0;
  int fs = 44100;
  float s[44100] = {};
  float s_sum = 0;
  float rms = 0;
  for (i = 0; i < fs; i++) {
    s[i] = sin(1 * (2 * 3.141) * i / fs);
    s_sum += s[i] * s[i];
  }
  rms = sqrt(s_sum / fs);
  printf("%f\n", rms);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b130,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0xac44,-0xc(%rbp)
lea    -0x2b120(%rbp),%rdi
xor    %esi,%esi
mov    $0x2b110,%edx
call   1040 <memset@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2b124(%rbp)
ff
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2b128(%rbp)
ff
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120c <main+0xcc>
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xe57(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sin@plt>
movslq -0x8(%rbp),%rax
movss  %xmm0,-0x2b120(%rbp,%rax,4)
fd ff
movslq -0x8(%rbp),%rax
movss  -0x2b120(%rbp,%rax,4),%xmm0
fd ff
movslq -0x8(%rbp),%rax
movss  -0x2b120(%rbp,%rax,4),%xmm2
fd ff
movss  -0x2b124(%rbp),%xmm1
ff
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2b124(%rbp)
ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1190 <main+0x50>
movss  -0x2b124(%rbp),%xmm0
ff
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
call   1060 <sqrt@plt>
movss  %xmm0,-0x2b128(%rbp)
ff
movss  -0x2b128(%rbp),%xmm0
ff
lea    0xdcf(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x2b130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  %xmm0,0x4(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm1
movsd  0xe96(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe92(%rip),%xmm2
divsd  %xmm2,%xmm1
cvttsd2si %xmm1,%edi
call   1040 <sin@plt>
mulss  %xmm0,%xmm0
addss  0x4(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0xe5e(%rip),%xmm0
divsd  0xe5e(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sin@plt>
movsd  0x8(%rsp),%xmm1
mulss  %xmm0,%xmm0
addss  0x4(%rsp),%xmm0
addsd  0xe45(%rip),%xmm1
add    $0x2,%ebx
cmp    $0xac45,%ebx
jne    1150 <main+0x20>
divss  0xe36(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     11f1 <main+0xc1>
sqrtss %xmm0,%xmm0
jmp    11f6 <main+0xc6>
call   1050 <sqrt@plt>
lea    0xe1f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [44100 x float]
%5 = alloca float
%6 = alloca float
store i32 0, i32* %1
store i32 0, i32* %2
store i32 44100, i32* %3
%7 = bitcast [44100 x float]* %4 to i8*
store float 0.000000e+00, float* %5
store float 0.000000e+00, float* %6
store i32 0, i32* %2
br label %8
8: ; preds = %34, %0
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %37
12: ; preds = %8
%13 = load i32, i32* %2
%14 = sitofp i32 %13 to double
%15 = fmul double 6.282000e+00, %14
%16 = load i32, i32* %3
%17 = sitofp i32 %16 to double
%18 = fdiv double %15, %17
%19 = fptosi double %18 to i32
%20 = call float @sin(i32 %19)
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [44100 x float], [44100 x float]* %4, i64 0, i64 %22
store float %20, float* %23
%24 = load i32, i32* %2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [44100 x float], [44100 x float]* %4, i64 0, i64 %25
%27 = load float, float* %26
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [44100 x float], [44100 x float]* %4, i64 0, i64 %29
%31 = load float, float* %30
%32 = load float, float* %5
%33 = call float @llvm.fmuladd.f32(float %27, float %31, float %32)
store float %33, float* %5
br label %34
34: ; preds = %12
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
br label %8
37: ; preds = %8
%38 = load float, float* %5
%39 = load i32, i32* %3
%40 = sitofp i32 %39 to float
%41 = fdiv float %38, %40
%42 = call float @sqrt(float %41)
store float %42, float* %6
%43 = load float, float* %6
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), float %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%f\0A\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi float [ 0.000000e+00, %0 ], [ %16, %1 ]
%3 = phi i32 [ 0, %0 ], [ %17, %1 ]
%4 = sitofp i32 %3 to double
%5 = fmul double %4, 6.282000e+00
%6 = fdiv double %5, 4.410000e+04
%7 = fptosi double %6 to i32
%8 = tail call float @sin(i32 %7)
%9 = tail call float @llvm.fmuladd.f32(float %8, float %8, float %2)
%10 = or i32 %3, 1
%11 = sitofp i32 %10 to double
%12 = fmul double %11, 6.282000e+00
%13 = fdiv double %12, 4.410000e+04
%14 = fptosi double %13 to i32
%15 = tail call float @sin(i32 %14)
%16 = tail call float @llvm.fmuladd.f32(float %15, float %15, float %9)
%17 = add nuw nsw i32 %3, 2
%18 = icmp eq i32 %17, 44100
br i1 %18, label %19, label %1
19: ; preds = %1
%20 = fdiv float %16, 4.410000e+04
%21 = tail call float @sqrt(float %20)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), float %21)
ret i32 0
}