#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 scalar_t__ clock_t;

/* Variables and functions */
int /*<<< orphan*/ err_sys(char *, ...);
int /*<<< orphan*/ pr_exit(int);
int /*<<< orphan*/ pr_times(scalar_t__, struct tms *, struct tms *);
int /*<<< orphan*/ printf(char *, char const *);
int system(char const *);
scalar_t__ times(struct tms *);
void do_cmd(const char *cmd) {
  int status;
  struct tms tstart, tend;
  clock_t start, end;
  printf("\ncommand: '%s'\n", cmd);
  if ((start = times(&tstart)) < 0) {
    err_sys("tms error");
  }
  if ((status = system(cmd)) < 0) {
    err_sys("error on system(%s)", cmd);
  }
  if ((end = times(&tend)) < 0) {
    err_sys("tms error");
  }
  pr_times(end - start, &tstart, &tend);
  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    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    11a1 <do_cmd+0x41>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
mov    -0x8(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11c8 <do_cmd+0x68>
mov    -0x8(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
lea    -0x18(%rbp),%rdi
call   1080 <times@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    11ed <do_cmd+0x8d>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
mov    -0x28(%rbp),%rdi
sub    -0x20(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <pr_times@plt>
mov    -0xc(%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,%rbx
lea    0xe8e(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0x8(%rsp),%rdi
call   1080 <times@plt>
mov    %rax,%r14
test   %rax,%rax
jns    119a <do_cmd+0x3a>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1030 <err_sys@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11b9 <do_cmd+0x59>
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <err_sys@plt>
mov    %rsp,%rdi
call   1080 <times@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    11d7 <do_cmd+0x77>
lea    0xe40(%rip),%rdi
xor    %eax,%eax
call   1030 <err_sys@plt>
sub    %r14,%rbx
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
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 = [16 x i8] c"\0Acommand: '%s'\0A\00"
@.str.1 = [10 x i8] c"tms error\00"
@.str.2 = [20 x i8] c"error on system(%s)\00"
define void @do_cmd(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.tms
%5 = alloca %struct.tms
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = call i64 @times(%struct.tms* %4)
store i64 %10, i64* %6
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([10 x i8], [10 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* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i8*, i8** %2
%20 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %14
%22 = call i64 @times(%struct.tms* %5)
store i64 %22, i64* %7
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = load i64, i64* %7
%28 = load i64, i64* %6
%29 = sub nsw i64 %27, %28
%30 = call i32 @pr_times(i64 %29, %struct.tms* %4, %struct.tms* %5)
%31 = load i32, i32* %3
%32 = call i32 @pr_exit(i32 %31)
ret void
}

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