#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  assert(argc == 2);
  int processCount, processCountRemaining, stat;
  sscanf(argv[1], "%d", &processCount);
  pid_t pid;
  processCountRemaining = processCount;
foo:
  pid = fork();
  processCountRemaining--;
  if (pid == 0) {
    printf("Started %d\n", processCount - processCountRemaining);
    if (processCountRemaining)
      goto foo;
  } else {
    waitpid(pid, &stat, 0);
    printf("Finished %d with status %d\n", processCount - processCountRemaining,
           stat);
  }
  return 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)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11dc <main+0x8c>
mov    -0x14(%rbp),%esi
sub    -0x18(%rbp),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
je     11d7 <main+0x87>
jmp    1195 <main+0x45>
jmp    1202 <main+0xb2>
mov    -0x28(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x14(%rbp),%esi
sub    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   1040 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0xe8f(%rip),%rsi
mov    %rsp,%rdx
call   1050 <sscanf@plt>
mov    $0x1,%ebx
sub    (%rsp),%ebx
lea    0xe7b(%rip),%r14
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    11b5 <main+0x65>
mov    (%rsp),%esi
add    %ebx,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0x1,%ebx
jne    1190 <main+0x40>
jmp    11db <main+0x8b>
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1060 <waitpid@plt>
add    (%rsp),%ebx
mov    0x4(%rsp),%edx
lea    0xe3d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [12 x i8] c"Started %d\0A\00"
@.str.2 = [28 x i8] c"Finished %d with status %d\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 i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%18 = load i32, i32* %6
store i32 %18, i32* %7
br label %19
19: ; preds = %32, %2
%20 = call i64 (...) @fork()
store i64 %20, i64* %9
%21 = load i32, i32* %7
%22 = add nsw i32 %21, -1
store i32 %22, i32* %7
%23 = load i64, i64* %9
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %19
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = sub nsw i32 %26, %27
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
br label %19
33: ; preds = %25
br label %42
34: ; preds = %19
%35 = load i64, i64* %9
%36 = call i32 @waitpid(i64 %35, i32* %8, i32 0)
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = sub nsw i32 %37, %38
%40 = load i32, i32* %8
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %39, i32 %40)
br label %42
42: ; preds = %34, %33
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [12 x i8] c"Started %d\0A\00"
@.str.2 = [28 x i8] c"Finished %d with status %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = icmp eq i32 %0, 2
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
br label %14
14: ; preds = %19, %2
%15 = phi i32 [ %13, %2 ], [ %17, %19 ]
%16 = call i64 (...) @fork()
%17 = add nsw i32 %15, -1
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, %17
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = icmp eq i32 %17, 0
br i1 %23, label %30, label %14
24: ; preds = %14
%25 = call i32 @waitpid(i64 %16, i32* %4, i32 0)
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, %17
%28 = load i32, i32* %4
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %28)
br label %30
30: ; preds = %19, %24
ret i32 0
}