#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 tms {
  int dummy;
};
typedef scalar_t__ pid_t;
typedef scalar_t__ clock_t;

/* Variables and functions */
int WEXITSTATUS(int);
int /*<<< orphan*/ _SC_CLK_TCK;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
double sysconf(int /*<<< orphan*/);
scalar_t__ times(struct tms *);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int estado, i, N = 2060000, busqueda = 1600000;
  int array[N];
  for (i = 0; i < N; i++) {
    array[i] = i;
  }
  struct tms buf;
  clock_t t1 = times(&buf);
  pid_t id1 = fork();
  if (id1 == 0) {
    for (i = 0; i < 10000000; i++) {
    }
    for (i = 0; i < N / 2 + 1; i++) {
      if (i == busqueda) {
        printf("Encontrado por el hijo 1\n");
        break;
      }
    }
    exit(1);
  } else {
    pid_t id2 = fork();
    if (id2 == 0) {
      for (i = 0; i < 10000000; i++) {
      }
      for (i = N / 2 + 1; i < N; i++) {
        if (i == busqueda) {
          printf("Encontrado por el hijo 2\n");
          break;
        }
      }
      exit(2);
    } else {
      waitpid(id2, &estado, 0);
      printf("Salida del hijo: %d\n", WEXITSTATUS(estado));
    }
    waitpid(id1, &estado, 0);
    printf("Salida del hijo: %d\n", WEXITSTATUS(estado));
  }
  double tvalor1 = sysconf(_SC_CLK_TCK);
  clock_t t2 = times(&buf);
  double tiempo = (double)(t2 - t1) / tvalor1;
  printf("El tiempo total ha sido: %f\n", tiempo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1f6ee0,-0x1c(%rbp)
movl   $0x186a00,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ed <main+0x7d>
mov    -0x70(%rbp),%rax
mov    -0x18(%rbp),%edx
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c5 <main+0x55>
lea    -0x38(%rbp),%rdi
call   1060 <times@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    129b <main+0x12b>
movl   $0x0,-0x18(%rbp)
cmpl   $0x989680,-0x18(%rbp)
jge    1237 <main+0xc7>
jmp    1229 <main+0xb9>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1217 <main+0xa7>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1291 <main+0x121>
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    127e <main+0x10e>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1291 <main+0x121>
jmp    1283 <main+0x113>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    123e <main+0xce>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1331 <main+0x1c1>
movl   $0x0,-0x18(%rbp)
cmpl   $0x989680,-0x18(%rbp)
jge    12d8 <main+0x168>
jmp    12ca <main+0x15a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12b8 <main+0x148>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1327 <main+0x1b7>
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    1314 <main+0x1a4>
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1327 <main+0x1b7>
jmp    1319 <main+0x1a9>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12e9 <main+0x179>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x50(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x14(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xce3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x14(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xcbc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
movsd  %xmm0,-0x58(%rbp)
lea    -0x38(%rbp),%rdi
call   1060 <times@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
sub    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
lea    0xc87(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsp,%r13
lea    0x10(%rsp),%rdi
call   1070 <times@plt>
mov    %rax,%r14
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     1260 <main+0xe0>
mov    %rax,%rbx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     126a <main+0xea>
lea    0xc(%rsp),%r15
mov    %rax,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xe1e(%rip),%r12
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
movsd  %xmm0,0x18(%rsp)
lea    0x10(%rsp),%rdi
call   1070 <times@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0x18(%rsp),%xmm0
lea    0xdcf(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r13,%rsp
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdc1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.tms = type { i32 }
@.str = [26 x i8] c"Encontrado por el hijo 1\0A\00"
@.str.1 = [26 x i8] c"Encontrado por el hijo 2\0A\00"
@.str.2 = [21 x i8] c"Salida del hijo: %d\0A\00"
@_SC_CLK_TCK = global i32 0
@.str.3 = [29 x i8] c"El tiempo total ha sido: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca %struct.tms
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca double
%17 = alloca i64
%18 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2060000, i32* %8
store i32 1600000, i32* %9
%19 = load i32, i32* %8
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %10
%22 = alloca i32, i64 %20
store i64 %20, i64* %11
store i32 0, i32* %7
br label %23
23: ; preds = %32, %2
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = load i32, i32* %7
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %22, i64 %30
store i32 %28, i32* %31
br label %32
32: ; preds = %27
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %23
35: ; preds = %23
%36 = call i64 @times(%struct.tms* %12)
store i64 %36, i64* %13
%37 = call i64 (...) @fork()
store i64 %37, i64* %14
%38 = load i64, i64* %14
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %67
40: ; preds = %35
store i32 0, i32* %7
br label %41
41: ; preds = %45, %40
%42 = load i32, i32* %7
%43 = icmp slt i32 %42, 10000000
br i1 %43, label %44, label %48
44: ; preds = %41
br label %45
45: ; preds = %44
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %41
48: ; preds = %41
store i32 0, i32* %7
br label %49
49: ; preds = %62, %48
%50 = load i32, i32* %7
%51 = load i32, i32* %8
%52 = sdiv i32 %51, 2
%53 = add nsw i32 %52, 1
%54 = icmp slt i32 %50, %53
br i1 %54, label %55, label %65
55: ; preds = %49
%56 = load i32, i32* %7
%57 = load i32, i32* %9
%58 = icmp eq i32 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %65
61: ; preds = %55
br label %62
62: ; preds = %61
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 1
store i32 %64, i32* %7
br label %49
65: ; preds = %59, %49
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %35
%68 = call i64 (...) @fork()
store i64 %68, i64* %15
%69 = load i64, i64* %15
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %99
71: ; preds = %67
store i32 0, i32* %7
br label %72
72: ; preds = %76, %71
%73 = load i32, i32* %7
%74 = icmp slt i32 %73, 10000000
br i1 %74, label %75, label %79
75: ; preds = %72
br label %76
76: ; preds = %75
%77 = load i32, i32* %7
%78 = add nsw i32 %77, 1
store i32 %78, i32* %7
br label %72
79: ; preds = %72
%80 = load i32, i32* %8
%81 = sdiv i32 %80, 2
%82 = add nsw i32 %81, 1
store i32 %82, i32* %7
br label %83
83: ; preds = %94, %79
%84 = load i32, i32* %7
%85 = load i32, i32* %8
%86 = icmp slt i32 %84, %85
br i1 %86, label %87, label %97
87: ; preds = %83
%88 = load i32, i32* %7
%89 = load i32, i32* %9
%90 = icmp eq i32 %88, %89
br i1 %90, label %91, label %93
91: ; preds = %87
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %97
93: ; preds = %87
br label %94
94: ; preds = %93
%95 = load i32, i32* %7
%96 = add nsw i32 %95, 1
store i32 %96, i32* %7
br label %83
97: ; preds = %91, %83
%98 = call i32 @exit(i32 2)
unreachable
99: ; preds = %67
%100 = load i64, i64* %15
%101 = call i32 @waitpid(i64 %100, i32* %6, i32 0)
%102 = load i32, i32* %6
%103 = call i32 @WEXITSTATUS(i32 %102)
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %103)
br label %105
105: ; preds = %99
%106 = load i64, i64* %14
%107 = call i32 @waitpid(i64 %106, i32* %6, i32 0)
%108 = load i32, i32* %6
%109 = call i32 @WEXITSTATUS(i32 %108)
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %109)
br label %111
111: ; preds = %105
%112 = load i32, i32* @_SC_CLK_TCK
%113 = call double @sysconf(i32 %112)
store double %113, double* %16
%114 = call i64 @times(%struct.tms* %12)
store i64 %114, i64* %17
%115 = load i64, i64* %17
%116 = load i64, i64* %13
%117 = sub nsw i64 %115, %116
%118 = sitofp i64 %117 to double
%119 = load double, double* %16
%120 = fdiv double %118, %119
store double %120, double* %18
%121 = load double, double* %18
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), double %121)
store i32 0, i32* %3
%123 = load i8*, i8** %10
%124 = load i32, i32* %3
ret i32 %124
}

LLVM IR (-O2):
%struct.tms = type { i32 }
@.str.2 = [21 x i8] c"Salida del hijo: %d\0A\00"
@_SC_CLK_TCK = global i32 0
@.str.3 = [29 x i8] c"El tiempo total ha sido: %f\0A\00"
@str = [25 x i8] c"Encontrado por el hijo 2\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.tms
%5 = bitcast i32* %3 to i8*
%6 = tail call i8* @llvm.stacksave()
%7 = bitcast %struct.tms* %4 to i8*
%8 = call i64 @times(%struct.tms* %4)
%9 = tail call i64 (...) @fork()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = tail call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 2)
unreachable
19: ; preds = %13
%20 = call i32 @waitpid(i64 %14, i32* %3, i32 0)
%21 = load i32, i32* %3
%22 = call i32 @WEXITSTATUS(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = call i32 @waitpid(i64 %9, i32* %3, i32 0)
%25 = load i32, i32* %3
%26 = call i32 @WEXITSTATUS(i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @_SC_CLK_TCK
%29 = call double @sysconf(i32 %28)
%30 = call i64 @times(%struct.tms* %4)
%31 = sub nsw i64 %30, %8
%32 = sitofp i64 %31 to double
%33 = fdiv double %32, %29
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), double %33)
ret i32 0
}