#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 */
char EOF;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ f(double);
double fabs(double const);
char getopt(int, char **, char *);
int omp_get_num_threads();
int omp_get_thread_num();
double omp_get_wtime();
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ print_usage(char *);
int /*<<< orphan*/ printf(char *, double const);
int main(int argc, char *argv[]) {
  const double PI24 = 3.141592653589793238462643;
  int nthreads, tid;
  double d, x, sum = 0.0, pi;
  double starttime, stoptime;
  int n = 1000, i;
  char c;
  if (argc <= 1) {
    print_usage(argv[0]);
  } else {
    while ((c = getopt(argc, argv, "hi:")) != EOF) {
      switch (c) {
      case 'h':
        print_usage(argv[0]);
      case 'i':
        n = atoi(optarg);
        break;
      default:
        print_usage(argv[0]);
      }
    }
  }
  d = 1.0 / (double)n;
#pragma omp parallel default(shared) private(nthreads, tid, x)
  {
    tid = omp_get_thread_num();
#pragma omp master
    {
      nthreads = omp_get_num_threads();
      printf("Number of threads = %d\n", nthreads);
      starttime = omp_get_wtime();
    }
#pragma omp for reduction(+ : sum)
    for (i = 0; i < n; i++) {
      x = d * (double)i;
      sum += f(x) + f(x + d);
    }
  }
  pi = d * sum * 0.5;
  stoptime = omp_get_wtime();
  printf("The computed value of Pi is %2.24f\n", pi);
  printf("The  \"exact\" value of Pi is %2.24f\n", PI24);
  printf("The difference is %e\n", fabs(PI24 - pi));
  printf("Time: %2.4f seconds \n", stoptime - starttime);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xe52(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x3e8,-0x54(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11dd <main+0x4d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <print_usage@plt>
jmp    126b <main+0xdb>
jmp    11e2 <main+0x52>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe40(%rip),%rdx
call   1080 <getopt@plt>
mov    %al,-0x59(%rbp)
movsbl %al,%eax
mov    0x2dde(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1266 <main+0xd6>
movsbl -0x59(%rbp),%eax
mov    %eax,-0x60(%rbp)
sub    $0x68,%eax
je     1233 <main+0xa3>
jmp    1222 <main+0x92>
mov    -0x60(%rbp),%eax
sub    $0x69,%eax
je     123f <main+0xaf>
jmp    1255 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <print_usage@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x54(%rbp)
jmp    1261 <main+0xd1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <print_usage@plt>
jmp    11e2 <main+0x52>
jmp    126b <main+0xdb>
cvtsi2sdl -0x54(%rbp),%xmm1
movsd  0xd90(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <omp_get_num_threads@plt>
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
lea    0xd93(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    131c <main+0x18c>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x58(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <f@plt>
mov    %rax,-0x68(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
call   1050 <f@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
add    %rcx,%rax
cvtsi2sd %rax,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    12b9 <main+0x129>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  0xce2(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xcfd(%rip),%rdi
call   1060 <printf@plt>
lea    0xd15(%rip),%rdi
movsd  0xc9d(%rip),%xmm0
call   1060 <printf@plt>
movsd  0xc90(%rip),%xmm0
subsd  -0x40(%rbp),%xmm0
movaps 0xca4(%rip),%xmm1
pand   %xmm1,%xmm0
lea    0xd0d(%rip),%rdi
call   1060 <printf@plt>
movsd  -0x50(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
lea    0xd0d(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jge    11b5 <main+0x25>
mov    (%r14),%rdi
call   10b0 <print_usage@plt>
mov    $0x3e8,%ebx
jmp    11dc <main+0x4c>
mov    %edi,%ebp
lea    0xe72(%rip),%rdx
mov    %r14,%rsi
call   1080 <getopt@plt>
mov    0x2e13(%rip),%r12
mov    $0x3e8,%ebx
cmp    (%r12),%al
jne    131f <main+0x18f>
cvtsi2sd %ebx,%xmm0
movsd  0xe18(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
xor    %eax,%eax
call   1070 <omp_get_num_threads@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xe27(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
test   %ebx,%ebx
jle    1297 <main+0x107>
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
nop
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rsp)
call   1050 <f@plt>
mov    %rax,%rbp
movsd  0x18(%rsp),%xmm0
addsd  (%rsp),%xmm0
call   1050 <f@plt>
add    %rbp,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x20(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
addsd  0xd6e(%rip),%xmm1
add    $0xffffffff,%ebx
jne    1230 <main+0xa0>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  0xd60(%rip),%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xd8b(%rip),%rdi
movsd  (%rsp),%xmm0
call   1060 <printf@plt>
lea    0xd9e(%rip),%rdi
movsd  0xd36(%rip),%xmm0
call   1060 <printf@plt>
movsd  0xd29(%rip),%xmm0
subsd  (%rsp),%xmm0
andpd  0xd2c(%rip),%xmm0
lea    0xd99(%rip),%rdi
call   1060 <printf@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
lea    0xd97(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    $0x3e8,%ebx
mov    0x2ccd(%rip),%r13
lea    0xcfe(%rip),%r15
jmp    136a <main+0x1da>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14),%rdi
call   10b0 <print_usage@plt>
mov    0x0(%r13),%edi
call   1090 <atoi@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
cmp    (%r12),%al
je     11dc <main+0x4c>
movsbl %al,%eax
cmp    $0x69,%eax
je     1348 <main+0x1b8>
cmp    $0x68,%eax
je     1340 <main+0x1b0>
mov    (%r14),%rdi
call   10b0 <print_usage@plt>
jmp    1353 <main+0x1c3>

LLVM IR (-O0):
@.str = [4 x i8] c"hi:\00"
@EOF = global i8 0
@optarg = global i32 0
@.str.1 = [24 x i8] c"Number of threads = %d\0A\00"
@.str.2 = [36 x i8] c"The computed value of Pi is %2.24f\0A\00"
@.str.3 = [36 x i8] c"The \22exact\22 value of Pi is %2.24f\0A\00"
@.str.4 = [22 x i8] c"The difference is %e\0A\00"
@.str.5 = [22 x i8] c"Time: %2.4f seconds \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0x400921FB54442D18, double* %6
store double 0.000000e+00, double* %11
store i32 1000, i32* %15
%18 = load i32, i32* %4
%19 = icmp sle i32 %18, 1
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 @print_usage(i8* %23)
br label %52
25: ; preds = %2
br label %26
26: ; preds = %50, %25
%27 = load i32, i32* %4
%28 = load i8**, i8*** %5
%29 = call signext i8 @getopt(i32 %27, i8** %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8 %29, i8* %17
%30 = sext i8 %29 to i32
%31 = load i8, i8* @EOF
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %51
34: ; preds = %26
%35 = load i8, i8* %17
%36 = sext i8 %35 to i32
switch i32 %36, label %45 [
i32 104, label %37
i32 105, label %42
]
37: ; preds = %34
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 @print_usage(i8* %40)
br label %42
42: ; preds = %34, %37
%43 = load i32, i32* @optarg
%44 = call i32 @atoi(i32 %43)
store i32 %44, i32* %15
br label %50
45: ; preds = %34
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 0
%48 = load i8*, i8** %47
%49 = call i32 @print_usage(i8* %48)
br label %50
50: ; preds = %45, %42
br label %26
51: ; preds = %26
br label %52
52: ; preds = %51, %20
%53 = load i32, i32* %15
%54 = sitofp i32 %53 to double
%55 = fdiv double 1.000000e+00, %54
store double %55, double* %9
%56 = call i32 (...) @omp_get_thread_num()
store i32 %56, i32* %8
%57 = call i32 (...) @omp_get_num_threads()
store i32 %57, i32* %7
%58 = load i32, i32* %7
%59 = sitofp i32 %58 to double
%60 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double %59)
%61 = call double (...) @omp_get_wtime()
store double %61, double* %13
store i32 0, i32* %16
br label %62
62: ; preds = %81, %52
%63 = load i32, i32* %16
%64 = load i32, i32* %15
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %84
66: ; preds = %62
%67 = load double, double* %9
%68 = load i32, i32* %16
%69 = sitofp i32 %68 to double
%70 = fmul double %67, %69
store double %70, double* %10
%71 = load double, double* %10
%72 = call i64 @f(double %71)
%73 = load double, double* %10
%74 = load double, double* %9
%75 = fadd double %73, %74
%76 = call i64 @f(double %75)
%77 = add nsw i64 %72, %76
%78 = sitofp i64 %77 to double
%79 = load double, double* %11
%80 = fadd double %79, %78
store double %80, double* %11
br label %81
81: ; preds = %66
%82 = load i32, i32* %16
%83 = add nsw i32 %82, 1
store i32 %83, i32* %16
br label %62
84: ; preds = %62
%85 = load double, double* %9
%86 = load double, double* %11
%87 = fmul double %85, %86
%88 = fmul double %87, 5.000000e-01
store double %88, double* %12
%89 = call double (...) @omp_get_wtime()
store double %89, double* %14
%90 = load double, double* %12
%91 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %90)
%92 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double 0x400921FB54442D18)
%93 = load double, double* %12
%94 = fsub double 0x400921FB54442D18, %93
%95 = call double @llvm.fabs.f64(double %94)
%96 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), double %95)
%97 = load double, double* %14
%98 = load double, double* %13
%99 = fsub double %97, %98
%100 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), double %99)
%101 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [4 x i8] c"hi:\00"
@EOF = global i8 0
@optarg = global i32 0
@.str.1 = [24 x i8] c"Number of threads = %d\0A\00"
@.str.2 = [36 x i8] c"The computed value of Pi is %2.24f\0A\00"
@.str.3 = [36 x i8] c"The \22exact\22 value of Pi is %2.24f\0A\00"
@.str.4 = [22 x i8] c"The difference is %e\0A\00"
@.str.5 = [22 x i8] c"Time: %2.4f seconds \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
br i1 %7, label %29, label %11
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @print_usage(i8* %9)
br label %29
11: ; preds = %4, %24
%12 = phi i8 [ %26, %24 ], [ %5, %4 ]
%13 = phi i32 [ %25, %24 ], [ 1000, %4 ]
%14 = sext i8 %12 to i32
switch i32 %14, label %21 [
i32 104, label %15
i32 105, label %18
]
15: ; preds = %11
%16 = load i8*, i8** %1
%17 = tail call i32 @print_usage(i8* %16)
br label %18
18: ; preds = %11, %15
%19 = load i32, i32* @optarg
%20 = tail call i32 @atoi(i32 %19)
br label %24
21: ; preds = %11
%22 = load i8*, i8** %1
%23 = tail call i32 @print_usage(i8* %22)
br label %24
24: ; preds = %21, %18
%25 = phi i32 [ %13, %21 ], [ %20, %18 ]
%26 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%27 = load i8, i8* @EOF
%28 = icmp eq i8 %26, %27
br i1 %28, label %29, label %11
29: ; preds = %24, %4, %8
%30 = phi i32 [ 1000, %8 ], [ 1000, %4 ], [ %25, %24 ]
%31 = sitofp i32 %30 to double
%32 = fdiv double 1.000000e+00, %31
%33 = tail call i32 (...) @omp_get_thread_num()
%34 = tail call i32 (...) @omp_get_num_threads()
%35 = sitofp i32 %34 to double
%36 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double %35)
%37 = tail call double (...) @omp_get_wtime()
%38 = icmp sgt i32 %30, 0
br i1 %38, label %39, label %52
39: ; preds = %29, %39
%40 = phi double [ %49, %39 ], [ 0.000000e+00, %29 ]
%41 = phi i32 [ %50, %39 ], [ 0, %29 ]
%42 = sitofp i32 %41 to double
%43 = fmul double %32, %42
%44 = tail call i64 @f(double %43)
%45 = fadd double %32, %43
%46 = tail call i64 @f(double %45)
%47 = add nsw i64 %46, %44
%48 = sitofp i64 %47 to double
%49 = fadd double %40, %48
%50 = add nuw nsw i32 %41, 1
%51 = icmp eq i32 %50, %30
br i1 %51, label %52, label %39
52: ; preds = %39, %29
%53 = phi double [ 0.000000e+00, %29 ], [ %49, %39 ]
%54 = fmul double %32, %53
%55 = fmul double %54, 5.000000e-01
%56 = tail call double (...) @omp_get_wtime()
%57 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %55)
%58 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double 0x400921FB54442D18)
%59 = fsub double 0x400921FB54442D18, %55
%60 = tail call double @llvm.fabs.f64(double %59)
%61 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), double %60)
%62 = fsub double %56, %37
%63 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), double %62)
%64 = tail call i32 @exit(i32 0)
unreachable
}