#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*/ 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");
  if ((status = system(cmd)) < 0)
    fprintf(stderr, "system() error");
  if ((end = times(&tmsend)) == -1)
    fprintf(stderr, "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   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1080 <times@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11a6 <do_cmd+0x46>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11d0 <do_cmd+0x70>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1060 <fprintf@plt>
lea    -0x18(%rbp),%rdi
call   1080 <times@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    11fa <do_cmd+0x9a>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
call   1060 <fprintf@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   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbp
lea    0xe8e(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
call   1080 <times@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    11a1 <do_cmd+0x41>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1060 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <system@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11c4 <do_cmd+0x64>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1060 <fprintf@plt>
mov    %rsp,%rdi
call   1080 <times@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11e8 <do_cmd+0x88>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1060 <fprintf@plt>
sub    %r14d,%ebx
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <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"
@stderr = global i32 0
@.str.1 = [12 x i8] c"times error\00"
@.str.2 = [15 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 %15
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %1
%16 = load i8*, i8** %2
%17 = call i32 @system(i8* %16)
store i32 %17, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %19, %15
%23 = call i32 @times(%struct.tms* %4)
store i32 %23, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %6
%30 = load i32, i32* %5
%31 = sub nsw i32 %29, %30
%32 = call i32 @pr_times(i32 %31, %struct.tms* %3, %struct.tms* %4)
%33 = load i32, i32* %7
%34 = call i32 @pr_exit(i32 %33)
ret void
}

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