#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 execve(char *, char **, int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
double microtime();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main(int argc, char **argv) {
  double start = microtime();
  int pid = fork();
  if (pid == -1) {
    fprintf(stderr, "fork fault\n");
    return 2;
  }
  if (pid == 0) {
    int r = execve(argv[1], argv + 1, 0);
    if (r == -1) {
      fprintf(stderr, "exec fault\n");
      return 3;
    }
  }
  wait(0);
  double time = microtime() - start;
  fprintf(stderr, "time: %.6f seconds\n", time);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <microtime@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a9 <main+0x59>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    123a <main+0xea>
cmpl   $0x0,-0x1c(%rbp)
jne    11ff <main+0xaf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
xor    %edx,%edx
call   1030 <execve@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11fa <main+0xaa>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    123a <main+0xea>
jmp    11ff <main+0xaf>
xor    %edi,%edi
call   1060 <wait@plt>
mov    $0x0,%al
call   1050 <microtime@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
movsd  -0x28(%rbp),%xmm0
lea    0xdec(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
call   1050 <microtime@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1193 <main+0x43>
cmp    $0xffffffff,%eax
jne    11aa <main+0x5a>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x2,%ebx
jmp    11f5 <main+0xa5>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <execve@plt>
cmp    $0xffffffff,%eax
je     11d9 <main+0x89>
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <wait@plt>
xor    %eax,%eax
call   1050 <microtime@plt>
subsd  0x8(%rsp),%xmm0
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    11f5 <main+0xa5>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x3,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"fork fault\0A\00"
@.str.1 = [12 x i8] c"exec fault\0A\00"
@.str.2 = [20 x i8] c"time: %.6f seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call double (...) @microtime()
store double %10, double* %6
%11 = call i32 (...) @fork()
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %41
17: ; preds = %2
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = call i32 @execve(i8* %23, i8** %25, i32 0)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 3, i32* %3
br label %41
32: ; preds = %20
br label %33
33: ; preds = %32, %17
%34 = call i32 @wait(i32 0)
%35 = call double (...) @microtime()
%36 = load double, double* %6
%37 = fsub double %35, %36
store double %37, double* %9
%38 = load i32, i32* @stderr
%39 = load double, double* %9
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %39)
store i32 0, i32* %3
br label %41
41: ; preds = %33, %29, %14
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"fork fault\0A\00"
@.str.1 = [12 x i8] c"exec fault\0A\00"
@.str.2 = [20 x i8] c"time: %.6f seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call double (...) @microtime()
%4 = tail call i32 (...) @fork()
switch i32 %4, label %16 [
i32 -1, label %5
i32 0, label %8
]
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %22
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @execve(i8* %10, i8** %9, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %22
16: ; preds = %8, %2
%17 = tail call i32 @wait(i32 0)
%18 = tail call double (...) @microtime()
%19 = fsub double %18, %3
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %19)
br label %22
22: ; preds = %13, %16, %5
%23 = phi i32 [ 2, %5 ], [ 0, %16 ], [ 3, %13 ]
ret i32 %23
}