#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 func3(int c, char **v) {
  while (--c > 1 && !fork())
    ;
  int val = atoi(v[c]);
  sleep(val);
  printf("%d\n", val);
  return 0;
}


x86 assembly (clang, -O0):
<func3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x15(%rbp)
jle    1178 <func3+0x38>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1188 <func3+0x48>
jmp    118d <func3+0x4d>
jmp    114f <func3+0xf>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <sleep@plt>
mov    -0x14(%rbp),%esi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func3>:
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     1175 <func3+0x35>
xor    %eax,%eax
call   1060 <fork@plt>
add    $0xffffffff,%ebp
test   %eax,%eax
je     1160 <func3+0x20>
jmp    1177 <func3+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    0xe6d(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @func3(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
br label %6
6: ; preds = %16, %2
%7 = load i32, i32* %3
%8 = add nsw i32 %7, -1
store i32 %8, i32* %3
%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*** %4
%19 = load i32, i32* %3
%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* %5
%24 = load i32, i32* %5
%25 = call i32 @sleep(i32 %24)
%26 = load i32, i32* %5
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @func3(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)
ret i32 0
}