#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__ pid_t;
typedef double clock_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ _SC_CLK_TCK;
int /*<<< orphan*/ execvp(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
double sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ times(struct tms *);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  struct tms before, after;
  pid_t pid;
  int status;
  if (argc < 2) {
    fprintf(stderr, "Usage: ctime cmd...\n");
    return EXIT_FAILURE;
  }
  (void)times(&before);
  pid = fork();
  if (pid == 0) {
    (void)execvp(argv[1], argv + 1);
    perror(argv[1]);
    return EXIT_FAILURE;
  }
  if (pid == (pid_t)(-1)) {
    perror(argv[1]);
    return EXIT_FAILURE;
  }
  waitpid(pid, &status, 0);
  (void)times(&after);
  {
    clock_t CLK_TCK = sysconf(_SC_CLK_TCK);
    double u = (double)after.tms_cutime - (double)before.tms_cutime;
    double s = (double)after.tms_cstime - (double)before.tms_cstime;
    u /= CLK_TCK;
    s /= CLK_TCK;
    fprintf(stderr, "%.3f user + %.3f system = %.3f total seconds.\n", u, s,
            u + s);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b8 <main+0x48>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e5 <main+0x175>
lea    -0x20(%rbp),%rdi
call   1050 <times@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    120a <main+0x9a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1080 <execvp@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <perror@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e5 <main+0x175>
cmpq   $0xffffffffffffffff,-0x38(%rbp)
jne    1233 <main+0xc3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <perror@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e5 <main+0x175>
mov    -0x38(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
lea    -0x30(%rbp),%rdi
call   1050 <times@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
movsd  %xmm0,-0x48(%rbp)
cvtsi2sdq -0x28(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdq -0x30(%rbp),%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
movsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
addsd  -0x58(%rbp),%xmm2
lea    0xd43(%rip),%rsi
mov    $0x3,%al
call   1030 <fprintf@plt>
mov    0x2ce8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
cmp    $0x1,%edi
jg     119d <main+0x2d>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e38(%rip),%rax
jmp    1271 <main+0x101>
mov    %rsi,%rbx
lea    0x20(%rsp),%rdi
call   1050 <times@plt>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffffffffffff,%rax
je     1286 <main+0x116>
test   %rax,%rax
je     1279 <main+0x109>
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <waitpid@plt>
lea    0x10(%rsp),%rdi
call   1050 <times@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
movdqa 0x10(%rsp),%xmm2
movq   %xmm2,%rax
cvtsi2sd %rax,%xmm1
pshufd $0xee,%xmm2,%xmm2
movq   %xmm2,%rax
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
unpcklpd %xmm2,%xmm1
movdqa 0x20(%rsp),%xmm2
movq   %xmm2,%rax
cvtsi2sd %rax,%xmm3
pshufd $0xee,%xmm2,%xmm2
movq   %xmm2,%rax
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
unpcklpd %xmm2,%xmm3
subpd  %xmm3,%xmm1
unpcklpd %xmm0,%xmm0
divpd  %xmm0,%xmm1
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
lea    0xdb2(%rip),%rsi
mov    $0x3,%al
call   1030 <fprintf@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0x8(%rbx),%rsi
mov    0x8(%rbx),%rdi
call   1080 <execvp@plt>
mov    0x8(%rbx),%rdi
call   1060 <perror@plt>
mov    0x2d3a(%rip),%rax
jmp    1271 <main+0x101>

LLVM IR (-O0):
%struct.tms = type { i64, i64 }
@stderr = global i32 0
@.str = [21 x i8] c"Usage: ctime cmd...\0A\00"
@EXIT_FAILURE = global i32 0
@_SC_CLK_TCK = global i32 0
@.str.1 = [47 x i8] c"%.3f user + %.3f system = %.3f total seconds.\0A\00"
@EXIT_SUCCESS = global i32 0
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 i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %79
19: ; preds = %2
%20 = call i32 @times(%struct.tms* %6)
%21 = call i64 (...) @fork()
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %19
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = call i32 @execvp(i8* %27, i8** %29)
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @perror(i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %79
36: ; preds = %19
%37 = load i64, i64* %8
%38 = icmp eq i64 %37, -1
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @perror(i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %3
br label %79
45: ; preds = %36
%46 = load i64, i64* %8
%47 = call i32 @waitpid(i64 %46, i32* %9, i32 0)
%48 = call i32 @times(%struct.tms* %7)
%49 = load i32, i32* @_SC_CLK_TCK
%50 = call double @sysconf(i32 %49)
store double %50, double* %10
%51 = getelementptr inbounds %struct.tms, %struct.tms* %7, i32 0, i32 1
%52 = load i64, i64* %51
%53 = sitofp i64 %52 to double
%54 = getelementptr inbounds %struct.tms, %struct.tms* %6, i32 0, i32 1
%55 = load i64, i64* %54
%56 = sitofp i64 %55 to double
%57 = fsub double %53, %56
store double %57, double* %11
%58 = getelementptr inbounds %struct.tms, %struct.tms* %7, i32 0, i32 0
%59 = load i64, i64* %58
%60 = sitofp i64 %59 to double
%61 = getelementptr inbounds %struct.tms, %struct.tms* %6, i32 0, i32 0
%62 = load i64, i64* %61
%63 = sitofp i64 %62 to double
%64 = fsub double %60, %63
store double %64, double* %12
%65 = load double, double* %10
%66 = load double, double* %11
%67 = fdiv double %66, %65
store double %67, double* %11
%68 = load double, double* %10
%69 = load double, double* %12
%70 = fdiv double %69, %68
store double %70, double* %12
%71 = load i32, i32* @stderr
%72 = load double, double* %11
%73 = load double, double* %12
%74 = load double, double* %11
%75 = load double, double* %12
%76 = fadd double %74, %75
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), double %72, double %73, double %76)
%78 = load i32, i32* @EXIT_SUCCESS
store i32 %78, i32* %3
br label %79
79: ; preds = %45, %39, %24, %15
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
%struct.tms = type { i64, i64 }
@stderr = global i32 0
@.str = [21 x i8] c"Usage: ctime cmd...\0A\00"
@EXIT_FAILURE = global i32 0
@_SC_CLK_TCK = global i32 0
@.str.1 = [47 x i8] c"%.3f user + %.3f system = %.3f total seconds.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca <2 x i64>
%4 = alloca <2 x i64>
%5 = bitcast <2 x i64>* %4 to %struct.tms*
%6 = alloca i32
%7 = bitcast <2 x i64>* %3 to i8*
%8 = bitcast <2 x i64>* %4 to i8*
%9 = bitcast i32* %6 to i8*
%10 = icmp slt i32 %0, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %46
14: ; preds = %2
%15 = bitcast <2 x i64>* %3 to %struct.tms*
%16 = call i32 @times(%struct.tms* %15)
%17 = tail call i64 (...) @fork()
switch i64 %17, label %28 [
i64 0, label %18
i64 -1, label %24
]
18: ; preds = %14
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32 @execvp(i8* %20, i8** %19)
%22 = load i8*, i8** %19
%23 = tail call i32 @perror(i8* %22)
br label %46
24: ; preds = %14
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = tail call i32 @perror(i8* %26)
br label %46
28: ; preds = %14
%29 = call i32 @waitpid(i64 %17, i32* %6, i32 0)
%30 = call i32 @times(%struct.tms* %5)
%31 = load i32, i32* @_SC_CLK_TCK
%32 = call double @sysconf(i32 %31)
%33 = load <2 x i64>, <2 x i64>* %4
%34 = sitofp <2 x i64> %33 to <2 x double>
%35 = load <2 x i64>, <2 x i64>* %3
%36 = sitofp <2 x i64> %35 to <2 x double>
%37 = fsub <2 x double> %34, %36
%38 = insertelement <2 x double> poison, double %32, i64 0
%39 = shufflevector <2 x double> %38, <2 x double> poison, <2 x i32> zeroinitializer
%40 = fdiv <2 x double> %37, %39
%41 = load i32, i32* @stderr
%42 = extractelement <2 x double> %40, i64 0
%43 = extractelement <2 x double> %40, i64 1
%44 = fadd double %43, %42
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), double %43, double %42, double %44)
br label %46
46: ; preds = %28, %24, %18, %11
%47 = phi i32* [ @EXIT_FAILURE, %11 ], [ @EXIT_FAILURE, %18 ], [ @EXIT_FAILURE, %24 ], [ @EXIT_SUCCESS, %28 ]
%48 = load i32, i32* %47
ret i32 %48
}