#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 RAND_MAX;
double cos(double);
double log(double);
double rand();
double sin(double);
double sqrt(double);
int /*<<< orphan*/ srand(int);
void gaussianNoise(int *image, int *width, int *height, int *depth,
                   double *mean, double *variance) {
  int i = 0, plane_size = *width * *height * *depth;
  double temp, u1, u2;
  int g1, g2;
  srand(1);
  for (i = 0; i < plane_size; i = i + 2) {
    int res1 = 0, res2 = 0;
    while (u1 == 0.0)
      u1 = (1.0 * rand() / RAND_MAX);
    u2 = (1.0 * rand() / RAND_MAX);
    temp = sqrt(-2.0 * *variance * log(u1));
    g1 = (int)(temp * cos(6.283186 * u2) + *mean);
    g2 = (int)(temp * sin(6.283186 * u2) + *mean);
    res1 = ((image[i] + g1) < (0))
               ? (0)
               : (((image[i] + g1) > (255)) ? (255) : (image[i] + g1));
    image[i] = res1;
    if (i + 1 < plane_size) {
      res2 =
          ((image[i + 1] + g2) < (0))
              ? (0)
              : (((image[i + 1] + g2) > (255)) ? (255) : (image[i + 1] + g2));
      image[i + 1] = res2;
    }
    u1 = 0.0;
  }
}


x86 assembly (clang, -O0):
<gaussianNoise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
imul   (%rcx),%eax
mov    -0x20(%rbp),%rcx
imul   (%rcx),%eax
mov    %eax,-0x38(%rbp)
mov    $0x1,%edi
call   1030 <srand@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    140f <gaussianNoise+0x2af>
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    120f <gaussianNoise+0xaf>
jp     120f <gaussianNoise+0xaf>
mov    $0x0,%al
call   1080 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xe1a(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2de7(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    11cc <gaussianNoise+0x6c>
mov    $0x0,%al
call   1080 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xdef(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2dbc(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x30(%rbp),%rax
movsd  0xdc7(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xd84(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x70(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x54(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xd49(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x54(%rbp),%eax
cmp    $0x0,%eax
jge    1301 <gaussianNoise+0x1a1>
xor    %eax,%eax
mov    %eax,-0x7c(%rbp)
jmp    133e <gaussianNoise+0x1de>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x54(%rbp),%eax
cmp    $0xff,%eax
jle    1327 <gaussianNoise+0x1c7>
mov    $0xff,%eax
mov    %eax,-0x80(%rbp)
jmp    1338 <gaussianNoise+0x1d8>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cmp    -0x38(%rbp),%eax
jge    13f9 <gaussianNoise+0x299>
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
add    -0x58(%rbp),%eax
cmp    $0x0,%eax
jge    138a <gaussianNoise+0x22a>
xor    %eax,%eax
mov    %eax,-0x84(%rbp)
jmp    13dd <gaussianNoise+0x27d>
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
add    -0x58(%rbp),%eax
cmp    $0xff,%eax
jle    13b8 <gaussianNoise+0x258>
mov    $0xff,%eax
mov    %eax,-0x88(%rbp)
jmp    13d1 <gaussianNoise+0x271>
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x34(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
jmp    11b2 <gaussianNoise+0x52>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussianNoise>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x18(%rsp)
mov    %r8,%r15
mov    %rdi,%rbx
mov    (%rdx),%ebp
imul   (%rsi),%ebp
imul   (%rcx),%ebp
mov    $0x1,%edi
call   1030 <srand@plt>
test   %ebp,%ebp
jle    12d4 <gaussianNoise+0x174>
mov    %ebp,%eax
mov    %rax,0x10(%rsp)
mov    0x2e47(%rip),%r13
xor    %r14d,%r14d
jmp    11c0 <gaussianNoise+0x60>
add    $0x2,%r14
cmp    %r14d,%ebp
jle    12d4 <gaussianNoise+0x174>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1080 <rand@plt>
divsd  0x0(%r13),%xmm0
ucomisd 0xe3b(%rip),%xmm0
jne    11d9 <gaussianNoise+0x79>
jnp    11c0 <gaussianNoise+0x60>
xor    %eax,%eax
movsd  %xmm0,(%rsp)
call   1080 <rand@plt>
divsd  0x0(%r13),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x18(%rsp),%rax
movsd  (%rax),%xmm0
mulsd  0xdfe(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  (%rsp),%xmm0
call   1060 <log@plt>
mulsd  0x20(%rsp),%xmm0
ucomisd 0xdf0(%rip),%xmm0
jb     1228 <gaussianNoise+0xc8>
sqrtsd %xmm0,%xmm0
jmp    122d <gaussianNoise+0xcd>
call   1070 <sqrt@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xdc8(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
addsd  (%r15),%xmm0
cvttsd2si %xmm0,%r12d
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
add    (%rbx,%r14,4),%r12d
cmp    $0xff,%r12d
mov    $0xff,%eax
cmovge %eax,%r12d
test   %r12d,%r12d
mov    $0x0,%eax
cmovs  %eax,%r12d
movsd  (%r15),%xmm1
mov    %r12d,(%rbx,%r14,4)
mov    %r14,%rax
or     $0x1,%rax
cmp    0x10(%rsp),%rax
jge    11a6 <gaussianNoise+0x46>
movsd  (%rsp),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
cvttsd2si %xmm2,%ecx
add    (%rbx,%rax,4),%ecx
cmp    $0xff,%ecx
mov    $0xff,%edx
cmovge %edx,%ecx
test   %ecx,%ecx
mov    $0x0,%edx
cmovs  %edx,%ecx
mov    %ecx,(%rbx,%rax,4)
jmp    11a6 <gaussianNoise+0x46>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define void @gaussianNoise(i32* %0, i32* %1, i32* %2, i32* %3, double* %4, double* %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store double* %4, double** %11
store double* %5, double** %12
store i32 0, i32* %13
%22 = load i32*, i32** %8
%23 = load i32, i32* %22
%24 = load i32*, i32** %9
%25 = load i32, i32* %24
%26 = mul nsw i32 %23, %25
%27 = load i32*, i32** %10
%28 = load i32, i32* %27
%29 = mul nsw i32 %26, %28
store i32 %29, i32* %14
%30 = call i32 @srand(i32 1)
store i32 0, i32* %13
br label %31
31: ; preds = %154, %6
%32 = load i32, i32* %13
%33 = load i32, i32* %14
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %157
35: ; preds = %31
store i32 0, i32* %20
store i32 0, i32* %21
br label %36
36: ; preds = %39, %35
%37 = load double, double* %16
%38 = fcmp oeq double %37, 0.000000e+00
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = call double (...) @rand()
%41 = fmul double 1.000000e+00, %40
%42 = load double, double* @RAND_MAX
%43 = fdiv double %41, %42
store double %43, double* %16
br label %36
44: ; preds = %36
%45 = call double (...) @rand()
%46 = fmul double 1.000000e+00, %45
%47 = load double, double* @RAND_MAX
%48 = fdiv double %46, %47
store double %48, double* %17
%49 = load double*, double** %12
%50 = load double, double* %49
%51 = fmul double -2.000000e+00, %50
%52 = load double, double* %16
%53 = call double @log(double %52)
%54 = fmul double %51, %53
%55 = call double @sqrt(double %54)
store double %55, double* %15
%56 = load double, double* %15
%57 = load double, double* %17
%58 = fmul double 0x401921FB82C2BD7F, %57
%59 = call double @cos(double %58)
%60 = load double*, double** %11
%61 = load double, double* %60
%62 = call double @llvm.fmuladd.f64(double %56, double %59, double %61)
%63 = fptosi double %62 to i32
store i32 %63, i32* %18
%64 = load double, double* %15
%65 = load double, double* %17
%66 = fmul double 0x401921FB82C2BD7F, %65
%67 = call double @sin(double %66)
%68 = load double*, double** %11
%69 = load double, double* %68
%70 = call double @llvm.fmuladd.f64(double %64, double %67, double %69)
%71 = fptosi double %70 to i32
store i32 %71, i32* %19
%72 = load i32*, i32** %7
%73 = load i32, i32* %13
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %72, i64 %74
%76 = load i32, i32* %75
%77 = load i32, i32* %18
%78 = add nsw i32 %76, %77
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %44
br label %101
81: ; preds = %44
%82 = load i32*, i32** %7
%83 = load i32, i32* %13
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %82, i64 %84
%86 = load i32, i32* %85
%87 = load i32, i32* %18
%88 = add nsw i32 %86, %87
%89 = icmp sgt i32 %88, 255
br i1 %89, label %90, label %91
90: ; preds = %81
br label %99
91: ; preds = %81
%92 = load i32*, i32** %7
%93 = load i32, i32* %13
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i32, i32* %92, i64 %94
%96 = load i32, i32* %95
%97 = load i32, i32* %18
%98 = add nsw i32 %96, %97
br label %99
99: ; preds = %91, %90
%100 = phi i32 [ 255, %90 ], [ %98, %91 ]
br label %101
101: ; preds = %99, %80
%102 = phi i32 [ 0, %80 ], [ %100, %99 ]
store i32 %102, i32* %20
%103 = load i32, i32* %20
%104 = load i32*, i32** %7
%105 = load i32, i32* %13
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i32, i32* %104, i64 %106
store i32 %103, i32* %107
%108 = load i32, i32* %13
%109 = add nsw i32 %108, 1
%110 = load i32, i32* %14
%111 = icmp slt i32 %109, %110
br i1 %111, label %112, label %153
112: ; preds = %101
%113 = load i32*, i32** %7
%114 = load i32, i32* %13
%115 = add nsw i32 %114, 1
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32, i32* %113, i64 %116
%118 = load i32, i32* %117
%119 = load i32, i32* %19
%120 = add nsw i32 %118, %119
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %123
122: ; preds = %112
br label %145
123: ; preds = %112
%124 = load i32*, i32** %7
%125 = load i32, i32* %13
%126 = add nsw i32 %125, 1
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i32, i32* %124, i64 %127
%129 = load i32, i32* %128
%130 = load i32, i32* %19
%131 = add nsw i32 %129, %130
%132 = icmp sgt i32 %131, 255
br i1 %132, label %133, label %134
133: ; preds = %123
br label %143
134: ; preds = %123
%135 = load i32*, i32** %7
%136 = load i32, i32* %13
%137 = add nsw i32 %136, 1
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i32, i32* %135, i64 %138
%140 = load i32, i32* %139
%141 = load i32, i32* %19
%142 = add nsw i32 %140, %141
br label %143
143: ; preds = %134, %133
%144 = phi i32 [ 255, %133 ], [ %142, %134 ]
br label %145
145: ; preds = %143, %122
%146 = phi i32 [ 0, %122 ], [ %144, %143 ]
store i32 %146, i32* %21
%147 = load i32, i32* %21
%148 = load i32*, i32** %7
%149 = load i32, i32* %13
%150 = add nsw i32 %149, 1
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds i32, i32* %148, i64 %151
store i32 %147, i32* %152
br label %153
153: ; preds = %145, %101
store double 0.000000e+00, double* %16
br label %154
154: ; preds = %153
%155 = load i32, i32* %13
%156 = add nsw i32 %155, 2
store i32 %156, i32* %13
br label %31
157: ; preds = %31
ret void
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define void @gaussianNoise(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture %3, double* nocapture %4, double* nocapture %5) {
%7 = load i32, i32* %1
%8 = load i32, i32* %2
%9 = mul nsw i32 %8, %7
%10 = load i32, i32* %3
%11 = mul nsw i32 %9, %10
%12 = tail call i32 @srand(i32 1)
%13 = icmp sgt i32 %11, 0
br i1 %13, label %14, label %62
14: ; preds = %6
%15 = zext i32 %11 to i64
br label %16
16: ; preds = %14, %58
%17 = phi i64 [ 0, %14 ], [ %59, %58 ]
br label %18
18: ; preds = %16, %18
%19 = tail call double (...) @rand()
%20 = load double, double* @RAND_MAX
%21 = fdiv double %19, %20
%22 = fcmp oeq double %21, 0.000000e+00
br i1 %22, label %18, label %23
23: ; preds = %18
%24 = tail call double (...) @rand()
%25 = load double, double* @RAND_MAX
%26 = fdiv double %24, %25
%27 = load double, double* %5
%28 = fmul double %27, -2.000000e+00
%29 = tail call double @log(double %21)
%30 = fmul double %28, %29
%31 = tail call double @sqrt(double %30)
%32 = fmul double %26, 0x401921FB82C2BD7F
%33 = tail call double @cos(double %32)
%34 = load double, double* %4
%35 = tail call double @llvm.fmuladd.f64(double %31, double %33, double %34)
%36 = fptosi double %35 to i32
%37 = tail call double @sin(double %32)
%38 = load double, double* %4
%39 = getelementptr inbounds i32, i32* %0, i64 %17
%40 = load i32, i32* %39
%41 = add nsw i32 %40, %36
%42 = icmp slt i32 %41, 255
%43 = select i1 %42, i32 %41, i32 255
%44 = icmp sgt i32 %43, 0
%45 = select i1 %44, i32 %43, i32 0
store i32 %45, i32* %39
%46 = or i64 %17, 1
%47 = icmp slt i64 %46, %15
br i1 %47, label %48, label %58
48: ; preds = %23
%49 = tail call double @llvm.fmuladd.f64(double %31, double %37, double %38)
%50 = fptosi double %49 to i32
%51 = getelementptr inbounds i32, i32* %0, i64 %46
%52 = load i32, i32* %51
%53 = add nsw i32 %52, %50
%54 = icmp slt i32 %53, 255
%55 = select i1 %54, i32 %53, i32 255
%56 = icmp sgt i32 %55, 0
%57 = select i1 %56, i32 %55, i32 0
store i32 %57, i32* %51
br label %58
58: ; preds = %48, %23
%59 = add nuw i64 %17, 2
%60 = trunc i64 %59 to i32
%61 = icmp sgt i32 %11, %60
br i1 %61, label %16, label %62
62: ; preds = %58, %6
ret void
}