#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_stime;
  scalar_t__ tms_cutime;
  scalar_t__ tms_utime;
};
typedef int pid_t;
typedef scalar_t__ clock_t;

/* Variables and functions */
scalar_t__ WIFEXITED(int);
int _time_error(char *, int);
int _time_exec(char **);
int _time_print(scalar_t__, scalar_t__, scalar_t__);
int fork();
scalar_t__ times(struct tms *);
int waitpid(int, int *, int /*<<< orphan*/);
int _time(char *argv[]) {
  pid_t pid;
  int status;
  struct tms tmsbuf;
  clock_t cbefore, cafter;
  if ((cbefore = times(&tmsbuf)) == (clock_t)-1)
    return _time_error("times", 2);
  if ((pid = fork()) == -1)
    return _time_error("fork", 2);
  if (pid == 0)
    return _time_exec(argv);
  for (;;) {
    if (waitpid(pid, &status, 0) == -1)
      return _time_error("waitpid", 2);
    if (WIFEXITED(status))
      break;
  }
  if ((cafter = times(&tmsbuf)) == (clock_t)-1)
    return _time_error("times", 2);
  return _time_print(cafter - cbefore, tmsbuf.tms_utime + tmsbuf.tms_cutime,
                     tmsbuf.tms_stime + tmsbuf.tms_cstime);
}


x86 assembly (clang, -O0):
<_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
call   1070 <times@plt>
mov    %rax,-0x40(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    11ac <_time+0x3c>
lea    0xe66(%rip),%rdi
mov    $0x2,%esi
call   1030 <_time_error@plt>
mov    %eax,-0x4(%rbp)
jmp    1294 <_time+0x124>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11d8 <_time+0x68>
lea    0xe40(%rip),%rdi
mov    $0x2,%esi
call   1030 <_time_error@plt>
mov    %eax,-0x4(%rbp)
jmp    1294 <_time+0x124>
cmpl   $0x0,-0x14(%rbp)
jne    11f3 <_time+0x83>
mov    -0x10(%rbp),%rdi
call   1040 <_time_exec@plt>
mov    %eax,-0x4(%rbp)
jmp    1294 <_time+0x124>
jmp    11f8 <_time+0x88>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    1228 <_time+0xb8>
lea    0xdf5(%rip),%rdi
mov    $0x2,%esi
call   1030 <_time_error@plt>
mov    %eax,-0x4(%rbp)
jmp    1294 <_time+0x124>
mov    -0x18(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     123f <_time+0xcf>
jmp    1244 <_time+0xd4>
jmp    11f8 <_time+0x88>
lea    -0x38(%rbp),%rdi
call   1070 <times@plt>
mov    %rax,-0x48(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    1274 <_time+0x104>
lea    0xd9e(%rip),%rdi
mov    $0x2,%esi
call   1030 <_time_error@plt>
mov    %eax,-0x4(%rbp)
jmp    1294 <_time+0x124>
mov    -0x48(%rbp),%rdi
sub    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
add    -0x38(%rbp),%rdx
call   1050 <_time_print@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_time>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
call   1070 <times@plt>
cmp    $0xffffffffffffffff,%rax
je     11b4 <_time+0x44>
mov    %rax,%r15
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11bd <_time+0x4d>
mov    %eax,%ebp
test   %eax,%eax
jne    11d8 <_time+0x68>
mov    %r14,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <_time_exec@plt>
lea    0xe45(%rip),%rdi
jmp    11c4 <_time+0x54>
lea    0xe42(%rip),%rdi
mov    $0x2,%esi
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_time_error@plt>
lea    0x4(%rsp),%rbx
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
cmp    $0xffffffff,%eax
je     1230 <_time+0xc0>
mov    0x4(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
je     11e0 <_time+0x70>
lea    0x8(%rsp),%rdi
call   1070 <times@plt>
cmp    $0xffffffffffffffff,%rax
je     1239 <_time+0xc9>
sub    %r15,%rax
mov    0x8(%rsp),%rdx
mov    0x18(%rsp),%rsi
add    0x20(%rsp),%rsi
add    0x10(%rsp),%rdx
mov    %rax,%rdi
call   1050 <_time_print@plt>
jmp    124a <_time+0xda>
lea    0xdd4(%rip),%rdi
jmp    1240 <_time+0xd0>
lea    0xdc0(%rip),%rdi
mov    $0x2,%esi
call   1030 <_time_error@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tms = type { i64, i64, i64, i64 }
@.str = [6 x i8] c"times\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [8 x i8] c"waitpid\00"
define i32 @_time(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.tms
%7 = alloca i64
%8 = alloca i64
store i8** %0, i8*** %3
%9 = call i64 @times(%struct.tms* %6)
store i64 %9, i64* %7
%10 = icmp eq i64 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @_time_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 2)
store i32 %12, i32* %2
br label %57
13: ; preds = %1
%14 = call i32 (...) @fork()
store i32 %14, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @_time_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 2)
store i32 %17, i32* %2
br label %57
18: ; preds = %13
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8**, i8*** %3
%23 = call i32 @_time_exec(i8** %22)
store i32 %23, i32* %2
br label %57
24: ; preds = %18
br label %25
25: ; preds = %36, %24
%26 = load i32, i32* %4
%27 = call i32 @waitpid(i32 %26, i32* %5, i32 0)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @_time_error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 2)
store i32 %30, i32* %2
br label %57
31: ; preds = %25
%32 = load i32, i32* %5
%33 = call i64 @WIFEXITED(i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
br label %37
36: ; preds = %31
br label %25
37: ; preds = %35
%38 = call i64 @times(%struct.tms* %6)
store i64 %38, i64* %8
%39 = icmp eq i64 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @_time_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 2)
store i32 %41, i32* %2
br label %57
42: ; preds = %37
%43 = load i64, i64* %8
%44 = load i64, i64* %7
%45 = sub nsw i64 %43, %44
%46 = getelementptr inbounds %struct.tms, %struct.tms* %6, i32 0, i32 3
%47 = load i64, i64* %46
%48 = getelementptr inbounds %struct.tms, %struct.tms* %6, i32 0, i32 2
%49 = load i64, i64* %48
%50 = add nsw i64 %47, %49
%51 = getelementptr inbounds %struct.tms, %struct.tms* %6, i32 0, i32 1
%52 = load i64, i64* %51
%53 = getelementptr inbounds %struct.tms, %struct.tms* %6, i32 0, i32 0
%54 = load i64, i64* %53
%55 = add nsw i64 %52, %54
%56 = call i32 @_time_print(i64 %45, i64 %50, i64 %55)
store i32 %56, i32* %2
br label %57
57: ; preds = %42, %40, %29, %21, %16, %11
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
%struct.tms = type { i64, i64, i64, i64 }
@.str = [6 x i8] c"times\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [8 x i8] c"waitpid\00"
define i32 @_time(i8** %0) {
%2 = alloca i32
%3 = alloca %struct.tms
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.tms* %3 to i8*
%6 = call i64 @times(%struct.tms* %3)
%7 = icmp eq i64 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @_time_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 2)
br label %43
10: ; preds = %1
%11 = tail call i32 (...) @fork()
switch i32 %11, label %16 [
i32 -1, label %12
i32 0, label %14
]
12: ; preds = %10
%13 = tail call i32 @_time_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %43
14: ; preds = %10
%15 = tail call i32 @_time_exec(i8** %0)
br label %43
16: ; preds = %10, %21
%17 = call i32 @waitpid(i32 %11, i32* %2, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @_time_error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 2)
br label %43
21: ; preds = %16
%22 = load i32, i32* %2
%23 = call i64 @WIFEXITED(i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %16, label %25
25: ; preds = %21
%26 = call i64 @times(%struct.tms* %3)
%27 = icmp eq i64 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @_time_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 2)
br label %43
30: ; preds = %25
%31 = sub nsw i64 %26, %6
%32 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 3
%33 = load i64, i64* %32
%34 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 2
%35 = load i64, i64* %34
%36 = add nsw i64 %35, %33
%37 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 1
%38 = load i64, i64* %37
%39 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 0
%40 = load i64, i64* %39
%41 = add nsw i64 %40, %38
%42 = call i32 @_time_print(i64 %31, i64 %36, i64 %41)
br label %43
43: ; preds = %30, %28, %19, %14, %12, %8
%44 = phi i32 [ %9, %8 ], [ %13, %12 ], [ %15, %14 ], [ %20, %19 ], [ %29, %28 ], [ %42, %30 ]
ret i32 %44
}