#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*/ EXIT_FAILURE;
long long atoll(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
double integrate_pi(long long);
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, double, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *awnser[] = {"bad", "ok"};
  double pi;
  long long int n;
  double elapsed, start, end;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <number of rectangles>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  n = atoll(argv[1]);
  printf("number of rectangles: %lld\n", n);
  start = omp_get_wtime();
  pi = integrate_pi(n);
  end = omp_get_wtime();
  elapsed = end - start;
  printf("pi value is %lf\ntime: %.3f seconds\n", pi, elapsed);
  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)
mov    0x2c83(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c80(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c0 <main+0x60>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5a(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoll@plt>
mov    %rax,-0x30(%rbp)
cvtsi2sdq -0x30(%rbp),%xmm0
lea    0xe4b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <integrate_pi@plt>
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xe1a(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11cf <main+0x6f>
mov    0x8(%rsi),%rdi
call   1060 <atoll@plt>
mov    %rax,%rbx
cvtsi2sd %rax,%xmm0
lea    0xea0(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <integrate_pi@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
lea    0xe83(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe1e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"bad\00"
@.str.1 = [3 x i8] c"ok\00"
@__const.main.awnser = [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0)]
@stderr = global i32 0
@.str.2 = [34 x i8] c"Usage: %s <number of rectangles>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [28 x i8] c"number of rectangles: %lld\0A\00"
@.str.4 = [36 x i8] c"pi value is %lf\0Atime: %.3f seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i8*]
%7 = alloca double
%8 = alloca i64
%9 = alloca double
%10 = alloca double
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [2 x i8*]* %6 to i8*
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @atoll(i8* %26)
store i64 %27, i64* %8
%28 = load i64, i64* %8
%29 = sitofp i64 %28 to double
%30 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), double %29)
%31 = call double (...) @omp_get_wtime()
store double %31, double* %10
%32 = load i64, i64* %8
%33 = call double @integrate_pi(i64 %32)
store double %33, double* %7
%34 = call double (...) @omp_get_wtime()
store double %34, double* %11
%35 = load double, double* %11
%36 = load double, double* %10
%37 = fsub double %35, %36
store double %37, double* %9
%38 = load double, double* %7
%39 = load double, double* %9
%40 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %38, double %39)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.2 = [34 x i8] c"Usage: %s <number of rectangles>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [28 x i8] c"number of rectangles: %lld\0A\00"
@.str.4 = [36 x i8] c"pi value is %lf\0Atime: %.3f seconds\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @atoll(i8* %12)
%14 = sitofp i64 %13 to double
%15 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), double %14)
%16 = tail call double (...) @omp_get_wtime()
%17 = tail call double @integrate_pi(i64 %13)
%18 = tail call double (...) @omp_get_wtime()
%19 = fsub double %18, %16
%20 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %17, double %19)
ret i32 0
}