#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 timeval {
  int dummy;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int atoi(char *);
scalar_t__ fork();
scalar_t__ getpid();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  struct timeval startTime;
  struct timeval endTime;
  pid_t childs[50];
  int childNum = 0;
  gettimeofday(&startTime, NULL);
  if (argc < 3) {
    printf("Usage : ./test threadNum commandStr\n");
    return 1;
  }
  printf("command is %s\n", argv[2]);
  childNum = atoi(argv[1]);
  int i = 0;
  for (i = 0; i < childNum; i++) {
    childs[i] = fork();
    if (childs[i] == 0) {
      printf(" I am in child process %ld\n", (long)getpid());
      system(argv[2]);
      return 0;
    }
  }
  for (i = 0; i < childNum; i++) {
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1b4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
cmpl   $0x3,-0x8(%rbp)
jge    11b4 <main+0x54>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129f <main+0x13f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1b4(%rbp)
movl   $0x0,-0x1b8(%rbp)
movl   $0x0,-0x1b8(%rbp)
mov    -0x1b8(%rbp),%eax
cmp    -0x1b4(%rbp),%eax
jge    127c <main+0x11c>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,%rcx
movslq -0x1b8(%rbp),%rax
mov    %rcx,-0x1b0(%rbp,%rax,8)
ff
movslq -0x1b8(%rbp),%rax
cmpq   $0x0,-0x1b0(%rbp,%rax,8)
jne    1263 <main+0x103>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
jmp    129f <main+0x13f>
jmp    1268 <main+0x108>
mov    -0x1b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
jmp    11f1 <main+0x91>
movl   $0x0,-0x1b8(%rbp)
mov    -0x1b8(%rbp),%eax
cmp    -0x1b4(%rbp),%eax
jge    129f <main+0x13f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
cmp    $0x2,%ebp
jg     11a3 <main+0x33>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    1208 <main+0x98>
mov    0x10(%r14),%rsi
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jle    1208 <main+0x98>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11e5 <main+0x75>
add    $0xffffffff,%ebp
jne    11d0 <main+0x60>
xor    %ebx,%ebx
jmp    1208 <main+0x98>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe1a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%r14),%rdi
call   1050 <system@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [37 x i8] c"Usage : ./test threadNum commandStr\0A\00"
@.str.1 = [15 x i8] c"command is %s\0A\00"
@.str.2 = [28 x i8] c" I am in child process %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca [50 x i64]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%11 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %59
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %9
store i32 0, i32* %10
store i32 0, i32* %10
br label %25
25: ; preds = %47, %16
%26 = load i32, i32* %10
%27 = load i32, i32* %9
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %50
29: ; preds = %25
%30 = call i64 (...) @fork()
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [50 x i64], [50 x i64]* %8, i64 0, i64 %32
store i64 %30, i64* %33
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [50 x i64], [50 x i64]* %8, i64 0, i64 %35
%37 = load i64, i64* %36
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %29
%40 = call i64 (...) @getpid()
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %40)
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 @system(i8* %44)
store i32 0, i32* %3
br label %59
46: ; preds = %29
br label %47
47: ; preds = %46
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
br label %25
50: ; preds = %25
store i32 0, i32* %10
br label %51
51: ; preds = %56, %50
%52 = load i32, i32* %10
%53 = load i32, i32* %9
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %59
55: ; preds = %51
store i32 0, i32* %3
br label %59
56: ; No predecessors!
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 1
store i32 %58, i32* %10
br label %51
59: ; preds = %14, %39, %55, %51
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str.1 = [15 x i8] c"command is %s\0A\00"
@.str.2 = [28 x i8] c" I am in child process %ld\0A\00"
@str = [36 x i8] c"Usage : ./test threadNum commandStr\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %29
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %19, label %29
17: ; preds = %19
%18 = icmp eq i32 %23, %15
br i1 %18, label %29, label %19
19: ; preds = %9, %17
%20 = phi i32 [ %23, %17 ], [ 0, %9 ]
%21 = tail call i64 (...) @fork()
%22 = icmp eq i64 %21, 0
%23 = add nuw nsw i32 %20, 1
br i1 %22, label %24, label %17
24: ; preds = %19
%25 = tail call i64 (...) @getpid()
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %25)
%27 = load i8*, i8** %10
%28 = tail call i32 @system(i8* %27)
br label %29
29: ; preds = %17, %9, %24, %7
%30 = phi i32 [ 1, %7 ], [ 0, %24 ], [ 0, %9 ], [ 0, %17 ]
ret i32 %30
}