#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 int /*<<< orphan*/ pid_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int *v, n, i, j;
  pid_t pid1, pid2;
  if (argc < 2) {
    fprintf(stdout, "Usage: %s <n>\n", argv[0]);
    exit(1);
  }
  n = atoi(argv[1]);
  v = (int *)malloc(n * sizeof(int));
  for (i = 0; i < n; i++) {
    if (fork()) {
      if (fork()) {
        wait((int *)0);
        wait((int *)0);
        exit(0);
      } else {
        v[i] = 0;
      }
    } else
      v[i] = 1;
  }
  for (j = 0; j < n; j++) {
    fprintf(stdout, "%d", v[j]);
  }
  fprintf(stdout, "\n");
  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)
jge    11a8 <main+0x48>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    124f <main+0xef>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
je     122d <main+0xcd>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
je     1219 <main+0xb9>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    123c <main+0xdc>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    1241 <main+0xe1>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d2 <main+0x72>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1292 <main+0x132>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1256 <main+0xf6>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
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    $0x1,%edi
jle    1243 <main+0xe3>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%edi
call   1040 <malloc@plt>
test   %r14d,%r14d
jle    121b <main+0xbb>
mov    %rax,%r15
mov    %r14d,%r12d
xor    %ebx,%ebx
jmp    11b2 <main+0x52>
mov    $0x1,%ebp
mov    %ebp,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
je     11e1 <main+0x81>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11a0 <main+0x40>
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11a5 <main+0x45>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1060 <exit@plt>
test   %r14d,%r14d
jle    121b <main+0xbb>
mov    0x2df3(%rip),%r13
lea    0xe1b(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    (%r15,%rbx,4),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1200 <main+0xa0>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdaa(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [15 x i8] c"Usage: %s <n>\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\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
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stdout
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 4
%29 = trunc i64 %28 to i32
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i32*
store i32* %31, i32** %6
store i32 0, i32* %8
br label %32
32: ; preds = %58, %21
%33 = load i32, i32* %8
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %61
36: ; preds = %32
%37 = call i64 (...) @fork()
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %52
39: ; preds = %36
%40 = call i64 (...) @fork()
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = call i32 @wait(i32* null)
%44 = call i32 @wait(i32* null)
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %39
%47 = load i32*, i32** %6
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
store i32 0, i32* %50
br label %51
51: ; preds = %46
br label %57
52: ; preds = %36
%53 = load i32*, i32** %6
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
store i32 1, i32* %56
br label %57
57: ; preds = %52, %51
br label %58
58: ; preds = %57
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %32
61: ; preds = %32
store i32 0, i32* %9
br label %62
62: ; preds = %74, %61
%63 = load i32, i32* %9
%64 = load i32, i32* %7
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %77
66: ; preds = %62
%67 = load i32, i32* @stdout
%68 = load i32*, i32** %6
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %68, i64 %70
%72 = load i32, i32* %71
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %66
%75 = load i32, i32* %9
%76 = add nsw i32 %75, 1
store i32 %76, i32* %9
br label %62
77: ; preds = %62
%78 = load i32, i32* @stdout
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [15 x i8] c"Usage: %s <n>\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stdout
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = shl i32 %12, 2
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
%16 = icmp sgt i32 %12, 0
br i1 %16, label %17, label %46
17: ; preds = %9
%18 = zext i32 %12 to i64
br label %22
19: ; preds = %33
br i1 %16, label %20, label %46
20: ; preds = %19
%21 = zext i32 %12 to i64
br label %38
22: ; preds = %17, %33
%23 = phi i64 [ 0, %17 ], [ %36, %33 ]
%24 = tail call i64 (...) @fork()
%25 = icmp eq i64 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %22
%27 = tail call i64 (...) @fork()
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = tail call i32 @wait(i32* null)
%31 = tail call i32 @wait(i32* null)
%32 = tail call i32 @exit(i32 0)
unreachable
33: ; preds = %22, %26
%34 = phi i32 [ 0, %26 ], [ 1, %22 ]
%35 = getelementptr inbounds i32, i32* %15, i64 %23
store i32 %34, i32* %35
%36 = add nuw nsw i64 %23, 1
%37 = icmp eq i64 %36, %18
br i1 %37, label %19, label %22
38: ; preds = %20, %38
%39 = phi i64 [ 0, %20 ], [ %44, %38 ]
%40 = load i32, i32* @stdout
%41 = getelementptr inbounds i32, i32* %15, i64 %39
%42 = load i32, i32* %41
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = add nuw nsw i64 %39, 1
%45 = icmp eq i64 %44, %21
br i1 %45, label %46, label %38
46: ; preds = %38, %9, %19
%47 = load i32, i32* @stdout
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}