#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 */
struct timeval {
  unsigned int tv_sec;
  double tv_usec;
};
typedef scalar_t__ clock_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int atoi(char *);
scalar_t__ clock();
int f(double, double, double, double, double);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, double, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
double uran(double, double);
int main(int argc, char **argv) {
  srand(time(0));
  double a = 0.0;
  double b = 1.0;
  double X[5];
  double integral = 0.0;
  double vol = 1.0;
  assert(argc == 2);
  int n = atoi(argv[1]);
  clock_t ts = clock();
  struct timeval start, end;
  gettimeofday(&start, NULL);
  omp_set_num_threads(16);
#pragma omp parallel for shared(integral)
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      X[j] = uran(a, b);
    }
#pragma omp atomic
    integral += f(X[0], X[1], X[2], X[3], X[4]) / n;
  }
  for (int j = 0; j < 5; j++) {
    vol *= b - a;
  }
  integral *= vol;
  gettimeofday(&end, NULL);
  double elapsed =
      ((end.tv_sec - start.tv_sec) * 1000000u + end.tv_usec - start.tv_usec) /
      1.e6;
  ts = clock() - ts;
  printf("%ld clocks (%lf seconds)\n", ts, elapsed);
  printf("integral is: %lf\n", integral);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe29(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xe14(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x64(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x70(%rbp)
lea    -0x80(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    $0x10,%edi
call   10b0 <omp_set_num_threads@plt>
movl   $0x0,-0x94(%rbp)
mov    -0x94(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    12d8 <main+0x138>
movl   $0x0,-0x98(%rbp)
cmpl   $0x5,-0x98(%rbp)
jge    1294 <main+0xf4>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1030 <uran@plt>
movslq -0x98(%rbp),%rax
movsd  %xmm0,-0x50(%rbp,%rax,8)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    1257 <main+0xb7>
movsd  -0x50(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm3
movsd  -0x30(%rbp),%xmm4
call   1050 <f@plt>
cltd
idivl  -0x64(%rbp)
cvtsi2sd %eax,%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    123e <main+0x9e>
movl   $0x0,-0x9c(%rbp)
cmpl   $0x5,-0x9c(%rbp)
jge    1317 <main+0x177>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    12e2 <main+0x142>
movsd  -0x60(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
xor    %eax,%eax
mov    %eax,%esi
lea    -0x90(%rbp),%rdi
call   1070 <gettimeofday@plt>
mov    -0x90(%rbp),%eax
mov    -0x80(%rbp),%ecx
sub    %ecx,%eax
imul   $0xf4240,%eax,%eax
cvtsi2sd %rax,%xmm0
addsd  -0x88(%rbp),%xmm0
ff
subsd  -0x78(%rbp),%xmm0
movsd  0xca3(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x70(%rbp),%rax
mov    %rax,-0x70(%rbp)
cvtsi2sdq -0x70(%rbp),%xmm0
movsd  -0xa8(%rbp),%xmm1
ff
lea    0xc7b(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
movsd  -0x58(%rbp),%xmm0
lea    0xc82(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
xor    %edi,%edi
cmp    $0x2,%ebp
sete   %dil
call   1090 <assert@plt>
mov    0x8(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
lea    0x40(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    $0x10,%edi
call   10b0 <omp_set_num_threads@plt>
xorpd  %xmm0,%xmm0
test   %ebx,%ebx
jle    12c3 <main+0x123>
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%ebp
nopl   0x0(%rax,%rax,1)
xorpd  %xmm0,%xmm0
movsd  0xde4(%rip),%xmm1
call   1030 <uran@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  0xdcd(%rip),%xmm1
call   1030 <uran@plt>
movsd  %xmm0,0x28(%rsp)
xorpd  %xmm0,%xmm0
movsd  0xdb6(%rip),%xmm1
call   1030 <uran@plt>
movsd  %xmm0,0x20(%rsp)
xorpd  %xmm0,%xmm0
movsd  0xd9f(%rip),%xmm1
call   1030 <uran@plt>
movsd  %xmm0,0x18(%rsp)
xorpd  %xmm0,%xmm0
movsd  0xd88(%rip),%xmm1
call   1030 <uran@plt>
movapd %xmm0,%xmm4
movsd  0x10(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
call   1050 <f@plt>
cltd
idiv   %ebx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0xffffffff,%ebp
jne    1210 <main+0x70>
jmp    12c9 <main+0x129>
movsd  %xmm0,0x8(%rsp)
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    0x30(%rsp),%eax
sub    0x40(%rsp),%eax
imul   $0xf4240,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x38(%rsp),%xmm0
subsd  0x48(%rsp),%xmm0
divsd  0xd09(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
lea    0xcf2(%rip),%rdi
movsd  0x10(%rsp),%xmm1
mov    $0x2,%al
call   1060 <printf@plt>
lea    0xcf8(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, double }
@.str = [26 x i8] c"%ld clocks (%lf seconds)\0A\00"
@.str.1 = [18 x i8] c"integral is: %lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca [5 x double]
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca i64
%13 = alloca %struct.timeval
%14 = alloca %struct.timeval
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = call i32 @time(i32 0)
%20 = call i32 @srand(i32 %19)
store double 0.000000e+00, double* %6
store double 1.000000e+00, double* %7
store double 0.000000e+00, double* %9
store double 1.000000e+00, double* %10
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 2
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %11
%29 = call i64 (...) @clock()
store i64 %29, i64* %12
%30 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%31 = call i32 @omp_set_num_threads(i32 16)
store i32 0, i32* %15
br label %32
32: ; preds = %67, %2
%33 = load i32, i32* %15
%34 = load i32, i32* %11
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %70
36: ; preds = %32
store i32 0, i32* %16
br label %37
37: ; preds = %47, %36
%38 = load i32, i32* %16
%39 = icmp slt i32 %38, 5
br i1 %39, label %40, label %50
40: ; preds = %37
%41 = load double, double* %6
%42 = load double, double* %7
%43 = call double @uran(double %41, double %42)
%44 = load i32, i32* %16
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 %45
store double %43, double* %46
br label %47
47: ; preds = %40
%48 = load i32, i32* %16
%49 = add nsw i32 %48, 1
store i32 %49, i32* %16
br label %37
50: ; preds = %37
%51 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 0
%52 = load double, double* %51
%53 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 1
%54 = load double, double* %53
%55 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 2
%56 = load double, double* %55
%57 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 3
%58 = load double, double* %57
%59 = getelementptr inbounds [5 x double], [5 x double]* %8, i64 0, i64 4
%60 = load double, double* %59
%61 = call i32 @f(double %52, double %54, double %56, double %58, double %60)
%62 = load i32, i32* %11
%63 = sdiv i32 %61, %62
%64 = sitofp i32 %63 to double
%65 = load double, double* %9
%66 = fadd double %65, %64
store double %66, double* %9
br label %67
67: ; preds = %50
%68 = load i32, i32* %15
%69 = add nsw i32 %68, 1
store i32 %69, i32* %15
br label %32
70: ; preds = %32
store i32 0, i32* %17
br label %71
71: ; preds = %80, %70
%72 = load i32, i32* %17
%73 = icmp slt i32 %72, 5
br i1 %73, label %74, label %83
74: ; preds = %71
%75 = load double, double* %7
%76 = load double, double* %6
%77 = fsub double %75, %76
%78 = load double, double* %10
%79 = fmul double %78, %77
store double %79, double* %10
br label %80
80: ; preds = %74
%81 = load i32, i32* %17
%82 = add nsw i32 %81, 1
store i32 %82, i32* %17
br label %71
83: ; preds = %71
%84 = load double, double* %10
%85 = load double, double* %9
%86 = fmul double %85, %84
store double %86, double* %9
%87 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%88 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%89 = load i32, i32* %88
%90 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%91 = load i32, i32* %90
%92 = sub i32 %89, %91
%93 = mul i32 %92, 1000000
%94 = uitofp i32 %93 to double
%95 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%96 = load double, double* %95
%97 = fadd double %94, %96
%98 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%99 = load double, double* %98
%100 = fsub double %97, %99
%101 = fdiv double %100, 1.000000e+06
store double %101, double* %18
%102 = call i64 (...) @clock()
%103 = load i64, i64* %12
%104 = sub nsw i64 %102, %103
store i64 %104, i64* %12
%105 = load i64, i64* %12
%106 = sitofp i64 %105 to double
%107 = load double, double* %18
%108 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double %106, double %107)
%109 = load double, double* %9
%110 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %109)
%111 = load i32, i32* %3
ret i32 %111
}

LLVM IR (-O2):
%struct.timeval = type { i32, double }
@.str = [26 x i8] c"%ld clocks (%lf seconds)\0A\00"
@.str.1 = [18 x i8] c"integral is: %lf\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = tail call i32 @time(i32 0)
%6 = tail call i32 @srand(i32 %5)
%7 = icmp eq i32 %0, 2
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = tail call i64 (...) @clock()
%14 = bitcast %struct.timeval* %3 to i8*
%15 = bitcast %struct.timeval* %4 to i8*
%16 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%17 = tail call i32 @omp_set_num_threads(i32 16)
%18 = icmp sgt i32 %12, 0
br i1 %18, label %19, label %33
19: ; preds = %2, %19
%20 = phi double [ %30, %19 ], [ 0.000000e+00, %2 ]
%21 = phi i32 [ %31, %19 ], [ 0, %2 ]
%22 = tail call double @uran(double 0.000000e+00, double 1.000000e+00)
%23 = tail call double @uran(double 0.000000e+00, double 1.000000e+00)
%24 = tail call double @uran(double 0.000000e+00, double 1.000000e+00)
%25 = tail call double @uran(double 0.000000e+00, double 1.000000e+00)
%26 = tail call double @uran(double 0.000000e+00, double 1.000000e+00)
%27 = tail call i32 @f(double %22, double %23, double %24, double %25, double %26)
%28 = sdiv i32 %27, %12
%29 = sitofp i32 %28 to double
%30 = fadd double %20, %29
%31 = add nuw nsw i32 %21, 1
%32 = icmp eq i32 %31, %12
br i1 %32, label %33, label %19
33: ; preds = %19, %2
%34 = phi double [ 0.000000e+00, %2 ], [ %30, %19 ]
%35 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%39 = load i32, i32* %38
%40 = sub i32 %37, %39
%41 = mul i32 %40, 1000000
%42 = uitofp i32 %41 to double
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%44 = load double, double* %43
%45 = fadd double %44, %42
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%47 = load double, double* %46
%48 = fsub double %45, %47
%49 = fdiv double %48, 1.000000e+06
%50 = tail call i64 (...) @clock()
%51 = sub nsw i64 %50, %13
%52 = sitofp i64 %51 to double
%53 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double %52, double %49)
%54 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %34)
ret i32 0
}