#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;
  long tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ _SC_CHILD_MAX;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, long);
long sysconf(int /*<<< orphan*/);
int main() {
  struct timeval Tinicio, Tfin;
  long duracion;
  int pid, err;
  gettimeofday(&Tinicio, 0);
  pid = fork();
  if (pid != 0) {
    gettimeofday(&Tfin, 0);
    duracion = ((Tfin.tv_sec * 1000000) + Tfin.tv_usec) -
               ((Tinicio.tv_sec * 1000000) + Tinicio.tv_usec);
  } else {
    exit(0);
  };
  printf("Tiempo para crear un nuevo hijo: %d uSegs \n", duracion);
  printf("Cantidad de procesos que puede crear:%lu \n", sysconf(_SC_CHILD_MAX));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11b0 <main+0x60>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
imul   $0xf4240,-0x28(%rbp),%eax
cltq
add    -0x20(%rbp),%rax
imul   $0xf4240,-0x18(%rbp),%ecx
movslq %ecx,%rcx
add    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    11b7 <main+0x67>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x30(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %rax,%rsi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11cc <main+0x7c>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movslq 0x8(%rsp),%rax
imul   $0xf4240,%rax,%rsi
movslq 0x18(%rsp),%rax
add    0x10(%rsp),%rsi
imul   $0xf4240,%rax,%rax
add    0x20(%rsp),%rax
sub    %rax,%rsi
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
lea    0xe6f(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [44 x i8] c"Tiempo para crear un nuevo hijo: %d uSegs \0A\00"
@.str.1 = [43 x i8] c"Cantidad de procesos que puede crear:%lu \0A\00"
@_SC_CHILD_MAX = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%8 = call i32 (...) @fork()
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %0
%12 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%14 = load i32, i32* %13
%15 = mul nsw i32 %14, 1000000
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%18 = load i64, i64* %17
%19 = add nsw i64 %16, %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%21 = load i32, i32* %20
%22 = mul nsw i32 %21, 1000000
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%25 = load i64, i64* %24
%26 = add nsw i64 %23, %25
%27 = sub nsw i64 %19, %26
store i64 %27, i64* %4
br label %30
28: ; preds = %0
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %11
%31 = load i64, i64* %4
%32 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i64 %31)
%33 = load i32, i32* @_SC_CHILD_MAX
%34 = call i64 @sysconf(i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i64 %34)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [44 x i8] c"Tiempo para crear un nuevo hijo: %d uSegs \0A\00"
@.str.1 = [43 x i8] c"Cantidad de procesos que puede crear:%lu \0A\00"
@_SC_CHILD_MAX = global i32 0
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 %29, label %8
8: ; preds = %0
%9 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = mul nsw i32 %11, 1000000
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%15 = load i64, i64* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%17 = load i32, i32* %16
%18 = mul nsw i32 %17, 1000000
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%21 = load i64, i64* %20
%22 = add i64 %15, %13
%23 = add i64 %21, %19
%24 = sub i64 %22, %23
%25 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i64 %24)
%26 = load i32, i32* @_SC_CHILD_MAX
%27 = call i64 @sysconf(i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i64 %27)
ret i32 0
29: ; preds = %0
%30 = call i32 @exit(i32 0)
unreachable
}