#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 */

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main(int c, char **v) {
  while (--c > 1 && !fork())
    ;
  sleep(c = atoi(v[c]));
  printf("%d\n", c);
  wait(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x11(%rbp)
jle    118f <main+0x3f>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    119f <main+0x4f>
jmp    11a4 <main+0x54>
jmp    1166 <main+0x16>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <atoi@plt>
mov    %eax,%edi
mov    %edi,-0x8(%rbp)
call   1050 <sleep@plt>
mov    -0x8(%rbp),%esi
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
cmp    $0x2,%edi
mov    $0x2,%ebx
cmovl  %edi,%ebx
add    $0xffffffff,%ebx
nopw   0x0(%rax,%rax,1)
cmp    $0x3,%ebp
jl     1185 <main+0x35>
xor    %eax,%eax
call   1070 <fork@plt>
add    $0xffffffff,%ebp
test   %eax,%eax
je     1170 <main+0x20>
jmp    1187 <main+0x37>
mov    %ebx,%ebp
movslq %ebp,%rax
mov    (%r14,%rax,8),%rdi
call   1040 <atoi@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <sleep@plt>
lea    0xe5d(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %6
6: ; preds = %16, %2
%7 = load i32, i32* %4
%8 = add nsw i32 %7, -1
store i32 %8, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = call i32 (...) @fork()
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br label %14
14: ; preds = %10, %6
%15 = phi i1 [ false, %6 ], [ %13, %10 ]
br i1 %15, label %16, label %17
16: ; preds = %14
br label %6
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %4
%24 = call i32 @sleep(i32 %23)
%25 = load i32, i32* %4
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = call i32 @wait(i32 0)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = call i32 @llvm.smin.i32(i32 %0, i32 2)
%4 = add i32 %3, -1
br label %5
5: ; preds = %9, %2
%6 = phi i32 [ %0, %2 ], [ %7, %9 ]
%7 = add nsw i32 %6, -1
%8 = icmp sgt i32 %6, 2
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = tail call i32 (...) @fork()
%11 = icmp eq i32 %10, 0
br i1 %11, label %5, label %12
12: ; preds = %5, %9
%13 = phi i32 [ %4, %5 ], [ %7, %9 ]
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = tail call i32 @sleep(i32 %17)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%20 = tail call i32 @wait(i32 0)
ret i32 0
}