#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 GaussRand();
double sqrt(double);
int awgn_real(double noise[], int len, double var) {
  double *vec_noise = noise;
  int i;
  for (i = 0; i < len; i++)
    vec_noise[i] = sqrt(var) * GaussRand();
  return 0;
}


x86 assembly (clang, -O0):
<awgn_real>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118c <awgn_real+0x6c>
movsd  -0x18(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <GaussRand@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1143 <awgn_real+0x23>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<awgn_real>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x8(%rsp)
test   %esi,%esi
jle    1195 <awgn_real+0x75>
mov    %rdi,%r14
mov    %esi,%r15d
movsd  0x8(%rsp),%xmm0
sqrtsd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %ebx,%ebx
jmp    1172 <awgn_real+0x52>
nopl   (%rax)
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
call   1030 <GaussRand@plt>
mulsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1195 <awgn_real+0x75>
movsd  0x8(%rsp),%xmm0
ucomisd 0xe80(%rip),%xmm0
movsd  0x10(%rsp),%xmm0
jae    1150 <awgn_real+0x30>
movsd  0x8(%rsp),%xmm0
call   1040 <sqrt@plt>
jmp    1150 <awgn_real+0x30>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @awgn_real(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca double*
%8 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
%9 = load double*, double** %4
store double* %9, double** %7
store i32 0, i32* %8
br label %10
10: ; preds = %23, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = load double, double* %6
%16 = call double @sqrt(double %15)
%17 = call double (...) @GaussRand()
%18 = fmul double %16, %17
%19 = load double*, double** %7
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
store double %18, double* %22
br label %23
23: ; preds = %14
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %10
26: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
define i32 @awgn_real(double* nocapture writeonly %0, i32 %1, double %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %15
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %13, %7 ]
%9 = tail call double @sqrt(double %2)
%10 = tail call double (...) @GaussRand()
%11 = fmul double %9, %10
%12 = getelementptr inbounds double, double* %0, i64 %8
store double %11, double* %12
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, %6
br i1 %14, label %15, label %7
15: ; preds = %7, %3
ret i32 0
}