#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 pid_t;

/* Variables and functions */
int atoi(char *);
int fork();
int /*<<< orphan*/ pattern(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("Not enough command-line arguments\n");
    return -1;
  }
  int num = atoi(argv[1]);
  if (num <= 0) {
    printf("Positive number needed\n");
    return -1;
  }
  pid_t child = fork();
  if (child == -1) {
    printf("Child fork failed\n");
    return -1;
  } else if (child == 0) {
    pattern(num);
    return 0;
  } else {
    wait(NULL);
    printf("\n");
  }
}


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)
jge    1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121e <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     11ba <main+0x6a>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121e <main+0xce>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11e6 <main+0x96>
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121e <main+0xce>
cmpl   $0x0,-0x18(%rbp)
jne    1204 <main+0xb4>
mov    -0x14(%rbp),%edi
call   1040 <pattern@plt>
movl   $0x0,-0x4(%rbp)
jmp    121e <main+0xce>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
jmp    121e <main+0xce>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1171 <main+0x11>
lea    0xeba(%rip),%rdi
jmp    11a2 <main+0x42>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    119b <main+0x3b>
mov    %eax,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11b5 <main+0x55>
cmp    $0xffffffff,%eax
jne    11be <main+0x5e>
lea    0xe67(%rip),%rdi
jmp    11a2 <main+0x42>
lea    0xe70(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebp,%edi
call   1050 <pattern@plt>
jmp    11ac <main+0x4c>
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <wait@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11ac <main+0x4c>

LLVM IR (-O0):
@.str = [35 x i8] c"Not enough command-line arguments\0A\00"
@.str.1 = [24 x i8] c"Positive number needed\0A\00"
@.str.2 = [19 x i8] c"Child fork failed\0A\00"
@.str.3 = [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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
12: ; preds = %2
%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 = load i32, i32* %6
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
21: ; preds = %12
%22 = call i32 (...) @fork()
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
27: ; preds = %21
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %6
%32 = call i32 @pattern(i32 %31)
store i32 0, i32* %3
br label %37
33: ; preds = %27
%34 = call i32 @wait(i32* null)
%35 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %33
br label %37
37: ; preds = %10, %19, %25, %30, %36
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@str = [18 x i8] c"Child fork failed\00"
@str.4 = [23 x i8] c"Positive number needed\00"
@str.5 = [34 x i8] c"Not enough command-line arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.5, i64 0, i64 0))
br label %22
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
br label %22
13: ; preds = %6
%14 = tail call i32 (...) @fork()
switch i32 %14, label %19 [
i32 -1, label %15
i32 0, label %17
]
15: ; preds = %13
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %22
17: ; preds = %13
%18 = tail call i32 @pattern(i32 %9)
br label %22
19: ; preds = %13
%20 = tail call i32 @wait(i32* null)
%21 = tail call i32 @putchar(i32 10)
br label %22
22: ; preds = %11, %19, %17, %15, %4
%23 = phi i32 [ -1, %4 ], [ -1, %11 ], [ -1, %15 ], [ 0, %17 ], [ 0, %19 ]
ret i32 %23
}