#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 {
  int tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ execv(char *, char **);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  double tiemponano;
  struct timespec ti_nano, tf_nano;
  int pid;
  clock_gettime(CLOCK_REALTIME, &ti_nano);
  pid = fork();
  if (pid != 0) {
    wait(0);
    clock_gettime(CLOCK_REALTIME, &tf_nano);
    tiemponano = (tf_nano.tv_sec - ti_nano.tv_sec) * 1000000000 +
                 (tf_nano.tv_nsec - ti_nano.tv_nsec);
    printf("crear un hijo y ejecutar la tarea tardo:%g us | %g ns \n",
           tiemponano / 1000, tiemponano);
    clock_gettime(CLOCK_REALTIME, &ti_nano);
    system("./salida");
    clock_gettime(CLOCK_REALTIME, &tf_nano);
    tiemponano = (tf_nano.tv_sec - ti_nano.tv_sec) * 1000000000 +
                 (tf_nano.tv_nsec - ti_nano.tv_nsec);
    printf("Realizar la misma tarea pero ejecutada con la llamada system sin "
           "crear otro hijo tardo:%g us | %g ns \n",
           tiemponano / 1000, tiemponano);
  } else {
    char *args[] = {"salida", argv[1], (char *)NULL};
    execv("salida", args);
    printf("Return not expected. Must be an execv error \n");
  }
  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    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     126c <main+0x10c>
xor    %edi,%edi
call   1060 <wait@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x28(%rbp),%eax
sub    -0x20(%rbp),%eax
imul   $0x3b9aca00,%eax,%eax
mov    -0x24(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe21(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xe19(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
lea    0xe31(%rip),%rdi
call   1040 <system@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x28(%rbp),%eax
sub    -0x20(%rbp),%eax
imul   $0x3b9aca00,%eax,%eax
mov    -0x24(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xdb0(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xde9(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
jmp    12a9 <main+0x149>
lea    0xdcf(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xdac(%rip),%rdi
call   1070 <execv@plt>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    0x2e5f(%rip),%r14
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1040 <clock_gettime@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1249 <main+0xd9>
xor    %edi,%edi
call   1070 <wait@plt>
mov    (%r14),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <clock_gettime@plt>
mov    0x10(%rsp),%eax
mov    0x14(%rsp),%ecx
sub    0x8(%rsp),%eax
imul   $0x3b9aca00,%eax,%eax
sub    0xc(%rsp),%ecx
add    %eax,%ecx
cvtsi2sd %ecx,%xmm1
movapd %xmm1,%xmm0
divsd  0xe24(%rip),%xmm0
lea    0xe25(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1040 <clock_gettime@plt>
lea    0xe42(%rip),%rdi
call   1050 <system@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
call   1040 <clock_gettime@plt>
mov    0x10(%rsp),%eax
sub    0x8(%rsp),%eax
mov    0x14(%rsp),%ecx
imul   $0x3b9aca00,%eax,%eax
sub    0xc(%rsp),%ecx
add    %eax,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
movapd %xmm1,%xmm0
divsd  0xdc7(%rip),%xmm0
lea    0xe09(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
jmp    127d <main+0x10d>
lea    0xdf2(%rip),%rdi
mov    %rdi,0x10(%rsp)
mov    0x8(%rbx),%rax
mov    %rax,0x18(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x10(%rsp),%rsi
call   1080 <execv@plt>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@CLOCK_REALTIME = global i32 0
@.str = [56 x i8] c"crear un hijo y ejecutar la tarea tardo:%g us | %g ns \0A\00"
@.str.1 = [9 x i8] c"./salida\00"
@.str.2 = [103 x i8] c"Realizar la misma tarea pero ejecutada con la llamada system sin crear otro hijo tardo:%g us | %g ns \0A\00"
@.str.3 = [7 x i8] c"salida\00"
@.str.4 = [46 x i8] c"Return not expected. Must be an execv error \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca %struct.timespec
%8 = alloca %struct.timespec
%9 = alloca i32
%10 = alloca [3 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @CLOCK_REALTIME
%12 = call i32 @clock_gettime(i32 %11, %struct.timespec* %7)
%13 = call i32 (...) @fork()
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %59
16: ; preds = %2
%17 = call i32 @wait(i32 0)
%18 = load i32, i32* @CLOCK_REALTIME
%19 = call i32 @clock_gettime(i32 %18, %struct.timespec* %8)
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%23 = load i32, i32* %22
%24 = sub nsw i32 %21, %23
%25 = mul nsw i32 %24, 1000000000
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%29 = load i32, i32* %28
%30 = sub nsw i32 %27, %29
%31 = add nsw i32 %25, %30
%32 = sitofp i32 %31 to double
store double %32, double* %6
%33 = load double, double* %6
%34 = fdiv double %33, 1.000000e+03
%35 = load double, double* %6
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), double %34, double %35)
%37 = load i32, i32* @CLOCK_REALTIME
%38 = call i32 @clock_gettime(i32 %37, %struct.timespec* %7)
%39 = call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* @CLOCK_REALTIME
%41 = call i32 @clock_gettime(i32 %40, %struct.timespec* %8)
%42 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%45 = load i32, i32* %44
%46 = sub nsw i32 %43, %45
%47 = mul nsw i32 %46, 1000000000
%48 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 1
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%51 = load i32, i32* %50
%52 = sub nsw i32 %49, %51
%53 = add nsw i32 %47, %52
%54 = sitofp i32 %53 to double
store double %54, double* %6
%55 = load double, double* %6
%56 = fdiv double %55, 1.000000e+03
%57 = load double, double* %6
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.2, i64 0, i64 0), double %56, double %57)
br label %69
59: ; preds = %2
%60 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %60
%61 = getelementptr inbounds i8*, i8** %60, i64 1
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 1
%64 = load i8*, i8** %63
store i8* %64, i8** %61
%65 = getelementptr inbounds i8*, i8** %61, i64 1
store i8* null, i8** %65
%66 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 0
%67 = call i32 @execv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
br label %69
69: ; preds = %59, %16
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@CLOCK_REALTIME = global i32 0
@.str = [56 x i8] c"crear un hijo y ejecutar la tarea tardo:%g us | %g ns \0A\00"
@.str.1 = [9 x i8] c"./salida\00"
@.str.2 = [103 x i8] c"Realizar la misma tarea pero ejecutada con la llamada system sin crear otro hijo tardo:%g us | %g ns \0A\00"
@.str.3 = [7 x i8] c"salida\00"
@str = [45 x i8] c"Return not expected. Must be an execv error \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca [3 x i8*]
%6 = bitcast %struct.timespec* %3 to i8*
%7 = bitcast %struct.timespec* %4 to i8*
%8 = load i32, i32* @CLOCK_REALTIME
%9 = call i32 @clock_gettime(i32 %8, %struct.timespec* %3)
%10 = call i32 (...) @fork()
%11 = icmp eq i32 %10, 0
br i1 %11, label %47, label %12
12: ; preds = %2
%13 = call i32 @wait(i32 0)
%14 = load i32, i32* @CLOCK_REALTIME
%15 = call i32 @clock_gettime(i32 %14, %struct.timespec* %4)
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = sub nsw i32 %17, %19
%21 = mul nsw i32 %20, 1000000000
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%25 = load i32, i32* %24
%26 = sub i32 %23, %25
%27 = add nsw i32 %26, %21
%28 = sitofp i32 %27 to double
%29 = fdiv double %28, 1.000000e+03
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), double %29, double %28)
%31 = load i32, i32* @CLOCK_REALTIME
%32 = call i32 @clock_gettime(i32 %31, %struct.timespec* %3)
%33 = call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @CLOCK_REALTIME
%35 = call i32 @clock_gettime(i32 %34, %struct.timespec* %4)
%36 = load i32, i32* %16
%37 = load i32, i32* %18
%38 = sub nsw i32 %36, %37
%39 = mul nsw i32 %38, 1000000000
%40 = load i32, i32* %22
%41 = load i32, i32* %24
%42 = sub i32 %40, %41
%43 = add nsw i32 %42, %39
%44 = sitofp i32 %43 to double
%45 = fdiv double %44, 1.000000e+03
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([103 x i8], [103 x i8]* @.str.2, i64 0, i64 0), double %45, double %44)
br label %56
47: ; preds = %2
%48 = bitcast [3 x i8*]* %5 to i8*
%49 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %49
%50 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 1
%51 = getelementptr inbounds i8*, i8** %1, i64 1
%52 = load i8*, i8** %51
store i8* %52, i8** %50
%53 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 2
store i8* null, i8** %53
%54 = call i32 @execv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %49)
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
br label %56
56: ; preds = %47, %12
ret i32 0
}