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

/* Variables and functions */
int /*<<< orphan*/ execvp(char *, int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main() {
  struct timeval timeInicio, timeFin;
  long total, usegInicio, usegFin;
  int pid;
  total = 0;
  gettimeofday(&timeInicio, 0);
  pid = fork();
  if (pid != 0) {
    wait(0);
    gettimeofday(&timeFin, 0);
    usegInicio = ((timeInicio.tv_sec * 1000000) + timeInicio.tv_usec);
    usegFin = ((timeFin.tv_sec * 1000000) + timeFin.tv_usec);
    total = usegFin - usegInicio;
    printf("crear un hijo y ejecutar la tarea tardo:%ld us \n", total);
    gettimeofday(&timeInicio, 0);
    system("./salida");
    gettimeofday(&timeFin, 0);
    usegInicio = ((timeInicio.tv_sec * 1000000) + timeInicio.tv_usec);
    usegFin = ((timeFin.tv_sec * 1000000) + timeFin.tv_usec);
    total = usegFin - usegInicio;
    printf("Realizar la misma tarea pero ejecutada con la llamada system sin "
           "crear otro hijo tardo:%ld us  \n",
           total);
  } else {
    execvp("./salida", NULL);
    printf("Return not expected. Must be an execv error \n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     124b <main+0xeb>
xor    %edi,%edi
call   1070 <wait@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
imul   $0xf4240,-0x10(%rbp),%eax
add    -0xc(%rbp),%eax
cltq
mov    %rax,-0x28(%rbp)
imul   $0xf4240,-0x18(%rbp),%eax
add    -0x14(%rbp),%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0xe39(%rip),%rdi
call   1030 <system@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
imul   $0xf4240,-0x10(%rbp),%eax
add    -0xc(%rbp),%eax
cltq
mov    %rax,-0x28(%rbp)
imul   $0xf4240,-0x18(%rbp),%eax
add    -0x14(%rbp),%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1269 <main+0x109>
lea    0xddf(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <execvp@plt>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1236 <main+0xc6>
xor    %edi,%edi
call   1080 <wait@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
movslq (%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0x4(%rsp),%rcx
add    %rax,%rcx
movslq 0x8(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0xc(%rsp),%rsi
add    %rax,%rsi
sub    %rcx,%rsi
lea    0xe2b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
lea    0xe44(%rip),%rdi
call   1040 <system@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
movslq (%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0x4(%rsp),%rcx
add    %rax,%rcx
movslq 0x8(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0xc(%rsp),%rsi
add    %rax,%rsi
sub    %rcx,%rsi
lea    0xe0d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1250 <main+0xe0>
lea    0xdf4(%rip),%rdi
xor    %esi,%esi
call   1070 <execvp@plt>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [49 x i8] c"crear un hijo y ejecutar la tarea tardo:%ld us \0A\00"
@.str.1 = [9 x i8] c"./salida\00"
@.str.2 = [97 x i8] c"Realizar la misma tarea pero ejecutada con la llamada system sin crear otro hijo tardo:%ld us \0A\00"
@str = [45 x i8] c"Return not expected. Must be an execv error \00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%6 = call i32 (...) @fork()
%7 = icmp eq i32 %6, 0
br i1 %7, label %42, label %8
8: ; preds = %0
%9 = call i32 @wait(i32 0)
%10 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%12 = load i32, i32* %11
%13 = mul nsw i32 %12, 1000000
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%15 = load i32, i32* %14
%16 = add nsw i32 %13, %15
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%19 = load i32, i32* %18
%20 = mul nsw i32 %19, 1000000
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%22 = load i32, i32* %21
%23 = add nsw i32 %20, %22
%24 = sext i32 %23 to i64
%25 = sub nsw i64 %24, %17
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i64 %25)
%27 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%28 = call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%30 = load i32, i32* %11
%31 = mul nsw i32 %30, 1000000
%32 = load i32, i32* %14
%33 = add nsw i32 %31, %32
%34 = sext i32 %33 to i64
%35 = load i32, i32* %18
%36 = mul nsw i32 %35, 1000000
%37 = load i32, i32* %21
%38 = add nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = sub nsw i64 %39, %34
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([97 x i8], [97 x i8]* @.str.2, i64 0, i64 0), i64 %40)
br label %45
42: ; preds = %0
%43 = call i32 @execvp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* null)
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
br label %45
45: ; preds = %42, %8
ret i32 0
}