#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, int, double, int, double);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  register double width, x;
  double sum = 0;
  register int intervals, i;
  double t;
  if (argc < 2) {
    fprintf(stderr, "\nFalta nº intervalos\n");
    exit(-1);
  }
  intervals = atoi(argv[1]);
  if (intervals < 1)
    intervals = 1;
  t = omp_get_wtime();
  width = 1.0 / intervals;
#pragma omp parallel
  {
#pragma omp for reduction(+ : sum) private(x)
    for (i = 0; i < intervals; i++) {
      x = (i + 0.5) * width;
      sum += 4.0 / (1.0 + x * x);
    }
  }
  sum *= width;
  t = omp_get_wtime() - t;
  printf("Iteraciones: %d.\t Pi: %26.24f.\t Threads: %d.\t Tiempo:\t%8.6f\n",
         intervals, sum, 1, t);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1197 <main+0x47>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jge    11b8 <main+0x68>
movl   $0x1,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xe2f(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1246 <main+0xf6>
cvtsi2sdl -0x30(%rbp),%xmm0
movsd  0xe16(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xde2(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xdde(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11e1 <main+0x91>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x2c(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xdb5(%rip),%rdi
mov    $0x1,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jle    12b5 <main+0x165>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
mov    $0x1,%r14d
cmovg  %eax,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
cvtsi2sd %r14d,%xmm2
movsd  0xe72(%rip),%xmm5
movapd %xmm5,%xmm1
divsd  %xmm2,%xmm1
cmp    $0x2,%ebp
movsd  %xmm0,0x8(%rsp)
jge    11bc <main+0x6c>
xorpd  %xmm0,%xmm0
movsd  0xe5b(%rip),%xmm3
test   $0x1,%r14b
jne    1257 <main+0x107>
jmp    1277 <main+0x127>
mov    %r14d,%eax
and    $0x7ffffffe,%eax
xorpd  %xmm2,%xmm2
movsd  0xe38(%rip),%xmm3
movsd  0xe38(%rip),%xmm4
movsd  0xe37(%rip),%xmm8
xorpd  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nop
movapd %xmm2,%xmm6
addsd  %xmm3,%xmm6
mulsd  %xmm1,%xmm6
mulsd  %xmm6,%xmm6
addsd  %xmm5,%xmm6
movapd %xmm4,%xmm7
divsd  %xmm6,%xmm7
addsd  %xmm0,%xmm7
lea    0x1(%rbx),%ecx
xorps  %xmm6,%xmm6
cvtsi2sd %ecx,%xmm6
addsd  %xmm3,%xmm6
mulsd  %xmm1,%xmm6
mulsd  %xmm6,%xmm6
addsd  %xmm5,%xmm6
movapd %xmm4,%xmm0
divsd  %xmm6,%xmm0
addsd  %xmm7,%xmm0
addsd  %xmm8,%xmm2
add    $0x2,%ebx
cmp    %ebx,%eax
jne    11f0 <main+0xa0>
xorps  %xmm3,%xmm3
cvtsi2sd %ebx,%xmm3
addsd  0xdb7(%rip),%xmm3
test   $0x1,%r14b
je     1277 <main+0x127>
mulsd  %xmm1,%xmm3
mulsd  %xmm3,%xmm3
addsd  0xd99(%rip),%xmm3
movsd  0xda1(%rip),%xmm2
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
lea    0xd9f(%rip),%rdi
mov    %r14d,%esi
movsd  (%rsp),%xmm0
mov    $0x1,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
lea    0xd5b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"\0AFalta n\C2\BA intervalos\0A\00"
@.str.1 = [61 x i8] c"Iteraciones: %d.\09 Pi: %26.24f.\09 Threads: %d.\09 Tiempo:\09%8.6f\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 double
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %8
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 1, i32* %9
br label %26
26: ; preds = %25, %18
%27 = call double (...) @omp_get_wtime()
store double %27, double* %11
%28 = load i32, i32* %9
%29 = sitofp i32 %28 to double
%30 = fdiv double 1.000000e+00, %29
store double %30, double* %6
store i32 0, i32* %10
br label %31
31: ; preds = %47, %26
%32 = load i32, i32* %10
%33 = load i32, i32* %9
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i32, i32* %10
%37 = sitofp i32 %36 to double
%38 = fadd double %37, 5.000000e-01
%39 = load double, double* %6
%40 = fmul double %38, %39
store double %40, double* %7
%41 = load double, double* %7
%42 = load double, double* %7
%43 = call double @llvm.fmuladd.f64(double %41, double %42, double 1.000000e+00)
%44 = fdiv double 4.000000e+00, %43
%45 = load double, double* %8
%46 = fadd double %45, %44
store double %46, double* %8
br label %47
47: ; preds = %35
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
br label %31
50: ; preds = %31
%51 = load double, double* %6
%52 = load double, double* %8
%53 = fmul double %52, %51
store double %53, double* %8
%54 = call double (...) @omp_get_wtime()
%55 = load double, double* %11
%56 = fsub double %54, %55
store double %56, double* %11
%57 = load i32, i32* %9
%58 = load double, double* %8
%59 = load double, double* %11
%60 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i32 %57, double %58, i32 1, double %59)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"\0AFalta n\C2\BA intervalos\0A\00"
@.str.1 = [61 x i8] c"Iteraciones: %d.\09 Pi: %26.24f.\09 Threads: %d.\09 Tiempo:\09%8.6f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp sgt i32 %11, 1
%13 = select i1 %12, i32 %11, i32 1
%14 = tail call double (...) @omp_get_wtime()
%15 = sitofp i32 %13 to double
%16 = fdiv double 1.000000e+00, %15
%17 = and i32 %13, 1
%18 = icmp slt i32 %11, 2
br i1 %18, label %44, label %19
19: ; preds = %8
%20 = and i32 %13, 2147483646
br label %21
21: ; preds = %21, %19
%22 = phi i32 [ 0, %19 ], [ %38, %21 ]
%23 = phi double [ 0.000000e+00, %19 ], [ %37, %21 ]
%24 = phi i32 [ 0, %19 ], [ %39, %21 ]
%25 = sitofp i32 %22 to double
%26 = fadd double %25, 5.000000e-01
%27 = fmul double %16, %26
%28 = tail call double @llvm.fmuladd.f64(double %27, double %27, double 1.000000e+00)
%29 = fdiv double 4.000000e+00, %28
%30 = fadd double %23, %29
%31 = or i32 %22, 1
%32 = sitofp i32 %31 to double
%33 = fadd double %32, 5.000000e-01
%34 = fmul double %16, %33
%35 = tail call double @llvm.fmuladd.f64(double %34, double %34, double 1.000000e+00)
%36 = fdiv double 4.000000e+00, %35
%37 = fadd double %30, %36
%38 = add nuw nsw i32 %22, 2
%39 = add i32 %24, 2
%40 = icmp eq i32 %39, %20
br i1 %40, label %41, label %21
41: ; preds = %21
%42 = sitofp i32 %38 to double
%43 = fadd double %42, 5.000000e-01
br label %44
44: ; preds = %41, %8
%45 = phi double [ undef, %8 ], [ %37, %41 ]
%46 = phi double [ 5.000000e-01, %8 ], [ %43, %41 ]
%47 = phi double [ 0.000000e+00, %8 ], [ %37, %41 ]
%48 = icmp eq i32 %17, 0
br i1 %48, label %54, label %49
49: ; preds = %44
%50 = fmul double %16, %46
%51 = tail call double @llvm.fmuladd.f64(double %50, double %50, double 1.000000e+00)
%52 = fdiv double 4.000000e+00, %51
%53 = fadd double %47, %52
br label %54
54: ; preds = %44, %49
%55 = phi double [ %45, %44 ], [ %53, %49 ]
%56 = fmul double %16, %55
%57 = tail call double (...) @omp_get_wtime()
%58 = fsub double %57, %14
%59 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i32 %13, double %56, i32 1, double %58)
ret i32 0
}