#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 timespec {
  double tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int atoi(char *);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
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;
  struct timespec cgt1, cgt2;
  double ncgt;
  if (argc < 2) {
    fprintf(stderr, "\nFalta nº intervalos\n");
    exit(-1);
  }
  intervals = atoi(argv[1]);
  if (intervals < 1)
    intervals = 1;
  clock_gettime(CLOCK_REALTIME, &cgt1);
  width = 1.0 / intervals;
  for (i = 0; i < intervals; i++) {
    x = (i + 0.5) * width;
    sum += 4.0 / (1.0 + x * x);
  }
  sum *= width;
  clock_gettime(CLOCK_REALTIME, &cgt2);
  ncgt = (double)(cgt2.tv_sec - cgt1.tv_sec) +
         (double)((cgt2.tv_nsec - cgt1.tv_nsec) / (1.e+9));
  printf("Iteraciones: %d.\t Pi: %26.24f.\t Threads: %d.\t Tiempo:\t%8.6f\n",
         intervals, sum, 1, ncgt);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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    0xe98(%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    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1030 <clock_gettime@plt>
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xe29(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    124c <main+0xfc>
cvtsi2sdl -0x30(%rbp),%xmm0
movsd  0xe18(%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  0xddc(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xde0(%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    11e7 <main+0x97>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x48(%rbp),%rax
sub    -0x38(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  -0x50(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
movsd  0xd7c(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x2c(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
lea    0xd8a(%rip),%rdi
mov    $0x1,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
cmp    $0x1,%edi
jle    12db <main+0x18b>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
mov    $0x1,%ebx
cmovg  %eax,%ebx
mov    0x2e5b(%rip),%r14
mov    (%r14),%edi
lea    0x20(%rsp),%rsi
call   1030 <clock_gettime@plt>
cvtsi2sd %ebx,%xmm0
movsd  0xe6a(%rip),%xmm4
movapd %xmm4,%xmm1
divsd  %xmm0,%xmm1
cmp    $0x2,%ebp
jge    11bd <main+0x6d>
movsd  0xe5d(%rip),%xmm3
xorpd  %xmm0,%xmm0
test   $0x1,%bl
jne    1256 <main+0x106>
jmp    1276 <main+0x126>
mov    %ebx,%eax
and    $0x7ffffffe,%eax
xor    %ecx,%ecx
xorpd  %xmm0,%xmm0
movsd  0xe36(%rip),%xmm2
movsd  0xe36(%rip),%xmm3
movsd  0xe35(%rip),%xmm8
xorpd  %xmm5,%xmm5
nopw   0x0(%rax,%rax,1)
movapd %xmm5,%xmm6
addsd  %xmm2,%xmm6
mulsd  %xmm1,%xmm6
mulsd  %xmm6,%xmm6
addsd  %xmm4,%xmm6
movapd %xmm3,%xmm7
divsd  %xmm6,%xmm7
addsd  %xmm0,%xmm7
lea    0x1(%rcx),%edx
xorps  %xmm6,%xmm6
cvtsi2sd %edx,%xmm6
addsd  %xmm2,%xmm6
mulsd  %xmm1,%xmm6
mulsd  %xmm6,%xmm6
addsd  %xmm4,%xmm6
movapd %xmm3,%xmm0
divsd  %xmm6,%xmm0
addsd  %xmm7,%xmm0
addsd  %xmm8,%xmm5
add    $0x2,%ecx
cmp    %ecx,%eax
jne    11f0 <main+0xa0>
xorps  %xmm3,%xmm3
cvtsi2sd %ecx,%xmm3
addsd  0xdb7(%rip),%xmm3
test   $0x1,%bl
je     1276 <main+0x126>
mulsd  %xmm1,%xmm3
mulsd  %xmm3,%xmm3
addsd  0xd9a(%rip),%xmm3
movsd  0xda2(%rip),%xmm2
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    (%r14),%edi
lea    0x10(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    0x18(%rsp),%rax
sub    0x28(%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x10(%rsp),%xmm1
subsd  0x20(%rsp),%xmm1
divsd  0xd6d(%rip),%xmm1
addsd  %xmm0,%xmm1
lea    0xd81(%rip),%rdi
mov    %ebx,%esi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
%struct.timespec = type { double, i64 }
@stderr = global i32 0
@.str = [23 x i8] c"\0AFalta n\C2\BA intervalos\0A\00"
@CLOCK_REALTIME = global i32 0
@.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 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %3 to i8*
%6 = bitcast %struct.timespec* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = icmp sgt i32 %15, 1
%17 = select i1 %16, i32 %15, i32 1
%18 = load i32, i32* @CLOCK_REALTIME
%19 = call i32 @clock_gettime(i32 %18, %struct.timespec* %3)
%20 = sitofp i32 %17 to double
%21 = fdiv double 1.000000e+00, %20
%22 = and i32 %17, 1
%23 = icmp slt i32 %15, 2
br i1 %23, label %49, label %24
24: ; preds = %12
%25 = and i32 %17, 2147483646
br label %26
26: ; preds = %26, %24
%27 = phi double [ 0.000000e+00, %24 ], [ %42, %26 ]
%28 = phi i32 [ 0, %24 ], [ %43, %26 ]
%29 = phi i32 [ 0, %24 ], [ %44, %26 ]
%30 = sitofp i32 %28 to double
%31 = fadd double %30, 5.000000e-01
%32 = fmul double %21, %31
%33 = call double @llvm.fmuladd.f64(double %32, double %32, double 1.000000e+00)
%34 = fdiv double 4.000000e+00, %33
%35 = fadd double %27, %34
%36 = or i32 %28, 1
%37 = sitofp i32 %36 to double
%38 = fadd double %37, 5.000000e-01
%39 = fmul double %21, %38
%40 = call double @llvm.fmuladd.f64(double %39, double %39, double 1.000000e+00)
%41 = fdiv double 4.000000e+00, %40
%42 = fadd double %35, %41
%43 = add nuw nsw i32 %28, 2
%44 = add i32 %29, 2
%45 = icmp eq i32 %44, %25
br i1 %45, label %46, label %26
46: ; preds = %26
%47 = sitofp i32 %43 to double
%48 = fadd double %47, 5.000000e-01
br label %49
49: ; preds = %46, %12
%50 = phi double [ undef, %12 ], [ %42, %46 ]
%51 = phi double [ 0.000000e+00, %12 ], [ %42, %46 ]
%52 = phi double [ 5.000000e-01, %12 ], [ %48, %46 ]
%53 = icmp eq i32 %22, 0
br i1 %53, label %59, label %54
54: ; preds = %49
%55 = fmul double %21, %52
%56 = call double @llvm.fmuladd.f64(double %55, double %55, double 1.000000e+00)
%57 = fdiv double 4.000000e+00, %56
%58 = fadd double %51, %57
br label %59
59: ; preds = %49, %54
%60 = phi double [ %50, %49 ], [ %58, %54 ]
%61 = fmul double %21, %60
%62 = load i32, i32* @CLOCK_REALTIME
%63 = call i32 @clock_gettime(i32 %62, %struct.timespec* %4)
%64 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%65 = load i64, i64* %64
%66 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%67 = load i64, i64* %66
%68 = sub nsw i64 %65, %67
%69 = sitofp i64 %68 to double
%70 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%71 = load double, double* %70
%72 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%73 = load double, double* %72
%74 = fsub double %71, %73
%75 = fdiv double %74, 1.000000e+09
%76 = fadd double %75, %69
%77 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i32 %17, double %61, i32 1, double %76)
ret i32 0
}