#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 atoi(char *);
int execvp(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ wait(int *);
int main(int argc, char **ARGV) {
  int status = atoi(ARGV[1]);
  int kuasdr;
  int l, i;
  int result;
  pid_t pid;
  char *string[] = {"/bin/sleep", "20", NULL};
  for (l = 0; l < status; l++) {
    pid = fork();
    if (pid < 0) {
      perror("fork");
    } else if (pid == 0) {
      result = execvp("/bin/sleep", string);
      if (result < 0) {
        perror("execvp");
        return 2;
      }
      return 1;
    }
  }
  for (i = 0; i < status; i++) {
    wait(&kuasdr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    0x2c83(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c80(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c7d(%rip),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1235 <main+0xe5>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    11d1 <main+0x81>
lea    0xe47(%rip),%rdi
call   1030 <perror@plt>
jmp    1222 <main+0xd2>
cmpq   $0x0,-0x30(%rbp)
jne    121d <main+0xcd>
lea    -0x50(%rbp),%rsi
lea    0xe19(%rip),%rdi
call   1040 <execvp@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1211 <main+0xc1>
lea    0xe13(%rip),%rdi
call   1030 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1266 <main+0x116>
movl   $0x1,-0x4(%rbp)
jmp    1266 <main+0x116>
jmp    1222 <main+0xd2>
jmp    1227 <main+0xd7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119e <main+0x4e>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125f <main+0x10f>
lea    -0x18(%rbp),%rdi
call   1060 <wait@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    123c <main+0xec>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebp
mov    0x2ca6(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0x2c8a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
test   %ebp,%ebp
jle    11af <main+0x5f>
lea    0xe88(%rip),%r14
mov    %ebp,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     11a5 <main+0x55>
je     11cf <main+0x7f>
add    $0xffffffff,%ebx
jne    1190 <main+0x40>
jmp    11b4 <main+0x64>
mov    %r14,%rdi
call   1030 <perror@plt>
jmp    119e <main+0x4e>
xor    %r14d,%r14d
jmp    11ea <main+0x9a>
xor    %r14d,%r14d
test   %ebp,%ebp
jle    11ea <main+0x9a>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <wait@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x70>
jmp    11ea <main+0x9a>
lea    0xe2a(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <execvp@plt>
mov    $0x1,%r14d
test   %eax,%eax
js     11f6 <main+0xa6>
mov    %r14d,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe16(%rip),%rdi
call   1030 <perror@plt>
mov    $0x2,%r14d
jmp    11ea <main+0x9a>

LLVM IR (-O0):
@.str = [11 x i8] c"/bin/sleep\00"
@.str.1 = [3 x i8] c"20\00"
@__const.main.string = [3 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [5 x i8] c"fork\00"
@.str.3 = [7 x i8] c"execvp\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
%10 = alloca i32
%11 = alloca i64
%12 = alloca [3 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
%17 = bitcast [3 x i8*]* %12 to i8*
store i32 0, i32* %8
br label %18
18: ; preds = %41, %2
%19 = load i32, i32* %8
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %44
22: ; preds = %18
%23 = call i64 (...) @fork()
store i64 %23, i64* %11
%24 = load i64, i64* %11
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %40
28: ; preds = %22
%29 = load i64, i64* %11
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %28
%32 = getelementptr inbounds [3 x i8*], [3 x i8*]* %12, i64 0, i64 0
%33 = call i32 @execvp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %32)
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %55
38: ; preds = %31
store i32 1, i32* %3
br label %55
39: ; preds = %28
br label %40
40: ; preds = %39, %26
br label %41
41: ; preds = %40
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %18
44: ; preds = %18
store i32 0, i32* %9
br label %45
45: ; preds = %51, %44
%46 = load i32, i32* %9
%47 = load i32, i32* %6
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %54
49: ; preds = %45
%50 = call i32 @wait(i32* %7)
br label %51
51: ; preds = %49
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
br label %45
54: ; preds = %45
store i32 0, i32* %3
br label %55
55: ; preds = %54, %38, %36
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [11 x i8] c"/bin/sleep\00"
@.str.1 = [3 x i8] c"20\00"
@__const.main.string = [3 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [5 x i8] c"fork\00"
@.str.3 = [7 x i8] c"execvp\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [3 x i8*]
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = bitcast i32* %3 to i8*
%9 = bitcast [3 x i8*]* %4 to i8*
%10 = icmp sgt i32 %7, 0
br i1 %10, label %12, label %34
11: ; preds = %26
br i1 %10, label %29, label %34
12: ; preds = %2, %26
%13 = phi i32 [ %27, %26 ], [ 0, %2 ]
%14 = tail call i64 (...) @fork()
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %26
18: ; preds = %12
%19 = icmp eq i64 %14, 0
br i1 %19, label %20, label %26
20: ; preds = %18
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%22 = call i32 @execvp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %34
26: ; preds = %16, %18
%27 = add nuw nsw i32 %13, 1
%28 = icmp eq i32 %27, %7
br i1 %28, label %11, label %12
29: ; preds = %11, %29
%30 = phi i32 [ %32, %29 ], [ 0, %11 ]
%31 = call i32 @wait(i32* %3)
%32 = add nuw nsw i32 %30, 1
%33 = icmp eq i32 %32, %7
br i1 %33, label %34, label %29
34: ; preds = %29, %2, %11, %20, %24
%35 = phi i32 [ 2, %24 ], [ 1, %20 ], [ 0, %11 ], [ 0, %2 ], [ 0, %29 ]
ret i32 %35
}