#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 */
scalar_t__ random(long, long);
int /*<<< orphan*/ randomSeed(long);
void simulateSensorDataWithRandomNoise(double readings[], int sizeReadings,
                                       double meanValues[], double margins[]) {
  randomSeed(0L);
  long randMin, randMax;
  for (int i = 0; i < sizeReadings; i++) {
    long randMin =
        (long)((meanValues[i] - margins[i] * meanValues[i]) * 1000.0);
    long randMax =
        (long)((meanValues[i] + margins[i] * meanValues[i]) * 1000.0);
    readings[i] = ((double)random(randMin, randMax)) / 1000.0;
  }
}


x86 assembly (clang, -O0):
<simulateSensorDataWithRandomNoise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <randomSeed@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122b <simulateSensorDataWithRandomNoise+0x10b>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe5f(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe1b(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1040 <random@plt>
cvtsi2sd %rax,%xmm0
movsd  0xdf4(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1147 <simulateSensorDataWithRandomNoise+0x27>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simulateSensorDataWithRandomNoise>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r12
xor    %edi,%edi
call   1030 <randomSeed@plt>
test   %ebp,%ebp
jle    11aa <simulateSensorDataWithRandomNoise+0x8a>
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%r15,%rbx,8),%xmm0
movsd  (%r14,%rbx,8),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movsd  0xe90(%rip),%xmm3
mulsd  %xmm3,%xmm2
cvttsd2si %xmm2,%rdi
addsd  %xmm0,%xmm1
mulsd  %xmm3,%xmm1
cvttsd2si %xmm1,%rsi
call   1040 <random@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0xe65(%rip),%xmm0
movsd  %xmm0,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <simulateSensorDataWithRandomNoise+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @simulateSensorDataWithRandomNoise(double* %0, i32 %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
store double* %0, double** %5
store i32 %1, i32* %6
store double* %2, double** %7
store double* %3, double** %8
%14 = call i32 @randomSeed(i64 0)
store i32 0, i32* %11
br label %15
15: ; preds = %66, %4
%16 = load i32, i32* %11
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %69
19: ; preds = %15
%20 = load double*, double** %7
%21 = load i32, i32* %11
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = load double*, double** %8
%26 = load i32, i32* %11
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = load double*, double** %7
%31 = load i32, i32* %11
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = fneg double %29
%36 = call double @llvm.fmuladd.f64(double %35, double %34, double %24)
%37 = fmul double %36, 1.000000e+03
%38 = fptosi double %37 to i64
store i64 %38, i64* %12
%39 = load double*, double** %7
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = load double*, double** %8
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = load double*, double** %7
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load double, double* %52
%54 = call double @llvm.fmuladd.f64(double %48, double %53, double %43)
%55 = fmul double %54, 1.000000e+03
%56 = fptosi double %55 to i64
store i64 %56, i64* %13
%57 = load i64, i64* %12
%58 = load i64, i64* %13
%59 = call i64 @random(i64 %57, i64 %58)
%60 = sitofp i64 %59 to double
%61 = fdiv double %60, 1.000000e+03
%62 = load double*, double** %5
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %62, i64 %64
store double %61, double* %65
br label %66
66: ; preds = %19
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %15
69: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @simulateSensorDataWithRandomNoise(double* nocapture writeonly %0, i32 %1, double* nocapture %2, double* nocapture %3) {
%5 = tail call i32 @randomSeed(i64 0)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = zext i32 %1 to i64
br label %10
9: ; preds = %10, %4
ret void
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %27, %10 ]
%12 = getelementptr inbounds double, double* %2, i64 %11
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %3, i64 %11
%15 = load double, double* %14
%16 = fneg double %15
%17 = tail call double @llvm.fmuladd.f64(double %16, double %13, double %13)
%18 = fmul double %17, 1.000000e+03
%19 = fptosi double %18 to i64
%20 = tail call double @llvm.fmuladd.f64(double %15, double %13, double %13)
%21 = fmul double %20, 1.000000e+03
%22 = fptosi double %21 to i64
%23 = tail call i64 @random(i64 %19, i64 %22)
%24 = sitofp i64 %23 to double
%25 = fdiv double %24, 1.000000e+03
%26 = getelementptr inbounds double, double* %0, i64 %11
store double %25, double* %26
%27 = add nuw nsw i64 %11, 1
%28 = icmp eq i64 %27, %8
br i1 %28, label %9, label %10
}