#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*/ execl(char *, char *, char *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int wait(int *);
int main(int argc, char *argv[]) {
  int i;
  char argbuff[50];
  pid_t pid;
  int status;
  for (i = 0; i < argc - 2; i++) {
    if (fork() == 0) {
      sprintf(argbuff, "%d", i);
      execl("./pot", "pot", argbuff, argv[i + 2], NULL);
      perror("error");
    }
  }
  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    $0x60,%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    122e <main+0x9e>
mov    $0x0,%al
call   10b0 <fork@plt>
cmp    $0x0,%rax
jne    121b <main+0x8b>
lea    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe23(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x50(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe05(%rip),%rdi
lea    0xe00(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
call   1080 <execl@plt>
lea    0xdf3(%rip),%rdi
call   1050 <perror@plt>
jmp    1220 <main+0x90>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ad <main+0x1d>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
cmp    %ecx,%eax
jge    127e <main+0xee>
mov    -0x14(%rbp),%esi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1235 <main+0xa5>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    12d1 <main+0x141>
lea    -0x58(%rbp),%rdi
call   10a0 <wait@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x58(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x60(%rbp),%esi
mov    %eax,%edx
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1285 <main+0xf5>
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
lea    -0x2(%r14),%r12d
cmp    $0x3,%edi
jl     1223 <main+0x83>
mov    %r12d,%ebx
lea    0x10(%rsp),%rbp
xor    %r13d,%r13d
jmp    11d9 <main+0x39>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r13,%rbx
je     1223 <main+0x83>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jne    11d0 <main+0x30>
mov    %rbp,%rdi
lea    0xe11(%rip),%rsi
mov    %r13d,%edx
call   1080 <sprintf@plt>
mov    0x10(%r15,%r13,8),%rcx
lea    0xe00(%rip),%rdi
lea    0xdfb(%rip),%rsi
mov    %rbp,%rdx
xor    %r8d,%r8d
call   1090 <execl@plt>
lea    0xded(%rip),%rdi
call   1060 <perror@plt>
jmp    11d0 <main+0x30>
mov    0x8(%r15),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
jle    1266 <main+0xc6>
lea    0xdd8(%rip),%rbp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
add    $0x1,%ebx
mov    0x8(%r15),%rdi
call   1070 <atoi@plt>
cmp    %eax,%ebx
jl     1240 <main+0xa0>
cmp    $0x3,%r14d
jl     12a7 <main+0x107>
lea    0xc(%rsp),%r14
lea    0xda7(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10b0 <wait@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%r12d
jne    1280 <main+0xe0>
lea    0xd87(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"./pot\00"
@.str.2 = [4 x i8] c"pot\00"
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [16 x i8] c"[main] step %d\0A\00"
@.str.5 = [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 [50 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [50 x i8], [50 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 %9, label %11
9: ; preds = %2
%10 = zext i32 %7 to i64
br label %16
11: ; preds = %28, %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %32, label %31
16: ; preds = %9, %28
%17 = phi i64 [ 0, %9 ], [ %29, %28 ]
%18 = call i64 (...) @fork()
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = trunc i64 %17 to i32
%22 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i64 %17, 2
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @execl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %25, i32* null)
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %16, %20
%29 = add nuw nsw i64 %17, 1
%30 = icmp eq i64 %29, %10
br i1 %30, label %11, label %16
31: ; preds = %32, %11
br i1 %8, label %40, label %48
32: ; preds = %11, %32
%33 = phi i32 [ %36, %32 ], [ 0, %11 ]
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = call i32 @sleep(i32 1)
%36 = add nuw nsw i32 %33, 1
%37 = load i8*, i8** %12
%38 = call i32 @atoi(i8* %37)
%39 = icmp slt i32 %36, %38
br i1 %39, label %32, label %31
40: ; preds = %31, %40
%41 = phi i32 [ %46, %40 ], [ 0, %31 ]
%42 = call i32 @wait(i32* %4)
%43 = load i32, i32* %4
%44 = call i32 @WEXITSTATUS(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %42, i32 %44)
%46 = add nuw nsw i32 %41, 1
%47 = icmp eq i32 %46, %7
br i1 %47, label %48, label %40
48: ; preds = %40, %31
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
ret i32 1
}