#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 fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("usage: %s tests_count\n", argv[0]);
    return -1;
  }
  int tests = atoi(argv[1]), i;
  for (i = 0; i < tests; ++i) {
    int a;
    if (a = fork()) {
      fprintf(stderr, "spawned child %d\n", a);
    } else
      for (;;)
        ;
  }
}


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)
cmpl   $0x2,-0x8(%rbp)
je     117f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <main+0xaf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ef <main+0xaf>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11d2 <main+0x92>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe4f(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11dc <main+0x9c>
jmp    11d7 <main+0x97>
jmp    11d7 <main+0x97>
jmp    11e1 <main+0xa1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1196 <main+0x56>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11a2 <main+0x62>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
test   %eax,%eax
jle    118d <main+0x4d>
mov    %eax,%ebx
mov    0x2e80(%rip),%r15
lea    0xeb0(%rip),%r14
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11a0 <main+0x60>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
add    $0xffffffff,%ebx
jne    1170 <main+0x30>
xor    %eax,%eax
jmp    11b6 <main+0x76>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
jmp    11a0 <main+0x60>
mov    (%rsi),%rsi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"usage: %s tests_count\0A\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"spawned child %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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %38
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
store i32 0, i32* %7
br label %21
21: ; preds = %35, %16
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = call i32 (...) @fork()
store i32 %26, i32* %8
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = load i32, i32* %8
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %34
32: ; preds = %25
br label %33
33: ; preds = %33, %32
br label %33
34: ; preds = %28
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %21
38: ; preds = %11, %21
%39 = load i32, i32* %3
ret i32 %39
}

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