#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;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ _SC_CHILD_MAX;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, double, ...);
int /*<<< orphan*/ sysconf(int /*<<< orphan*/);
int main() {
  struct timespec ini, fin;
  double nano;
  int pid, err;
  clock_gettime(CLOCK_REALTIME, &ini);
  pid = fork();
  if (pid != 0) {
    clock_gettime(CLOCK_REALTIME, &fin);
    nano = (fin.tv_sec - ini.tv_sec) * 1000000000 +
           (double)(fin.tv_nsec - ini.tv_nsec);
  } else {
    exit(0);
  };
  printf("Tiempo para crear un nuevo hijo: %g nSegs | %g uSegs\n", nano,
         nano / 1000);
  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)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11c2 <main+0x72>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x28(%rbp),%eax
sub    -0x18(%rbp),%eax
imul   $0x3b9aca00,%eax,%eax
cvtsi2sd %eax,%xmm0
mov    -0x20(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11c9 <main+0x79>
xor    %edi,%edi
call   1060 <exit@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xe25(%rip),%xmm2
divsd  %xmm2,%xmm1
lea    0xe22(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
cvtsi2sd %eax,%xmm0
lea    0xe38(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e7c(%rip),%rbx
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
call   1030 <clock_gettime@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11e6 <main+0x96>
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
mov    (%rsp),%eax
sub    0x10(%rsp),%eax
imul   $0x3b9aca00,%eax,%eax
cvtsi2sd %eax,%xmm1
mov    0x8(%rsp),%rax
sub    0x18(%rsp),%rax
cvtsi2sd %rax,%xmm0
addsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
divsd  0xe53(%rip),%xmm1
lea    0xe54(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xe67(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@.str = [54 x i8] c"Tiempo para crear un nuevo hijo: %g nSegs | %g 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.timespec
%3 = alloca %struct.timespec
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @CLOCK_REALTIME
%8 = call i32 @clock_gettime(i32 %7, %struct.timespec* %2)
%9 = call i32 (...) @fork()
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %0
%13 = load i32, i32* @CLOCK_REALTIME
%14 = call i32 @clock_gettime(i32 %13, %struct.timespec* %3)
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%18 = load i32, i32* %17
%19 = sub nsw i32 %16, %18
%20 = mul nsw i32 %19, 1000000000
%21 = sitofp i32 %20 to double
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%25 = load i64, i64* %24
%26 = sub nsw i64 %23, %25
%27 = sitofp i64 %26 to double
%28 = fadd double %21, %27
store double %28, double* %4
br label %31
29: ; preds = %0
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %12
%32 = load double, double* %4
%33 = load double, double* %4
%34 = fdiv double %33, 1.000000e+03
%35 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), double %32, double %34)
%36 = load i32, i32* @_SC_CHILD_MAX
%37 = call i32 @sysconf(i32 %36)
%38 = sitofp i32 %37 to double
%39 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), double %38)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@.str = [54 x i8] c"Tiempo para crear un nuevo hijo: %g nSegs | %g 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.timespec
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %1 to i8*
%4 = bitcast %struct.timespec* %2 to i8*
%5 = load i32, i32* @CLOCK_REALTIME
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %1)
%7 = call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %32, label %9
9: ; preds = %0
%10 = load i32, i32* @CLOCK_REALTIME
%11 = call i32 @clock_gettime(i32 %10, %struct.timespec* %2)
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%15 = load i32, i32* %14
%16 = sub nsw i32 %13, %15
%17 = mul nsw i32 %16, 1000000000
%18 = sitofp i32 %17 to double
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%20 = load i64, i64* %19
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%22 = load i64, i64* %21
%23 = sub nsw i64 %20, %22
%24 = sitofp i64 %23 to double
%25 = fadd double %18, %24
%26 = fdiv double %25, 1.000000e+03
%27 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), double %25, double %26)
%28 = load i32, i32* @_SC_CHILD_MAX
%29 = call i32 @sysconf(i32 %28)
%30 = sitofp i32 %29 to double
%31 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), double %30)
ret i32 0
32: ; preds = %0
%33 = call i32 @exit(i32 0)
unreachable
}