#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 tms {
  scalar_t__ tms_cstime;
  scalar_t__ tms_cutime;
};
typedef scalar_t__ clock_t;

/* Variables and functions */
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ print_time(scalar_t__);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ times(struct tms *);
int wait(int *);
int main(int argc, char **argv) {
  struct tms pre_buf, post_buf;
  clock_t start_time, end_time;
  int status, pid;
  if (argc == 1)
    exit(0);
  start_time = time(NULL);
  if ((pid = fork()) < 0) {
    fprintf(stderr, "Cannot fork\n");
    exit(1);
  }
  if (pid == 0) {
    execvp(argv[1], &argv[1]);
    fprintf(stderr, "Cannot execute %s\n", argv[1]);
    exit(-1);
  }
  do {
    times(&pre_buf);
  } while (wait(&status) != pid);
  end_time = time(NULL);
  if ((status & 0377) != 0)
    fprintf(stderr, "Command terminated abnormally.\n");
  times(&post_buf);
  printf("real ");
  print_time(end_time - start_time);
  printf("\nuser ");
  print_time(post_buf.tms_cutime - pre_buf.tms_cutime);
  printf("\nsys  ");
  print_time(post_buf.tms_cstime - pre_buf.tms_cstime);
  printf("\n");
  return ((status & 0377) ? -1 : (status >> 8));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11b7 <main+0x27>
xor    %edi,%edi
call   1090 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
jge    11f8 <main+0x68>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x48(%rbp)
jne    1240 <main+0xb0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1080 <execvp@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    1245 <main+0xb5>
lea    -0x20(%rbp),%rdi
call   1070 <times@plt>
lea    -0x44(%rbp),%rdi
call   10a0 <wait@plt>
cmp    -0x48(%rbp),%eax
jne    1245 <main+0xb5>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x40(%rbp)
mov    -0x44(%rbp),%eax
and    $0xff,%eax
cmp    $0x0,%eax
je     1295 <main+0x105>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x30(%rbp),%rdi
call   1070 <times@plt>
lea    0xd9b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x40(%rbp),%rdi
sub    -0x38(%rbp),%rdi
call   1060 <print_time@plt>
lea    0xd88(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
sub    -0x18(%rbp),%rdi
call   1060 <print_time@plt>
lea    0xd76(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
sub    -0x20(%rbp),%rdi
call   1060 <print_time@plt>
lea    0xd4e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
and    $0xff,%eax
cmp    $0x0,%eax
je     1313 <main+0x183>
mov    $0xffffffff,%eax
mov    %eax,-0x4c(%rbp)
jmp    131c <main+0x18c>
mov    -0x44(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x1,%edi
je     12a8 <main+0x108>
mov    %rsi,%r14
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%r15
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
js     12af <main+0x10f>
je     12d0 <main+0x130>
mov    %eax,%ebx
lea    0x18(%rsp),%r14
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1080 <times@plt>
mov    %r12,%rdi
call   10b0 <wait@plt>
cmp    %ebx,%eax
jne    11f0 <main+0x50>
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%rbx
cmpb   $0x0,0x4(%rsp)
je     122c <main+0x8c>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0x8(%rsp),%rdi
call   1080 <times@plt>
lea    0xe03(%rip),%rdi
call   1040 <printf@plt>
sub    %r15,%rbx
mov    %rbx,%rdi
call   1070 <print_time@plt>
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
mov    0x10(%rsp),%rdi
sub    0x20(%rsp),%rdi
call   1070 <print_time@plt>
lea    0xdde(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
sub    0x18(%rsp),%rdi
call   1070 <print_time@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%eax
mov    %eax,%ecx
sar    $0x8,%ecx
neg    %al
sbb    %eax,%eax
or     %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0x8(%r14),%rsi
mov    0x8(%r14),%rdi
call   1090 <execvp@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xd1c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.tms = type { i64, i64 }
@stderr = global i32 0
@.str = [13 x i8] c"Cannot fork\0A\00"
@.str.1 = [19 x i8] c"Cannot execute %s\0A\00"
@.str.2 = [32 x i8] c"Command terminated abnormally.\0A\00"
@.str.3 = [6 x i8] c"real \00"
@.str.4 = [7 x i8] c"\0Auser \00"
@.str.5 = [7 x i8] c"\0Asys \00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.tms
%7 = alloca %struct.tms
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = call i64 @time(i32* null)
store i64 %17, i64* %8
%18 = call i32 (...) @fork()
store i32 %18, i32* %11
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16
%25 = load i32, i32* %11
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %40
27: ; preds = %24
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = call i32 @execvp(i8* %30, i8** %32)
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %24
br label %41
41: ; preds = %43, %40
%42 = call i32 @times(%struct.tms* %6)
br label %43
43: ; preds = %41
%44 = call i32 @wait(i32* %10)
%45 = load i32, i32* %11
%46 = icmp ne i32 %44, %45
br i1 %46, label %41, label %47
47: ; preds = %43
%48 = call i64 @time(i32* null)
store i64 %48, i64* %9
%49 = load i32, i32* %10
%50 = and i32 %49, 255
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %52, %47
%56 = call i32 @times(%struct.tms* %7)
%57 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%58 = load i64, i64* %9
%59 = load i64, i64* %8
%60 = sub nsw i64 %58, %59
%61 = call i32 @print_time(i64 %60)
%62 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%63 = getelementptr inbounds %struct.tms, %struct.tms* %7, i32 0, i32 1
%64 = load i64, i64* %63
%65 = getelementptr inbounds %struct.tms, %struct.tms* %6, i32 0, i32 1
%66 = load i64, i64* %65
%67 = sub nsw i64 %64, %66
%68 = call i32 @print_time(i64 %67)
%69 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%70 = getelementptr inbounds %struct.tms, %struct.tms* %7, i32 0, i32 0
%71 = load i64, i64* %70
%72 = getelementptr inbounds %struct.tms, %struct.tms* %6, i32 0, i32 0
%73 = load i64, i64* %72
%74 = sub nsw i64 %71, %73
%75 = call i32 @print_time(i64 %74)
%76 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%77 = load i32, i32* %10
%78 = and i32 %77, 255
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %55
br label %84
81: ; preds = %55
%82 = load i32, i32* %10
%83 = ashr i32 %82, 8
br label %84
84: ; preds = %81, %80
%85 = phi i32 [ -1, %80 ], [ %83, %81 ]
ret i32 %85
}

LLVM IR (-O2):
%struct.tms = type { i64, i64 }
@stderr = global i32 0
@.str = [13 x i8] c"Cannot fork\0A\00"
@.str.1 = [19 x i8] c"Cannot execute %s\0A\00"
@.str.2 = [32 x i8] c"Command terminated abnormally.\0A\00"
@.str.3 = [6 x i8] c"real \00"
@.str.4 = [7 x i8] c"\0Auser \00"
@.str.5 = [7 x i8] c"\0Asys \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.tms
%4 = alloca %struct.tms
%5 = alloca i32
%6 = bitcast %struct.tms* %3 to i8*
%7 = bitcast %struct.tms* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i32 %0, 1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = tail call i64 @time(i32* null)
%14 = tail call i32 (...) @fork()
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = icmp eq i32 %14, 0
br i1 %21, label %22, label %30
22: ; preds = %20
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @execvp(i8* %24, i8** %23)
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %23
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = tail call i32 @exit(i32 -1)
unreachable
30: ; preds = %20, %30
%31 = call i32 @times(%struct.tms* %3)
%32 = call i32 @wait(i32* %5)
%33 = icmp eq i32 %32, %14
br i1 %33, label %34, label %30
34: ; preds = %30
%35 = call i64 @time(i32* null)
%36 = load i32, i32* %5
%37 = and i32 %36, 255
%38 = icmp eq i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %39, %34
%43 = call i32 @times(%struct.tms* %4)
%44 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%45 = sub nsw i64 %35, %13
%46 = call i32 @print_time(i64 %45)
%47 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%48 = getelementptr inbounds %struct.tms, %struct.tms* %4, i64 0, i32 1
%49 = load i64, i64* %48
%50 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 1
%51 = load i64, i64* %50
%52 = sub nsw i64 %49, %51
%53 = call i32 @print_time(i64 %52)
%54 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%55 = getelementptr inbounds %struct.tms, %struct.tms* %4, i64 0, i32 0
%56 = load i64, i64* %55
%57 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 0
%58 = load i64, i64* %57
%59 = sub nsw i64 %56, %58
%60 = call i32 @print_time(i64 %59)
%61 = call i32 @putchar(i32 10)
%62 = load i32, i32* %5
%63 = and i32 %62, 255
%64 = icmp eq i32 %63, 0
%65 = ashr i32 %62, 8
%66 = select i1 %64, i32 %65, i32 -1
ret i32 %66
}