#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 rusage {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ execvp(char const *, char **);
int fork();
unsigned long long read_timer();
int /*<<< orphan*/ wait4(int, int *, int /*<<< orphan*/, struct rusage *);
unsigned long long run(const char *runstr, struct rusage *usage, char *argv[]) {
  int status, pid;
  unsigned long long timeb, timea;
  timea = read_timer();
  if ((pid = fork()) == 0) {
    execvp(runstr, argv);
    _exit(0);
  }
  wait4(pid, &status, 0, usage);
  timeb = read_timer();
  return ((signed long long)timeb - (signed long long)timea);
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1040 <read_timer@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jne    1196 <run+0x46>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <execvp@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rcx
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1050 <wait4@plt>
mov    $0x0,%al
call   1040 <read_timer@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
xor    %eax,%eax
call   1040 <read_timer@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     119d <run+0x4d>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
mov    %rbx,%rcx
call   1050 <wait4@plt>
xor    %eax,%eax
call   1040 <read_timer@plt>
sub    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <execvp@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.rusage = type { i32 }
define i64 @run(i8* %0, %struct.rusage* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca %struct.rusage*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %4
store %struct.rusage* %1, %struct.rusage** %5
store i8** %2, i8*** %6
%11 = call i64 (...) @read_timer()
store i64 %11, i64* %10
%12 = call i32 (...) @fork()
store i32 %12, i32* %8
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = load i8**, i8*** %6
%17 = call i32 @execvp(i8* %15, i8** %16)
%18 = call i32 @_exit(i32 0)
unreachable
19: ; preds = %3
%20 = load i32, i32* %8
%21 = load %struct.rusage*, %struct.rusage** %5
%22 = call i32 @wait4(i32 %20, i32* %7, i32 0, %struct.rusage* %21)
%23 = call i64 (...) @read_timer()
store i64 %23, i64* %9
%24 = load i64, i64* %9
%25 = load i64, i64* %10
%26 = sub nsw i64 %24, %25
ret i64 %26
}

LLVM IR (-O2):
%struct.rusage = type { i32 }
define i64 @run(i8* %0, %struct.rusage* %1, i8** %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i64 (...) @read_timer()
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = tail call i32 @execvp(i8* %0, i8** %2)
%11 = tail call i32 @_exit(i32 0)
unreachable
12: ; preds = %3
%13 = call i32 @wait4(i32 %7, i32* %4, i32 0, %struct.rusage* %1)
%14 = call i64 (...) @read_timer()
%15 = sub nsw i64 %14, %6
ret i64 %15
}