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

/* Variables and functions */
int /*<<< orphan*/ do_cmd(char *);
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ pr_exit(int);
int /*<<< orphan*/ pr_times(int, struct tms *, struct tms *);
int /*<<< orphan*/ printf(char *, ...);
int times(struct tms *);
int wait(int *);
int main(int argc, char *argv[]) {
  int i;
  int status;
  pid_t pid;
  struct tms start, stop;
  clock_t begin, end;
  for (i = 1; i < argc; i++)
    do_cmd(argv[i]);
  if ((begin = times(&start)) == -1)
    err_sys("times error");
  while (1) {
    pid = wait(&status);
    if (pid < 0) {
      printf("wait all children\n");
      break;
    }
    printf("wait child %d\n", pid);
    pr_exit(status);
    if ((end = times(&stop)) == -1)
      err_sys("times error");
    pr_times(end - begin, &start, &stop);
    printf("---------------------------------\n");
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c8 <main+0x48>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <do_cmd@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119d <main+0x1d>
lea    -0x20(%rbp),%rdi
call   1080 <times@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    11e9 <main+0x69>
lea    0xe1c(%rip),%rdi
call   1030 <err_sys@plt>
jmp    11ee <main+0x6e>
lea    -0x18(%rbp),%rdi
call   10a0 <wait@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1217 <main+0x97>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1277 <main+0xf7>
mov    -0x1c(%rbp),%esi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <pr_exit@plt>
lea    -0x28(%rbp),%rdi
call   1080 <times@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    1251 <main+0xd1>
lea    0xdb4(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x30(%rbp),%edi
sub    -0x2c(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <pr_times@plt>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ee <main+0x6e>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     11c2 <main+0x32>
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1,%ebx
nopl   (%rax)
mov    (%r14,%rbx,8),%rdi
call   1080 <do_cmd@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <main+0x20>
lea    0x8(%rsp),%rdi
call   1090 <times@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11df <main+0x4f>
lea    0xe26(%rip),%rdi
call   1040 <err_sys@plt>
lea    0x4(%rsp),%rdi
call   10b0 <wait@plt>
test   %eax,%eax
jns    1200 <main+0x70>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r12
lea    0xe0a(%rip),%r13
lea    0x4(%rsp),%r15
jmp    1245 <main+0xb5>
nopl   0x0(%rax,%rax,1)
sub    %ebp,%r14d
mov    %r14d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <pr_times@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   10b0 <wait@plt>
test   %eax,%eax
js     11ed <main+0x5d>
lea    0xdc0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
call   1070 <pr_exit@plt>
mov    %rbx,%rdi
call   1090 <times@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    1220 <main+0x90>
lea    0xd8b(%rip),%rdi
call   1040 <err_sys@plt>
jmp    1220 <main+0x90>

LLVM IR (-O0):
%struct.tms = type { i32 }
@.str = [12 x i8] c"times error\00"
@.str.1 = [19 x i8] c"wait all children\0A\00"
@.str.2 = [15 x i8] c"wait child %d\0A\00"
@.str.3 = [35 x i8] c"---------------------------------\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.tms
%10 = alloca %struct.tms
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %13
13: ; preds = %24, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 @do_cmd(i8* %22)
br label %24
24: ; preds = %17
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %13
27: ; preds = %13
%28 = call i32 @times(%struct.tms* %9)
store i32 %28, i32* %11
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
br label %33
33: ; preds = %32, %48
%34 = call i32 @wait(i32* %7)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %54
39: ; preds = %33
%40 = load i32, i32* %8
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %7
%43 = call i32 @pr_exit(i32 %42)
%44 = call i32 @times(%struct.tms* %10)
store i32 %44, i32* %12
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %48
48: ; preds = %46, %39
%49 = load i32, i32* %12
%50 = load i32, i32* %11
%51 = sub nsw i32 %49, %50
%52 = call i32 @pr_times(i32 %51, %struct.tms* %9, %struct.tms* %10)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %33
54: ; preds = %37
%55 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.tms = type { i32 }
@.str = [12 x i8] c"times error\00"
@.str.2 = [15 x i8] c"wait child %d\0A\00"
@str = [34 x i8] c"---------------------------------\00"
@str.4 = [18 x i8] c"wait all children\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.tms
%5 = alloca %struct.tms
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.tms* %4 to i8*
%8 = bitcast %struct.tms* %5 to i8*
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 1, %10 ], [ %17, %12 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i32 @do_cmd(i8* %15)
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %11
br i1 %18, label %19, label %12
19: ; preds = %12, %2
%20 = call i32 @times(%struct.tms* %4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = call i32 @wait(i32* %3)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %39, %24
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %24, %39
%31 = phi i32 [ %43, %39 ], [ %25, %24 ]
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %3
%34 = call i32 @pr_exit(i32 %33)
%35 = call i32 @times(%struct.tms* %5)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %39
39: ; preds = %37, %30
%40 = sub nsw i32 %35, %20
%41 = call i32 @pr_times(i32 %40, %struct.tms* %4, %struct.tms* %5)
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%43 = call i32 @wait(i32* %3)
%44 = icmp slt i32 %43, 0
br i1 %44, label %27, label %30
}