#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;
  scalar_t__ tv_usec;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ fork();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, scalar_t__);
int main() {
  int i;
  struct timeval tempo1, tempo2;
  pid_t pid;
  gettimeofday(&tempo1, NULL);
  pid = fork();
  gettimeofday(&tempo2, NULL);
  if (pid) {
    printf("tempo de criação de um processo: %ld microssegundos\n",
           ((tempo2.tv_sec * 1000000 + tempo2.tv_usec) -
            (tempo1.tv_sec * 1000000 + tempo1.tv_usec)));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x30(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmpq   $0x0,-0x30(%rbp)
je     1199 <main+0x69>
imul   $0xf4240,-0x28(%rbp),%eax
movslq %eax,%rsi
add    -0x20(%rbp),%rsi
imul   $0xf4240,-0x18(%rbp),%eax
cltq
add    -0x10(%rbp),%rax
sub    %rax,%rsi
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
xor    %eax,%eax
call   1050 <fork@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rbx,%rbx
je     118a <main+0x5a>
movslq (%rsp),%rax
imul   $0xf4240,%rax,%rsi
movslq 0x10(%rsp),%rax
add    0x8(%rsp),%rsi
imul   $0xf4240,%rax,%rax
add    0x18(%rsp),%rax
sub    %rax,%rsi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [55 x i8] c"tempo de cria\C3\A7\C3\A3o de um processo: %ld microssegundos\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%7 = call i64 (...) @fork()
store i64 %7, i64* %5
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%9 = load i64, i64* %5
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %0
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = mul nsw i32 %13, 1000000
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%17 = load i64, i64* %16
%18 = add nsw i64 %15, %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%20 = load i32, i32* %19
%21 = mul nsw i32 %20, 1000000
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%24 = load i64, i64* %23
%25 = add nsw i64 %22, %24
%26 = sub nsw i64 %18, %25
%27 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i64 %26)
br label %28
28: ; preds = %11, %0
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [55 x i8] c"tempo de cria\C3\A7\C3\A3o de um processo: %ld microssegundos\0A\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* null)
%6 = tail call i64 (...) @fork()
%7 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%8 = icmp eq i64 %6, 0
br i1 %8, label %26, label %9
9: ; preds = %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 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i64 %24)
br label %26
26: ; preds = %9, %0
ret i32 0
}