#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 */
scalar_t__ WIFEXITED(int);
unsigned long long atol(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, long double *, int);
int /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ write(int, long double *, int);
int main(int argc, char *argv[]) {
  long double pi = 0.0, i = 0.0, temp;
  unsigned long long int pres = 0, den = 0;
  int pid, status, com[2];
  pipe(com);
  if (argc == 1)
    pres = 5000;
  else
    pres = atol(argv[1]);
  pid = fork();
  if (pid < 0)
    perror("Error!: ");
  else if (pid == 0) {
    for (i = 0.0, den = 1; i <= pres; i += 0.0001, den += 4) {
      pi += 1 / (long double)den;
    }
    close(com[0]);
    write(com[1], &pi, sizeof(long double));
    exit(1);
  } else {
    for (i = 0.0, den = 3; i <= pres; i += 0.0001, den += 4) {
      pi -= 1 / (long double)den;
    }
    wait(&status);
    if (WIFEXITED(status) != 0) {
      close(com[1]);
      read(com[0], &temp, sizeof(long double));
      pi = pi + temp;
    } else
      printf("Error!: El proceso hijo ha finalizado inesperadamenten");
  }
  pi = pi * 4;
  printf("Pi es aprox. : %.25Lgn", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
fldz
fld    %st(0)
fstpt  -0x20(%rbp)
fstpt  -0x30(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
lea    -0x60(%rbp),%rdi
call   1060 <pipe@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1203 <main+0x53>
movq   $0x1388,-0x48(%rbp)
jmp    1214 <main+0x64>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atol@plt>
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    1239 <main+0x89>
lea    0xde5(%rip),%rdi
call   1090 <perror@plt>
jmp    13e0 <main+0x230>
cmpl   $0x0,-0x54(%rbp)
jne    12f4 <main+0x144>
fldz
fstpt  -0x30(%rbp)
movq   $0x1,-0x50(%rbp)
fldt   -0x30(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x78(%rbp)
test   %rax,%rax
sets   %al
movzbl %al,%eax
mov    %eax,%ecx
fildll -0x78(%rbp)
lea    0xd90(%rip),%rax
flds   (%rax,%rcx,4)
faddp  %st,%st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     12d1 <main+0x121>
jmp    1284 <main+0xd4>
mov    -0x50(%rbp),%rax
mov    %rax,-0x80(%rbp)
test   %rax,%rax
sets   %al
movzbl %al,%eax
mov    %eax,%ecx
fildll -0x80(%rbp)
lea    0xd5f(%rip),%rax
flds   (%rax,%rcx,4)
faddp  %st,%st(1)
fld1
fdivp  %st,%st(1)
fldt   -0x20(%rbp)
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
fldt   -0x30(%rbp)
fldl   0xd4d(%rip)
faddp  %st,%st(1)
fstpt  -0x30(%rbp)
mov    -0x50(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x50(%rbp)
jmp    1250 <main+0xa0>
mov    -0x60(%rbp),%edi
call   1050 <close@plt>
mov    -0x5c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
fldz
fstpt  -0x30(%rbp)
movq   $0x3,-0x50(%rbp)
fldt   -0x30(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x68(%rbp)
test   %rax,%rax
sets   %al
movzbl %al,%eax
mov    %eax,%ecx
fildll -0x68(%rbp)
lea    0xcdf(%rip),%rax
flds   (%rax,%rcx,4)
faddp  %st,%st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     1384 <main+0x1d4>
jmp    1335 <main+0x185>
mov    -0x50(%rbp),%rax
mov    %rax,-0x70(%rbp)
test   %rax,%rax
sets   %al
movzbl %al,%eax
mov    %eax,%ecx
fildll -0x70(%rbp)
lea    0xcae(%rip),%rax
flds   (%rax,%rcx,4)
faddp  %st,%st(1)
fld1
fchs
fdivp  %st,%st(1)
fldt   -0x20(%rbp)
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
fldt   -0x30(%rbp)
fldl   0xc9a(%rip)
faddp  %st,%st(1)
fstpt  -0x30(%rbp)
mov    -0x50(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x50(%rbp)
jmp    1301 <main+0x151>
lea    -0x58(%rbp),%rdi
call   10c0 <wait@plt>
mov    -0x58(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     13c8 <main+0x218>
mov    -0x5c(%rbp),%edi
call   1050 <close@plt>
mov    -0x60(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1070 <read@plt>
fldt   -0x20(%rbp)
fldt   -0x40(%rbp)
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
jmp    13d6 <main+0x226>
lea    0xc4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13db <main+0x22b>
jmp    13e0 <main+0x230>
fldt   -0x20(%rbp)
flds   0xc27(%rip)
fmulp  %st,%st(1)
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xc57(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x18(%rsp),%rdi
call   1060 <pipe@plt>
flds   0xe35(%rip)
cmp    $0x1,%ebp
je     11f6 <main+0x46>
fstp   %st(0)
mov    0x8(%rbx),%rdi
call   1080 <atol@plt>
mov    %rax,0x50(%rsp)
xor    %ecx,%ecx
test   %rax,%rax
sets   %cl
fildll 0x50(%rsp)
lea    0xe15(%rip),%rax
fadds  (%rax,%rcx,4)
fstpt  0x20(%rsp)
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
js     12d6 <main+0x126>
je     12e6 <main+0x136>
mov    $0x3,%eax
fldz
lea    0xdeb(%rip),%rcx
fld1
fchs
fld    %st(1)
fldt   0x20(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %rax,0x48(%rsp)
xor    %edx,%edx
test   %rax,%rax
sets   %dl
fildll 0x48(%rsp)
fadds  (%rcx,%rdx,4)
fdivr  %st(3),%st
faddp  %st,%st(2)
fxch   %st(3)
faddl  0xdc0(%rip)
add    $0x4,%rax
fxch   %st(3)
fucomi %st(3),%st
jae    1230 <main+0x80>
fstp   %st(3)
fstp   %st(1)
fstp   %st(1)
fstpt  0x20(%rsp)
lea    0x2c(%rsp),%rdi
call   10c0 <wait@plt>
mov    0x2c(%rsp),%edi
call   10a0 <WIFEXITED@plt>
test   %rax,%rax
je     12a4 <main+0xf4>
mov    0x1c(%rsp),%edi
call   1050 <close@plt>
mov    0x18(%rsp),%edi
lea    0x30(%rsp),%rsi
mov    $0x10,%edx
call   1070 <read@plt>
fldt   0x30(%rsp)
fldt   0x20(%rsp)
faddp  %st,%st(1)
jmp    12b6 <main+0x106>
lea    0xd76(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
fldt   0x20(%rsp)
fmuls  0xd48(%rip)
fstpt  (%rsp)
lea    0xd92(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd3b(%rip),%rdi
call   1090 <perror@plt>
fldz
jmp    12b6 <main+0x106>
mov    $0x1,%eax
fldz
lea    0xd14(%rip),%rcx
fld1
fld    %st(1)
fldt   0x20(%rsp)
nopl   0x0(%rax)
mov    %rax,0x40(%rsp)
xor    %edx,%edx
test   %rax,%rax
sets   %dl
fildll 0x40(%rsp)
fadds  (%rcx,%rdx,4)
fdivr  %st(3),%st
faddp  %st,%st(2)
fxch   %st(3)
faddl  0xcf0(%rip)
add    $0x4,%rax
fxch   %st(3)
fucomi %st(3),%st
jae    1300 <main+0x150>
fstp   %st(3)
fstp   %st(1)
fstp   %st(1)
fstpt  0x30(%rsp)
mov    0x18(%rsp),%edi
call   1050 <close@plt>
mov    0x1c(%rsp),%edi
lea    0x30(%rsp),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"Error!: \00"
@.str.1 = [55 x i8] c"Error!: El proceso hijo ha finalizado inesperadamenten\00"
@.str.2 = [23 x i8] c"Pi es aprox. : %.25Lgn\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca x86_fp80
%7 = alloca x86_fp80
%8 = alloca x86_fp80
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store x86_fp80 0xK00000000000000000000, x86_fp80* %6
store x86_fp80 0xK00000000000000000000, x86_fp80* %7
store i64 0, i64* %9
store i64 0, i64* %10
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%15 = call i32 @pipe(i32* %14)
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %2
store i64 5000, i64* %9
br label %24
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @atol(i8* %22)
store i64 %23, i64* %9
br label %24
24: ; preds = %19, %18
%25 = call i32 (...) @fork()
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %94
30: ; preds = %24
%31 = load i32, i32* %11
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %58
33: ; preds = %30
store x86_fp80 0xK00000000000000000000, x86_fp80* %7
store i64 1, i64* %10
br label %34
34: ; preds = %45, %33
%35 = load x86_fp80, x86_fp80* %7
%36 = load i64, i64* %9
%37 = uitofp i64 %36 to x86_fp80
%38 = fcmp ole x86_fp80 %35, %37
br i1 %38, label %39, label %50
39: ; preds = %34
%40 = load i64, i64* %10
%41 = uitofp i64 %40 to x86_fp80
%42 = fdiv x86_fp80 0xK3FFF8000000000000000, %41
%43 = load x86_fp80, x86_fp80* %6
%44 = fadd x86_fp80 %43, %42
store x86_fp80 %44, x86_fp80* %6
br label %45
45: ; preds = %39
%46 = load x86_fp80, x86_fp80* %7
%47 = fadd x86_fp80 %46, 0xK3FF1D1B71758E2196800
store x86_fp80 %47, x86_fp80* %7
%48 = load i64, i64* %10
%49 = add i64 %48, 4
store i64 %49, i64* %10
br label %34
50: ; preds = %34
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%52 = load i32, i32* %51
%53 = call i32 @close(i32 %52)
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 1
%55 = load i32, i32* %54
%56 = call i32 @write(i32 %55, x86_fp80* %6, i32 16)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %30
store x86_fp80 0xK00000000000000000000, x86_fp80* %7
store i64 3, i64* %10
br label %59
59: ; preds = %70, %58
%60 = load x86_fp80, x86_fp80* %7
%61 = load i64, i64* %9
%62 = uitofp i64 %61 to x86_fp80
%63 = fcmp ole x86_fp80 %60, %62
br i1 %63, label %64, label %75
64: ; preds = %59
%65 = load i64, i64* %10
%66 = uitofp i64 %65 to x86_fp80
%67 = fdiv x86_fp80 0xK3FFF8000000000000000, %66
%68 = load x86_fp80, x86_fp80* %6
%69 = fsub x86_fp80 %68, %67
store x86_fp80 %69, x86_fp80* %6
br label %70
70: ; preds = %64
%71 = load x86_fp80, x86_fp80* %7
%72 = fadd x86_fp80 %71, 0xK3FF1D1B71758E2196800
store x86_fp80 %72, x86_fp80* %7
%73 = load i64, i64* %10
%74 = add i64 %73, 4
store i64 %74, i64* %10
br label %59
75: ; preds = %59
%76 = call i32 @wait(i32* %12)
%77 = load i32, i32* %12
%78 = call i64 @WIFEXITED(i32 %77)
%79 = icmp ne i64 %78, 0
br i1 %79, label %80, label %90
80: ; preds = %75
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 1
%82 = load i32, i32* %81
%83 = call i32 @close(i32 %82)
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%85 = load i32, i32* %84
%86 = call i32 @read(i32 %85, x86_fp80* %8, i32 16)
%87 = load x86_fp80, x86_fp80* %6
%88 = load x86_fp80, x86_fp80* %8
%89 = fadd x86_fp80 %87, %88
store x86_fp80 %89, x86_fp80* %6
br label %92
90: ; preds = %75
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
br label %92
92: ; preds = %90, %80
br label %93
93: ; preds = %92
br label %94
94: ; preds = %93, %28
%95 = load x86_fp80, x86_fp80* %6
%96 = fmul x86_fp80 %95, 0xK40018000000000000000
store x86_fp80 %96, x86_fp80* %6
%97 = load x86_fp80, x86_fp80* %6
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), x86_fp80 %97)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"Error!: \00"
@.str.1 = [55 x i8] c"Error!: El proceso hijo ha finalizado inesperadamenten\00"
@.str.2 = [23 x i8] c"Pi es aprox. : %.25Lgn\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca x86_fp80
%4 = alloca x86_fp80
%5 = alloca i32
%6 = alloca [2 x i32]
%7 = bitcast x86_fp80* %3 to i8*
%8 = bitcast x86_fp80* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast [2 x i32]* %6 to i8*
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = icmp eq i32 %0, 1
br i1 %13, label %19, label %14
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @atol(i8* %16)
%18 = uitofp i64 %17 to x86_fp80
br label %19
19: ; preds = %2, %14
%20 = phi x86_fp80 [ %18, %14 ], [ 0xK400B9C40000000000000, %2 ]
%21 = call i32 (...) @fork()
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %69
25: ; preds = %19
%26 = icmp eq i32 %21, 0
br i1 %26, label %27, label %44
27: ; preds = %25, %27
%28 = phi x86_fp80 [ %34, %27 ], [ 0xK00000000000000000000, %25 ]
%29 = phi i64 [ %35, %27 ], [ 1, %25 ]
%30 = phi x86_fp80 [ %33, %27 ], [ 0xK00000000000000000000, %25 ]
%31 = uitofp i64 %29 to x86_fp80
%32 = fdiv x86_fp80 0xK3FFF8000000000000000, %31
%33 = fadd x86_fp80 %32, %30
%34 = fadd x86_fp80 %28, 0xK3FF1D1B71758E2196800
%35 = add i64 %29, 4
%36 = fcmp ugt x86_fp80 %34, %20
br i1 %36, label %37, label %27
37: ; preds = %27
store x86_fp80 %33, x86_fp80* %3
%38 = load i32, i32* %11
%39 = call i32 @close(i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%41 = load i32, i32* %40
%42 = call i32 @write(i32 %41, x86_fp80* %3, i32 16)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %25, %44
%45 = phi x86_fp80 [ %51, %44 ], [ 0xK00000000000000000000, %25 ]
%46 = phi i64 [ %52, %44 ], [ 3, %25 ]
%47 = phi x86_fp80 [ %50, %44 ], [ 0xK00000000000000000000, %25 ]
%48 = uitofp i64 %46 to x86_fp80
%49 = fdiv x86_fp80 0xK3FFF8000000000000000, %48
%50 = fsub x86_fp80 %47, %49
%51 = fadd x86_fp80 %45, 0xK3FF1D1B71758E2196800
%52 = add i64 %46, 4
%53 = fcmp ugt x86_fp80 %51, %20
br i1 %53, label %54, label %44
54: ; preds = %44
%55 = call i32 @wait(i32* %5)
%56 = load i32, i32* %5
%57 = call i64 @WIFEXITED(i32 %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %67, label %59
59: ; preds = %54
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%61 = load i32, i32* %60
%62 = call i32 @close(i32 %61)
%63 = load i32, i32* %11
%64 = call i32 @read(i32 %63, x86_fp80* %4, i32 16)
%65 = load x86_fp80, x86_fp80* %4
%66 = fadd x86_fp80 %50, %65
br label %69
67: ; preds = %54
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
br label %69
69: ; preds = %67, %59, %23
%70 = phi x86_fp80 [ %50, %67 ], [ %66, %59 ], [ 0xK00000000000000000000, %23 ]
%71 = fmul x86_fp80 %70, 0xK40018000000000000000
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), x86_fp80 %71)
ret i32 0
}