#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 wait(int *);
int main(int argc, char *argv[]) {
  int i;
  for (i = 0; i < argc - 2; i++) {
    if (fork() == 0) {
      int j;
      for (j = 0; j < atoi(argv[i + 2]); j++) {
        printf("[child %d] step %d\n", i, j);
        sleep(1);
      }
      exit(i);
    }
  }
  for (i = 0; i < atoi(argv[1]); i++) {
    printf("[main] step %d\n", i);
    sleep(1);
  }
  pid_t pid;
  int status;
  for (i = 0; i < argc - 2; i++) {
    pid = wait(&status);
    printf(">\npid = %d\nstatus = %d\n", pid, WEXITSTATUS(status));
  }
  printf("\nthe end\n");
  return 1;
}


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   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    1226 <main+0xb6>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    1213 <main+0xa3>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    120b <main+0x9b>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b6 <main+0x46>
mov    -0x14(%rbp),%edi
call   1060 <exit@plt>
jmp    1218 <main+0xa8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x1d>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    1276 <main+0x106>
mov    -0x14(%rbp),%esi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122d <main+0xbd>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    12c9 <main+0x159>
lea    -0x20(%rbp),%rdi
call   1080 <wait@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    127d <main+0x10d>
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
lea    -0x2(%r14),%r12d
cmp    $0x3,%edi
jl     11b8 <main+0x38>
mov    %r12d,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     1255 <main+0xd5>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    11a0 <main+0x20>
mov    0x8(%r15),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    11f6 <main+0x76>
lea    0xe48(%rip),%rbx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
add    $0x1,%ebp
mov    0x8(%r15),%rdi
call   1060 <atoi@plt>
cmp    %eax,%ebp
jl     11d0 <main+0x50>
cmp    $0x3,%r14d
jl     1237 <main+0xb7>
lea    0xc(%rsp),%r14
lea    0xe1c(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1090 <wait@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%r12d
jne    1210 <main+0x90>
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%r15,%rbx,8),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    1299 <main+0x119>
lea    0xd96(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
add    $0x1,%ebp
mov    0x10(%r15,%rbx,8),%rdi
call   1060 <atoi@plt>
cmp    %eax,%ebp
jl     1270 <main+0xf0>
mov    %ebx,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"[child %d] step %d\0A\00"
@.str.1 = [16 x i8] c"[main] step %d\0A\00"
@.str.2 = [24 x i8] c">\0Apid = %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 i32
%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 = %41, %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 %44
15: ; preds = %10
%16 = call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %40
18: ; preds = %15
store i32 0, i32* %7
br label %19
19: ; preds = %34, %18
%20 = load i32, i32* %7
%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 @atoi(i8* %26)
%28 = icmp slt i32 %20, %27
br i1 %28, label %29, label %37
29: ; preds = %19
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %31)
%33 = call i32 @sleep(i32 1)
br label %34
34: ; preds = %29
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %19
37: ; preds = %19
%38 = load i32, i32* %6
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %15
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %10
44: ; preds = %10
store i32 0, i32* %6
br label %45
45: ; preds = %56, %44
%46 = load i32, i32* %6
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @atoi(i8* %49)
%51 = icmp slt i32 %46, %50
br i1 %51, label %52, label %59
52: ; preds = %45
%53 = load i32, i32* %6
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = call i32 @sleep(i32 1)
br label %56
56: ; preds = %52
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 1
store i32 %58, i32* %6
br label %45
59: ; preds = %45
store i32 0, i32* %6
br label %60
60: ; preds = %71, %59
%61 = load i32, i32* %6
%62 = load i32, i32* %4
%63 = sub nsw i32 %62, 2
%64 = icmp slt i32 %61, %63
br i1 %64, label %65, label %74
65: ; preds = %60
%66 = call i32 @wait(i32* %9)
store i32 %66, i32* %8
%67 = load i32, i32* %8
%68 = load i32, i32* %9
%69 = call i32 @WEXITSTATUS(i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %67, i32 %69)
br label %71
71: ; preds = %65
%72 = load i32, i32* %6
%73 = add nsw i32 %72, 1
store i32 %73, i32* %6
br label %60
74: ; preds = %60
%75 = 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 = [20 x i8] c"[child %d] step %d\0A\00"
@.str.1 = [16 x i8] c"[main] step %d\0A\00"
@.str.2 = [24 x i8] c">\0Apid = %d\0Astatus = %d\0A\00"
@str = [9 x i8] c"\0Athe end\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = add i32 %0, -2
%5 = icmp sgt i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %32, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %35, label %43
11: ; preds = %2, %32
%12 = phi i32 [ %33, %32 ], [ 0, %2 ]
%13 = tail call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %32
15: ; preds = %11
%16 = add nuw nsw i32 %12, 2
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %15, %22
%23 = phi i32 [ %26, %22 ], [ 0, %15 ]
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %23)
%25 = tail call i32 @sleep(i32 1)
%26 = add nuw nsw i32 %23, 1
%27 = load i8*, i8** %18
%28 = tail call i32 @atoi(i8* %27)
%29 = icmp slt i32 %26, %28
br i1 %29, label %22, label %30
30: ; preds = %22, %15
%31 = tail call i32 @exit(i32 %12)
unreachable
32: ; preds = %11
%33 = add nuw nsw i32 %12, 1
%34 = icmp eq i32 %33, %4
br i1 %34, label %6, label %11
35: ; preds = %6, %35
%36 = phi i32 [ %39, %35 ], [ 0, %6 ]
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = tail call i32 @sleep(i32 1)
%39 = add nuw nsw i32 %36, 1
%40 = load i8*, i8** %7
%41 = tail call i32 @atoi(i8* %40)
%42 = icmp slt i32 %39, %41
br i1 %42, label %35, label %43
43: ; preds = %35, %6
%44 = bitcast i32* %3 to i8*
br i1 %5, label %45, label %53
45: ; preds = %43, %45
%46 = phi i32 [ %51, %45 ], [ 0, %43 ]
%47 = call i32 @wait(i32* %3)
%48 = load i32, i32* %3
%49 = call i32 @WEXITSTATUS(i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %47, i32 %49)
%51 = add nuw nsw i32 %46, 1
%52 = icmp eq i32 %51, %4
br i1 %52, label %53, label %45
53: ; preds = %45, %43
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
ret i32 1
}