#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ pr_exit(int);
int /*<<< orphan*/ pr_times(int, struct tms *, struct tms *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int system(char *);
int times(struct tms *);
void do_cmd(char *cmd) {
  struct tms tmsstart, tmsend;
  clock_t start, end;
  int status;
  printf("\ncommand: %s\n", cmd);
  if ((start = times(&tmsstart)) == -1) {
    fprintf(stderr, "times error\n");
    exit(1);
  }
  if ((status = system(cmd)) < 0) {
    fprintf(stderr, "system() error\n");
    exit(1);
  }
  if ((end = times(&tmsend)) == -1) {
    fprintf(stderr, "times error\n");
    exit(1);
  }
  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    0xe79(%rip),%rdi
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1080 <times@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11c0 <do_cmd+0x50>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11f4 <do_cmd+0x84>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x18(%rbp),%rdi
call   1080 <times@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    1228 <do_cmd+0xb8>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%edi
sub    -0x1c(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <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   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xe80(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0x10(%rsp),%rdi
call   1080 <times@plt>
cmp    $0xffffffff,%eax
je     11d7 <do_cmd+0x67>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <system@plt>
test   %eax,%eax
js     11e9 <do_cmd+0x79>
mov    %eax,%ebx
lea    0x8(%rsp),%rdi
call   1080 <times@plt>
cmp    $0xffffffff,%eax
je     11d7 <do_cmd+0x67>
sub    %ebp,%eax
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1050 <pr_times@plt>
mov    %ebx,%edi
call   1070 <pr_exit@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
jmp    11f9 <do_cmd+0x89>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.tms = type { i32 }
@.str = [14 x i8] c"\0Acommand: %s\0A\00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"times error\0A\00"
@.str.2 = [16 x i8] c"system() error\0A\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 %16
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = load i8*, i8** %2
%18 = call i32 @system(i8* %17)
store i32 %18, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16
%25 = call i32 @times(%struct.tms* %4)
store i32 %25, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %24
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = sub nsw i32 %32, %33
%35 = call i32 @pr_times(i32 %34, %struct.tms* %3, %struct.tms* %4)
%36 = load i32, i32* %7
%37 = call i32 @pr_exit(i32 %36)
ret void
}

LLVM IR (-O2):
%struct.tms = type { i32 }
@.str = [14 x i8] c"\0Acommand: %s\0A\00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"times error\0A\00"
@.str.2 = [16 x i8] c"system() error\0A\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 %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = tail call i32 @system(i8* %0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = call i32 @times(%struct.tms* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = sub nsw i32 %21, %7
%29 = call i32 @pr_times(i32 %28, %struct.tms* %2, %struct.tms* %3)
%30 = call i32 @pr_exit(i32 %14)
ret void
}