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

/* Variables and functions */
int WEXITSTATUS(int);
int atoi(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int, char *);
int /*<<< orphan*/ system(char *);
int wait(int *);
int main(int argc, char *argv[]) {
  int i;
  char systembuff[100];
  pid_t pid;
  int status;
  for (i = 0; i < argc - 2; i++) {
    if (fork() == 0) {
      sprintf(systembuff, "./pot %d %s", i, argv[i + 2]);
      system(systembuff);
      exit(i);
    }
  }
  for (i = 0; i < atoi(argv[1]); i++) {
    printf("[main] step %d\n", i);
    sleep(1);
  }
  for (i = 0; i < argc - 2; i++) {
    pid = wait(&status);
    printf("pid = %d\nstatus = %d\n", pid, WEXITSTATUS(status));
  }
  printf("\nthe end\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    121a <main+0x8a>
mov    $0x0,%al
call   10b0 <fork@plt>
cmp    $0x0,%rax
jne    1207 <main+0x77>
lea    -0x80(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe0f(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x80(%rbp),%rdi
call   1030 <system@plt>
mov    -0x14(%rbp),%edi
call   1080 <exit@plt>
jmp    120c <main+0x7c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b0 <main+0x20>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x8c(%rbp),%eax
cmp    %ecx,%eax
jge    1270 <main+0xe0>
mov    -0x14(%rbp),%esi
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1221 <main+0x91>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    12d5 <main+0x145>
lea    -0x88(%rbp),%rdi
call   10a0 <wait@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x90(%rbp)
mov    -0x88(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    -0x90(%rbp),%esi
mov    %eax,%edx
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1277 <main+0xe7>
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
lea    -0x2(%r14),%r12d
cmp    $0x3,%edi
jl     11d8 <main+0x38>
mov    %r12d,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
je     1274 <main+0xd4>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    11c0 <main+0x20>
mov    0x8(%r15),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
jle    1216 <main+0x76>
lea    0xe20(%rip),%rbx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
add    $0x1,%ebp
mov    0x8(%r15),%rdi
call   1070 <atoi@plt>
cmp    %eax,%ebp
jl     11f0 <main+0x50>
cmp    $0x3,%r14d
jl     1256 <main+0xb6>
mov    %rsp,%r14
lea    0xdf6(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10b0 <wait@plt>
mov    %eax,%ebp
mov    (%rsp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%r12d
jne    1230 <main+0x90>
lea    0xdd5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%r15,%rbx,8),%rcx
lea    0xd80(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %ebx,%edx
call   1080 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <system@plt>
mov    %ebx,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"./pot %d %s\00"
@.str.1 = [16 x i8] c"[main] step %d\0A\00"
@.str.2 = [22 x i8] c"pid = %d\0Astatus = %d\0A\00"
@.str.3 = [10 x i8] c"\0Athe end\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %10
10: ; preds = %33, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 2
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %36
15: ; preds = %10
%16 = call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %32
18: ; preds = %15
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%20 = load i32, i32* %6
%21 = load i8**, i8*** %5
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %21, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %26)
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%29 = call i32 @system(i8* %28)
%30 = load i32, i32* %6
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %15
br label %33
33: ; preds = %32
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %10
36: ; preds = %10
store i32 0, i32* %6
br label %37
37: ; preds = %48, %36
%38 = load i32, i32* %6
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @atoi(i8* %41)
%43 = icmp slt i32 %38, %42
br i1 %43, label %44, label %51
44: ; preds = %37
%45 = load i32, i32* %6
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = call i32 @sleep(i32 1)
br label %48
48: ; preds = %44
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %37
51: ; preds = %37
store i32 0, i32* %6
br label %52
52: ; preds = %63, %51
%53 = load i32, i32* %6
%54 = load i32, i32* %4
%55 = sub nsw i32 %54, 2
%56 = icmp slt i32 %53, %55
br i1 %56, label %57, label %66
57: ; preds = %52
%58 = call i32 @wait(i32* %9)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = load i32, i32* %9
%61 = call i32 @WEXITSTATUS(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %59, i32 %61)
br label %63
63: ; preds = %57
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %52
66: ; preds = %52
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [12 x i8] c"./pot %d %s\00"
@.str.1 = [16 x i8] c"[main] step %d\0A\00"
@.str.2 = [22 x i8] c"pid = %d\0Astatus = %d\0A\00"
@str = [9 x i8] c"\0Athe end\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = add i32 %0, -2
%8 = icmp sgt i32 %0, 2
br i1 %8, label %14, label %9
9: ; preds = %26, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %30, label %29
14: ; preds = %2, %26
%15 = phi i32 [ %27, %26 ], [ 0, %2 ]
%16 = tail call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = add nuw nsw i32 %15, 2
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %22)
%24 = call i32 @system(i8* %5)
%25 = tail call i32 @exit(i32 %15)
unreachable
26: ; preds = %14
%27 = add nuw nsw i32 %15, 1
%28 = icmp eq i32 %27, %7
br i1 %28, label %9, label %14
29: ; preds = %30, %9
br i1 %8, label %38, label %46
30: ; preds = %9, %30
%31 = phi i32 [ %34, %30 ], [ 0, %9 ]
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = tail call i32 @sleep(i32 1)
%34 = add nuw nsw i32 %31, 1
%35 = load i8*, i8** %10
%36 = tail call i32 @atoi(i8* %35)
%37 = icmp slt i32 %34, %36
br i1 %37, label %30, label %29
38: ; preds = %29, %38
%39 = phi i32 [ %44, %38 ], [ 0, %29 ]
%40 = call i32 @wait(i32* %4)
%41 = load i32, i32* %4
%42 = call i32 @WEXITSTATUS(i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %40, i32 %42)
%44 = add nuw nsw i32 %39, 1
%45 = icmp eq i32 %44, %7
br i1 %45, label %46, label %38
46: ; preds = %38, %29
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
ret i32 1
}