#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 */
double atof(char *);
int atoi(char *);
double normrand(double, double);
int /*<<< orphan*/ printf(char *, ...);
double sqrt(double);
double sum(double *, int);
void test_normrand(int argc, char *argv[]) {
  if (argc < 4) {
    printf("usage: %s <n> <mu> <sigma>\n", argv[0]);
    return;
  }
  int i, n = atoi(argv[1]);
  double mu = atof(argv[2]);
  double sigma = atof(argv[3]);
  printf("x = [ ");
  double x[n];
  for (i = 0; i < n; i++) {
    x[i] = normrand(mu, sigma);
    printf("%f, ", x[i]);
  }
  printf("]\n");
  double sample_mu = sum(x, n) / (double)n;
  for (i = 0; i < n; i++)
    x[i] = (x[i] - sample_mu) * (x[i] - sample_mu);
  double sample_sigma = sqrt(sum(x, n) / (double)n);
  printf("sample mu = %f, sample_sigma = %f\n", sample_mu, sample_sigma);
}


x86 assembly (clang, -O0):
<test_normrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x4(%rbp)
jge    1193 <test_normrand+0x33>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1304 <test_normrand+0x1a4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x28(%rbp)
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1250 <test_normrand+0xf0>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1060 <normrand@plt>
mov    -0x50(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xde8(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1203 <test_normrand+0xa3>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <sum@plt>
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12c6 <test_normrand+0x166>
mov    -0x50(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x40(%rbp),%xmm0
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
subsd  -0x40(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    127f <test_normrand+0x11f>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <sum@plt>
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1080 <sqrt@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
lea    0xd35(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_normrand>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jg     11a8 <test_normrand+0x38>
mov    (%rbx),%rsi
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x40(%rbp)
mov    0x18(%rbx),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x30(%rbp)
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%r12
mov    %r15d,%r14d
mov    %rsp,%r13
lea    0xf(,%r14,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
test   %r15d,%r15d
jle    1239 <test_normrand+0xc9>
xor    %ebx,%ebx
lea    0xe1c(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsd  -0x40(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
call   1070 <normrand@plt>
movsd  %xmm0,0x0(%r13,%rbx,8)
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1210 <test_normrand+0xa0>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r14d,%esi
call   1060 <sum@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
movsd  %xmm1,-0x30(%rbp)
divsd  %xmm1,%xmm0
test   %r14d,%r14d
jle    136f <test_normrand+0x1ff>
cmp    $0x4,%r14d
jae    1277 <test_normrand+0x107>
xor    %eax,%eax
jmp    1350 <test_normrand+0x1e0>
mov    %r14d,%eax
and    $0xfffffffc,%eax
movapd %xmm0,%xmm5
unpcklpd %xmm0,%xmm5
lea    -0x4(%rax),%rcx
mov    %rcx,%rdx
shr    $0x2,%rdx
add    $0x1,%rdx
test   %rcx,%rcx
je     13c4 <test_normrand+0x254>
mov    %rdx,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
movapd 0x0(%r13,%rcx,8),%xmm1
movapd 0x10(%r13,%rcx,8),%xmm2
movapd 0x20(%r13,%rcx,8),%xmm3
movapd 0x30(%r13,%rcx,8),%xmm4
subpd  %xmm5,%xmm1
subpd  %xmm5,%xmm2
mulpd  %xmm1,%xmm1
mulpd  %xmm2,%xmm2
movapd %xmm1,0x0(%r13,%rcx,8)
movapd %xmm2,0x10(%r13,%rcx,8)
subpd  %xmm5,%xmm3
subpd  %xmm5,%xmm4
mulpd  %xmm3,%xmm3
mulpd  %xmm4,%xmm4
movapd %xmm3,0x20(%r13,%rcx,8)
movapd %xmm4,0x30(%r13,%rcx,8)
add    $0x8,%rcx
add    $0xfffffffffffffffe,%rsi
jne    12b0 <test_normrand+0x140>
test   $0x1,%dl
je     1343 <test_normrand+0x1d3>
movapd 0x0(%r13,%rcx,8),%xmm1
movapd 0x10(%r13,%rcx,8),%xmm2
subpd  %xmm5,%xmm1
subpd  %xmm5,%xmm2
mulpd  %xmm1,%xmm1
mulpd  %xmm2,%xmm2
movapd %xmm1,0x0(%r13,%rcx,8)
movapd %xmm2,0x10(%r13,%rcx,8)
cmp    %r14,%rax
je     136f <test_normrand+0x1ff>
nopl   0x0(%rax,%rax,1)
movsd  0x0(%r13,%rax,8),%xmm1
subsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm1
movsd  %xmm1,0x0(%r13,%rax,8)
add    $0x1,%rax
cmp    %rax,%r14
jne    1350 <test_normrand+0x1e0>
movapd %xmm0,-0x40(%rbp)
mov    %r13,%rdi
mov    %r14d,%esi
call   1060 <sum@plt>
divsd  -0x30(%rbp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1397 <test_normrand+0x227>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    13a0 <test_normrand+0x230>
call   1090 <sqrt@plt>
movapd %xmm0,%xmm1
lea    0xc81(%rip),%rdi
movaps -0x40(%rbp),%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
mov    %r12,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ecx,%ecx
test   $0x1,%dl
jne    1317 <test_normrand+0x1a7>
jmp    1343 <test_normrand+0x1d3>

LLVM IR (-O0):
@.str = [28 x i8] c"usage: %s <n> <mu> <sigma>\0A\00"
@.str.1 = [7 x i8] c"x = [ \00"
@.str.2 = [5 x i8] c"%f, \00"
@.str.3 = [3 x i8] c"]\0A\00"
@.str.4 = [35 x i8] c"sample mu = %f, sample_sigma = %f\0A\00"
define void @test_normrand(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca i8*
%10 = alloca i64
%11 = alloca double
%12 = alloca double
store i32 %0, i32* %3
store i8** %1, i8*** %4
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %99
20: ; preds = %2
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %6
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call double @atof(i8* %27)
store double %28, double* %7
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
%32 = call double @atof(i8* %31)
store double %32, double* %8
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %6
%35 = zext i32 %34 to i64
%36 = call i8* @llvm.stacksave()
store i8* %36, i8** %9
%37 = alloca double, i64 %35
store i64 %35, i64* %10
store i32 0, i32* %5
br label %38
38: ; preds = %54, %20
%39 = load i32, i32* %5
%40 = load i32, i32* %6
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %57
42: ; preds = %38
%43 = load double, double* %7
%44 = load double, double* %8
%45 = call double @normrand(double %43, double %44)
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %37, i64 %47
store double %45, double* %48
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %37, i64 %50
%52 = load double, double* %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %52)
br label %54
54: ; preds = %42
%55 = load i32, i32* %5
%56 = add nsw i32 %55, 1
store i32 %56, i32* %5
br label %38
57: ; preds = %38
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%59 = load i32, i32* %6
%60 = call double @sum(double* %37, i32 %59)
%61 = load i32, i32* %6
%62 = sitofp i32 %61 to double
%63 = fdiv double %60, %62
store double %63, double* %11
store i32 0, i32* %5
br label %64
64: ; preds = %85, %57
%65 = load i32, i32* %5
%66 = load i32, i32* %6
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %88
68: ; preds = %64
%69 = load i32, i32* %5
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %37, i64 %70
%72 = load double, double* %71
%73 = load double, double* %11
%74 = fsub double %72, %73
%75 = load i32, i32* %5
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %37, i64 %76
%78 = load double, double* %77
%79 = load double, double* %11
%80 = fsub double %78, %79
%81 = fmul double %74, %80
%82 = load i32, i32* %5
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds double, double* %37, i64 %83
store double %81, double* %84
br label %85
85: ; preds = %68
%86 = load i32, i32* %5
%87 = add nsw i32 %86, 1
store i32 %87, i32* %5
br label %64
88: ; preds = %64
%89 = load i32, i32* %6
%90 = call double @sum(double* %37, i32 %89)
%91 = load i32, i32* %6
%92 = sitofp i32 %91 to double
%93 = fdiv double %90, %92
%94 = call double @sqrt(double %93)
store double %94, double* %12
%95 = load double, double* %11
%96 = load double, double* %12
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), double %95, double %96)
%98 = load i8*, i8** %9
br label %99
99: ; preds = %88, %15
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"usage: %s <n> <mu> <sigma>\0A\00"
@.str.1 = [7 x i8] c"x = [ \00"
@.str.2 = [5 x i8] c"%f, \00"
@.str.4 = [35 x i8] c"sample mu = %f, sample_sigma = %f\0A\00"
@str = [2 x i8] c"]\00"
define void @test_normrand(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %113
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call double @atof(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call double @atof(i8* %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = zext i32 %10 to i64
%19 = tail call i8* @llvm.stacksave()
%20 = alloca double, i64 %18
%21 = icmp sgt i32 %10, 0
br i1 %21, label %22, label %29
22: ; preds = %7, %22
%23 = phi i64 [ %27, %22 ], [ 0, %7 ]
%24 = tail call double @normrand(double %13, double %16)
%25 = getelementptr inbounds double, double* %20, i64 %23
store double %24, double* %25
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %24)
%27 = add nuw nsw i64 %23, 1
%28 = icmp eq i64 %27, %18
br i1 %28, label %29, label %22
29: ; preds = %22, %7
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%31 = call double @sum(double* %20, i32 %10)
%32 = sitofp i32 %10 to double
%33 = fdiv double %31, %32
br i1 %21, label %34, label %108
34: ; preds = %29
%35 = icmp ult i32 %10, 4
br i1 %35, label %98, label %36
36: ; preds = %34
%37 = and i64 %18, 4294967292
%38 = insertelement <2 x double> poison, double %33, i64 0
%39 = shufflevector <2 x double> %38, <2 x double> poison, <2 x i32> zeroinitializer
%40 = insertelement <2 x double> poison, double %33, i64 0
%41 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> zeroinitializer
%42 = add nsw i64 %37, -4
%43 = lshr exact i64 %42, 2
%44 = add nuw nsw i64 %43, 1
%45 = and i64 %44, 1
%46 = icmp eq i64 %42, 0
br i1 %46, label %80, label %47
47: ; preds = %36
%48 = and i64 %44, 9223372036854775806
br label %49
49: ; preds = %49, %47
%50 = phi i64 [ 0, %47 ], [ %77, %49 ]
%51 = phi i64 [ 0, %47 ], [ %78, %49 ]
%52 = getelementptr inbounds double, double* %20, i64 %50
%53 = bitcast double* %52 to <2 x double>*
%54 = load <2 x double>, <2 x double>* %53
%55 = getelementptr inbounds double, double* %52, i64 2
%56 = bitcast double* %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = fsub <2 x double> %54, %39
%59 = fsub <2 x double> %57, %41
%60 = fmul <2 x double> %58, %58
%61 = fmul <2 x double> %59, %59
%62 = bitcast double* %52 to <2 x double>*
store <2 x double> %60, <2 x double>* %62
%63 = bitcast double* %55 to <2 x double>*
store <2 x double> %61, <2 x double>* %63
%64 = or i64 %50, 4
%65 = getelementptr inbounds double, double* %20, i64 %64
%66 = bitcast double* %65 to <2 x double>*
%67 = load <2 x double>, <2 x double>* %66
%68 = getelementptr inbounds double, double* %65, i64 2
%69 = bitcast double* %68 to <2 x double>*
%70 = load <2 x double>, <2 x double>* %69
%71 = fsub <2 x double> %67, %39
%72 = fsub <2 x double> %70, %41
%73 = fmul <2 x double> %71, %71
%74 = fmul <2 x double> %72, %72
%75 = bitcast double* %65 to <2 x double>*
store <2 x double> %73, <2 x double>* %75
%76 = bitcast double* %68 to <2 x double>*
store <2 x double> %74, <2 x double>* %76
%77 = add nuw i64 %50, 8
%78 = add i64 %51, 2
%79 = icmp eq i64 %78, %48
br i1 %79, label %80, label %49
80: ; preds = %49, %36
%81 = phi i64 [ 0, %36 ], [ %77, %49 ]
%82 = icmp eq i64 %45, 0
br i1 %82, label %96, label %83
83: ; preds = %80
%84 = getelementptr inbounds double, double* %20, i64 %81
%85 = bitcast double* %84 to <2 x double>*
%86 = load <2 x double>, <2 x double>* %85
%87 = getelementptr inbounds double, double* %84, i64 2
%88 = bitcast double* %87 to <2 x double>*
%89 = load <2 x double>, <2 x double>* %88
%90 = fsub <2 x double> %86, %39
%91 = fsub <2 x double> %89, %41
%92 = fmul <2 x double> %90, %90
%93 = fmul <2 x double> %91, %91
%94 = bitcast double* %84 to <2 x double>*
store <2 x double> %92, <2 x double>* %94
%95 = bitcast double* %87 to <2 x double>*
store <2 x double> %93, <2 x double>* %95
br label %96
96: ; preds = %80, %83
%97 = icmp eq i64 %37, %18
br i1 %97, label %108, label %98
98: ; preds = %34, %96
%99 = phi i64 [ 0, %34 ], [ %37, %96 ]
br label %100
100: ; preds = %98, %100
%101 = phi i64 [ %106, %100 ], [ %99, %98 ]
%102 = getelementptr inbounds double, double* %20, i64 %101
%103 = load double, double* %102
%104 = fsub double %103, %33
%105 = fmul double %104, %104
store double %105, double* %102
%106 = add nuw nsw i64 %101, 1
%107 = icmp eq i64 %106, %18
br i1 %107, label %108, label %100
108: ; preds = %100, %96, %29
%109 = call double @sum(double* %20, i32 %10)
%110 = fdiv double %109, %32
%111 = call double @sqrt(double %110)
%112 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), double %33, double %111)
br label %113
113: ; preds = %108, %4
ret void
}