#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 */

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
int fork();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned long long);
unsigned long long rdtsc();
int main() {
  float avg_diff;
  unsigned long long coldstart = 0;
  unsigned long long start = 0;
  unsigned long long end = 0;
  int child_pid = 0;
  coldstart = rdtsc();
  start = rdtsc();
  child_pid = fork();
  end = rdtsc();
  if (child_pid > 0) {
    kill(child_pid, SIGKILL);
  }
  printf("%llu", (end - start));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    $0x0,%al
call   1040 <rdtsc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <rdtsc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <rdtsc@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    11b4 <main+0x74>
mov    -0x24(%rbp),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    -0x20(%rbp),%rsi
sub    -0x18(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <rdtsc@plt>
xor    %eax,%eax
call   1040 <rdtsc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <rdtsc@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jle    117c <main+0x3c>
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1050 <kill@plt>
sub    %r14,%rbx
lea    0xe7a(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SIGKILL = global i32 0
@.str = [5 x i8] c"%llu\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %3
store i64 0, i64* %4
store i64 0, i64* %5
store i32 0, i32* %6
%7 = call i64 (...) @rdtsc()
store i64 %7, i64* %3
%8 = call i64 (...) @rdtsc()
store i64 %8, i64* %4
%9 = call i32 (...) @fork()
store i32 %9, i32* %6
%10 = call i64 (...) @rdtsc()
store i64 %10, i64* %5
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* %6
%15 = load i32, i32* @SIGKILL
%16 = call i32 @kill(i32 %14, i32 %15)
br label %17
17: ; preds = %13, %0
%18 = load i64, i64* %5
%19 = load i64, i64* %4
%20 = sub i64 %18, %19
%21 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %20)
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@SIGKILL = global i32 0
@.str = [5 x i8] c"%llu\00"
define i32 @main() {
%1 = tail call i64 (...) @rdtsc()
%2 = tail call i64 (...) @rdtsc()
%3 = tail call i32 (...) @fork()
%4 = tail call i64 (...) @rdtsc()
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @SIGKILL
%8 = tail call i32 @kill(i32 %3, i32 %7)
br label %9
9: ; preds = %6, %0
%10 = sub i64 %4, %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %10)
ret i32 0
}