#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 */
int /*<<< orphan*/ Usage(char *);
int /*<<< orphan*/ printf(char *, double, ...);
int strtol(char *, int /*<<< orphan*/ *, int);
long long strtoll(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  long long n, i;
  int thread_count;
  double factor;
  double sum = 0.0;
  if (argc != 3)
    Usage(argv[0]);
  thread_count = strtol(argv[1], NULL, 10);
  n = strtoll(argv[2], NULL, 10);
  if (thread_count < 1 || n < 1)
    Usage(argv[0]);
#pragma omp parallel for num_threads(thread_count) reduction(+: sum) private(factor)
  for (i = 0; i < n; i++) {
    factor = (i % 2 == 0) ? 1.0 : -1.0;
    sum += factor / (2 * i + 1);
  }
  sum = 4.0 * sum;
  printf("With n = %lld terms and %d threads", n, thread_count);
  printf(" - Our estimate of pi = %.14f\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1174 <main+0x34>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <Usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoll@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x24(%rbp)
jl     11bc <main+0x7c>
cmpq   $0x1,-0x18(%rbp)
jge    11c8 <main+0x88>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <Usage@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1259 <main+0x119>
mov    -0x20(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
movsd  0xe14(%rip),%xmm0
movsd  0xe14(%rip),%xmm1
movsd  %xmm1,-0x48(%rbp)
cmp    $0x0,%rdx
movsd  %xmm0,-0x40(%rbp)
je     121a <main+0xda>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11d0 <main+0x90>
movsd  0xd9f(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
mov    -0x24(%rbp),%esi
lea    0xd9d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x38(%rbp),%xmm0
lea    0xdad(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
cmp    $0x3,%edi
je     1159 <main+0x19>
mov    0x0(%rbp),%rdi
call   1040 <Usage@plt>
mov    0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%r14d
mov    0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoll@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    1189 <main+0x49>
test   %rbx,%rbx
jg     119b <main+0x5b>
mov    0x0(%rbp),%rdi
call   1040 <Usage@plt>
test   %rbx,%rbx
jle    1248 <main+0x108>
cmp    $0x1,%rbx
jne    11a9 <main+0x69>
xorpd  %xmm4,%xmm4
xor    %eax,%eax
jmp    1209 <main+0xc9>
mov    %rbx,%rcx
and    $0xfffffffffffffffe,%rcx
xorpd  %xmm4,%xmm4
mov    $0x3,%edx
xor    %eax,%eax
movsd  0xe3d(%rip),%xmm0
movsd  0xe3d(%rip),%xmm1
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rdx),%rsi
xorps  %xmm2,%xmm2
cvtsi2sd %rsi,%xmm2
movapd %xmm0,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm4,%xmm3
xorps  %xmm2,%xmm2
cvtsi2sd %rdx,%xmm2
movapd %xmm1,%xmm4
divsd  %xmm2,%xmm4
addsd  %xmm3,%xmm4
add    $0x2,%rax
add    $0x4,%rdx
cmp    %rax,%rcx
jne    11d0 <main+0x90>
test   $0x1,%bl
je     1238 <main+0xf8>
xor    %ecx,%ecx
test   $0x1,%al
sete   %cl
lea    0xdfc(%rip),%rdx
movsd  (%rdx,%rcx,8),%xmm0
add    %rax,%rax
add    $0x1,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
addsd  %xmm0,%xmm4
mulsd  0xdd0(%rip),%xmm4
movsd  %xmm4,0x8(%rsp)
jmp    1252 <main+0x112>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
lea    0xdc7(%rip),%rdi
mov    %r14d,%esi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xdd9(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"With n = %lld terms and %d threads\00"
@.str.1 = [31 x i8] c" - Our estimate of pi = %.14f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %10
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @Usage(i8* %16)
br label %18
18: ; preds = %13, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strtol(i8* %21, i32* null, i32 10)
store i32 %22, i32* %8
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i64 @strtoll(i8* %25, i32* null, i32 10)
store i64 %26, i64* %6
%27 = load i32, i32* %8
%28 = icmp slt i32 %27, 1
br i1 %28, label %32, label %29
29: ; preds = %18
%30 = load i64, i64* %6
%31 = icmp slt i64 %30, 1
br i1 %31, label %32, label %37
32: ; preds = %29, %18
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @Usage(i8* %35)
br label %37
37: ; preds = %32, %29
store i64 0, i64* %7
br label %38
38: ; preds = %56, %37
%39 = load i64, i64* %7
%40 = load i64, i64* %6
%41 = icmp slt i64 %39, %40
br i1 %41, label %42, label %59
42: ; preds = %38
%43 = load i64, i64* %7
%44 = srem i64 %43, 2
%45 = icmp eq i64 %44, 0
%46 = zext i1 %45 to i64
%47 = select i1 %45, double 1.000000e+00, double -1.000000e+00
store double %47, double* %9
%48 = load double, double* %9
%49 = load i64, i64* %7
%50 = mul nsw i64 2, %49
%51 = add nsw i64 %50, 1
%52 = sitofp i64 %51 to double
%53 = fdiv double %48, %52
%54 = load double, double* %10
%55 = fadd double %54, %53
store double %55, double* %10
br label %56
56: ; preds = %42
%57 = load i64, i64* %7
%58 = add nsw i64 %57, 1
store i64 %58, i64* %7
br label %38
59: ; preds = %38
%60 = load double, double* %10
%61 = fmul double 4.000000e+00, %60
store double %61, double* %10
%62 = load i64, i64* %6
%63 = sitofp i64 %62 to double
%64 = load i32, i32* %8
%65 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), double %63, i32 %64)
%66 = load double, double* %10
%67 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), double %66)
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"With n = %lld terms and %d threads\00"
@.str.1 = [31 x i8] c" - Our estimate of pi = %.14f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @Usage(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strtol(i8* nocapture %9, i32* null, i32 10)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i64 @strtoll(i8* nocapture %12, i32* null, i32 10)
%14 = icmp slt i32 %10, 1
%15 = icmp slt i64 %13, 1
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %17, label %21
17: ; preds = %7
%18 = load i8*, i8** %1
%19 = tail call i32 @Usage(i8* %18)
%20 = icmp sgt i64 %13, 0
br i1 %20, label %21, label %60
21: ; preds = %7, %17
%22 = and i64 %13, 1
%23 = icmp eq i64 %13, 1
br i1 %23, label %43, label %24
24: ; preds = %21
%25 = and i64 %13, -2
br label %26
26: ; preds = %26, %24
%27 = phi double [ 0.000000e+00, %24 ], [ %39, %26 ]
%28 = phi i64 [ 0, %24 ], [ %40, %26 ]
%29 = phi i64 [ 0, %24 ], [ %41, %26 ]
%30 = shl nuw nsw i64 %28, 1
%31 = or i64 %30, 1
%32 = sitofp i64 %31 to double
%33 = fdiv double 1.000000e+00, %32
%34 = fadd double %27, %33
%35 = shl nuw i64 %28, 1
%36 = or i64 %35, 3
%37 = sitofp i64 %36 to double
%38 = fdiv double -1.000000e+00, %37
%39 = fadd double %34, %38
%40 = add nuw nsw i64 %28, 2
%41 = add i64 %29, 2
%42 = icmp eq i64 %41, %25
br i1 %42, label %43, label %26
43: ; preds = %26, %21
%44 = phi double [ undef, %21 ], [ %39, %26 ]
%45 = phi double [ 0.000000e+00, %21 ], [ %39, %26 ]
%46 = phi i64 [ 0, %21 ], [ %40, %26 ]
%47 = icmp eq i64 %22, 0
br i1 %47, label %57, label %48
48: ; preds = %43
%49 = and i64 %46, 1
%50 = icmp eq i64 %49, 0
%51 = select i1 %50, double 1.000000e+00, double -1.000000e+00
%52 = shl nuw nsw i64 %46, 1
%53 = or i64 %52, 1
%54 = sitofp i64 %53 to double
%55 = fdiv double %51, %54
%56 = fadd double %45, %55
br label %57
57: ; preds = %43, %48
%58 = phi double [ %44, %43 ], [ %56, %48 ]
%59 = fmul double %58, 4.000000e+00
br label %60
60: ; preds = %57, %17
%61 = phi double [ 0.000000e+00, %17 ], [ %59, %57 ]
%62 = sitofp i64 %13 to double
%63 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), double %62, i32 %10)
%64 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), double %61)
ret i32 0
}