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


x86 assembly (clang, -O0):
<ch_awgn_real>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    11a7 <ch_awgn_real+0x87>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <GaussRand@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %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 <ch_awgn_real+0x23>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ch_awgn_real>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,(%rsp)
test   %esi,%esi
jle    11a5 <ch_awgn_real+0x85>
mov    %rdi,%r15
mov    %esi,%r14d
movsd  (%rsp),%xmm0
sqrtsd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
jmp    1178 <ch_awgn_real+0x58>
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1030 <GaussRand@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
je     11a5 <ch_awgn_real+0x85>
movsd  (%r15,%rbx,8),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  (%rsp),%xmm0
ucomisd 0xe6f(%rip),%xmm0
movsd  0x8(%rsp),%xmm0
jae    1150 <ch_awgn_real+0x30>
movsd  (%rsp),%xmm0
call   1040 <sqrt@plt>
jmp    1150 <ch_awgn_real+0x30>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @ch_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 = %28, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = load double*, double** %7
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = load double, double* %6
%21 = call double @sqrt(double %20)
%22 = call double (...) @GaussRand()
%23 = call double @llvm.fmuladd.f64(double %21, double %22, double %19)
%24 = load double*, double** %7
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
store double %23, double* %27
br label %28
28: ; preds = %14
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %10
31: ; preds = %10
ret i32 0
}

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