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

/* Variables and functions */
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ pr_exit(int);
int /*<<< orphan*/ pr_times(int, struct tms *, struct tms *);
int /*<<< orphan*/ printf(char *, char const *);
int system(char const *);
int times(struct tms *);
void do_cmd(const char *cmd) {
  struct tms tmsstart, tmsend;
  clock_t start, end;
  int status;
  printf("\ncommand: %s\n", cmd);
  if ((start = times(&tmsstart)) == -1)
    err_sys("times error");
  if ((status = system(cmd)) < 0)
    err_sys("system error");
  if ((end = times(&tmsend)) == -1)
    err_sys("times error");
  pr_times(end - start, &tmsstart, &tmsend);
  pr_exit(status);
}


x86 assembly (clang, -O0):
<do_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe89(%rip),%rdi
call   1050 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1080 <times@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    119d <do_cmd+0x3d>
lea    0xe76(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x8(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11be <do_cmd+0x5e>
lea    0xe61(%rip),%rdi
call   1030 <err_sys@plt>
lea    -0x18(%rbp),%rdi
call   1080 <times@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    11df <do_cmd+0x7f>
lea    0xe34(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x20(%rbp),%edi
sub    -0x1c(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <pr_times@plt>
mov    -0x24(%rbp),%edi
call   1070 <pr_exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_cmd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbp
lea    0xe8e(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
lea    0x8(%rsp),%rdi
call   1080 <times@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    1198 <do_cmd+0x38>
lea    0xe7b(%rip),%rdi
call   1030 <err_sys@plt>
mov    %rbp,%rdi
call   1040 <system@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11b2 <do_cmd+0x52>
lea    0xe6d(%rip),%rdi
call   1030 <err_sys@plt>
mov    %rsp,%rdi
call   1080 <times@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11cd <do_cmd+0x6d>
lea    0xe46(%rip),%rdi
call   1030 <err_sys@plt>
sub    %r14d,%ebx
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1060 <pr_times@plt>
mov    %ebp,%edi
call   1070 <pr_exit@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tms = type { i32 }
@.str = [14 x i8] c"\0Acommand: %s\0A\00"
@.str.1 = [12 x i8] c"times error\00"
@.str.2 = [13 x i8] c"system error\00"
define void @do_cmd(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tms
%4 = alloca %struct.tms
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = call i32 @times(%struct.tms* %3)
store i32 %10, i32* %5
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = load i8*, i8** %2
%16 = call i32 @system(i8* %15)
store i32 %16, i32* %7
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = call i32 @times(%struct.tms* %4)
store i32 %21, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = sub nsw i32 %26, %27
%29 = call i32 @pr_times(i32 %28, %struct.tms* %3, %struct.tms* %4)
%30 = load i32, i32* %7
%31 = call i32 @pr_exit(i32 %30)
ret void
}

LLVM IR (-O2):
%struct.tms = type { i32 }
@.str = [14 x i8] c"\0Acommand: %s\0A\00"
@.str.1 = [12 x i8] c"times error\00"
@.str.2 = [13 x i8] c"system error\00"
define void @do_cmd(i8* %0) {
%2 = alloca %struct.tms
%3 = alloca %struct.tms
%4 = bitcast %struct.tms* %2 to i8*
%5 = bitcast %struct.tms* %3 to i8*
%6 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32 @times(%struct.tms* %2)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = tail call i32 @system(i8* %0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = call i32 @times(%struct.tms* %3)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = sub nsw i32 %17, %7
%23 = call i32 @pr_times(i32 %22, %struct.tms* %2, %struct.tms* %3)
%24 = call i32 @pr_exit(i32 %12)
ret void
}