#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 /*<<< orphan*/ EXIT_FAILURE;
int WCONTINUED;
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ WIFSIGNALED(int);
int WUNTRACED;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
scalar_t__ getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int waitpid(int, int *, int);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("No child`s count! \n");
    exit(EXIT_FAILURE);
  }
  int i;
  for (i = 0; i < atoi(argv[1]); i++) {
    int status;
    int cpid = fork();
    if (cpid == -1) {
      perror("fork");
      exit(EXIT_FAILURE);
    }
    if (cpid == 0) {
      printf("Child PID is %ld\n", (long)getpid());
      exit(0);
    } else {
      do {
        int w = waitpid(cpid, &status, WUNTRACED | WCONTINUED);
      } while (!WIFEXITED(status) && !WIFSIGNALED(status));
    }
  }
  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)
je     11cc <main+0x3c>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    12be <main+0x12e>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1221 <main+0x91>
lea    0xe06(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    124a <main+0xba>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    124f <main+0xbf>
mov    -0x1c(%rbp),%edi
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
mov    0x2d66(%rip),%rax
or     (%rax),%edx
lea    -0x18(%rbp),%rsi
call   1060 <waitpid@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1090 <WIFEXITED@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
jne    129b <main+0x10b>
mov    -0x18(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    124f <main+0xbf>
jmp    12ab <main+0x11b>
jmp    12b0 <main+0x120>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d3 <main+0x43>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1287 <main+0xe7>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jle    123d <main+0x9d>
mov    0x2e15(%rip),%r15
mov    0x2df6(%rip),%r12
lea    0x4(%rsp),%rbx
xor    %r13d,%r13d
jmp    11f2 <main+0x52>
nopl   0x0(%rax)
add    $0x1,%r13d
mov    0x8(%r14),%rdi
call   1090 <atoi@plt>
cmp    %eax,%r13d
jge    123d <main+0x9d>
xor    %eax,%eax
call   10c0 <fork@plt>
cmp    $0xffffffff,%eax
je     124e <main+0xae>
mov    %eax,%ebp
test   %eax,%eax
je     1268 <main+0xc8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%edx
or     (%r15),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <waitpid@plt>
mov    0x4(%rsp),%edi
call   10a0 <WIFEXITED@plt>
test   %eax,%eax
jne    11e0 <main+0x40>
mov    0x4(%rsp),%edi
call   1060 <WIFSIGNALED@plt>
test   %eax,%eax
je     1210 <main+0x70>
jmp    11e0 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdab(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xd8f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd89(%rip),%rdi
call   1030 <puts@plt>
jmp    125a <main+0xba>

LLVM IR (-O0):
@.str = [20 x i8] c"No child`s count! \0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [18 x i8] c"Child PID is %ld\0A\00"
@WUNTRACED = global i32 0
@WCONTINUED = global i32 0
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
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
store i32 0, i32* %6
br label %17
17: ; preds = %59, %16
%18 = load i32, i32* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = icmp slt i32 %18, %22
br i1 %23, label %24, label %62
24: ; preds = %17
%25 = call i32 (...) @fork()
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %24
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = call i64 (...) @getpid()
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %36)
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %32
br label %40
40: ; preds = %55, %39
%41 = load i32, i32* %8
%42 = load i32, i32* @WUNTRACED
%43 = load i32, i32* @WCONTINUED
%44 = or i32 %42, %43
%45 = call i32 @waitpid(i32 %41, i32* %7, i32 %44)
store i32 %45, i32* %9
br label %46
46: ; preds = %40
%47 = load i32, i32* %7
%48 = call i32 @WIFEXITED(i32 %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %46
%51 = load i32, i32* %7
%52 = call i32 @WIFSIGNALED(i32 %51)
%53 = icmp ne i32 %52, 0
%54 = xor i1 %53, true
br label %55
55: ; preds = %50, %46
%56 = phi i1 [ false, %46 ], [ %54, %50 ]
br i1 %56, label %40, label %57
57: ; preds = %55
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
br label %17
62: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [18 x i8] c"Child PID is %ld\0A\00"
@WUNTRACED = global i32 0
@WCONTINUED = global i32 0
@str = [19 x i8] c"No child`s count! \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = call i32 @atoi(i8* %7)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %44
10: ; preds = %5
%11 = bitcast i32* %3 to i8*
br label %16
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %10, %39
%17 = phi i32 [ 0, %10 ], [ %40, %39 ]
%18 = call i32 (...) @fork()
switch i32 %18, label %27 [
i32 -1, label %19
i32 0, label %23
]
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %16
%24 = call i64 (...) @getpid()
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %24)
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %16, %35
%28 = load i32, i32* @WUNTRACED
%29 = load i32, i32* @WCONTINUED
%30 = or i32 %29, %28
%31 = call i32 @waitpid(i32 %18, i32* %3, i32 %30)
%32 = load i32, i32* %3
%33 = call i32 @WIFEXITED(i32 %32)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %27
%36 = load i32, i32* %3
%37 = call i32 @WIFSIGNALED(i32 %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %27, label %39
39: ; preds = %27, %35
%40 = add nuw nsw i32 %17, 1
%41 = load i8*, i8** %6
%42 = call i32 @atoi(i8* %41)
%43 = icmp slt i32 %40, %42
br i1 %43, label %16, label %44
44: ; preds = %39, %5
ret i32 0
}