#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fib(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc != 2) {
    if (argc == 1) {
      fprintf(stderr, "No argument\n");
      exit(1);
    } else {
      fprintf(stderr, "One argument only\n");
      exit(1);
    }
  }
  if (atoi(argv[1]) <= 0) {
    fprintf(stderr, "Only positive integers\n");
    exit(1);
  }
  int number = atoi(argv[1]);
  pid_t id, pid;
  id = fork();
  if (id < 0) {
    fprintf(stderr, "Fork Failed");
    return 1;
  } else if (id == 0) {
    printf("Child: The first %d numbers in the Fibonacci sequence are: ",
           atoi(argv[1]));
    fib(number);
    return 1;
  } else {
    wait(NULL);
    printf("\nParent: The child process is done!\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)
je     11d8 <main+0x68>
cmpl   $0x1,-0x8(%rbp)
jne    11b9 <main+0x49>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
cmp    $0x0,%eax
jg     120d <main+0x9d>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1254 <main+0xe4>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b3 <main+0x143>
cmpq   $0x0,-0x20(%rbp)
jne    1290 <main+0x120>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <fib@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b3 <main+0x143>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ac <main+0x13c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    120c <main+0x8c>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
jle    1223 <main+0xa3>
mov    %eax,%ebp
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     11c7 <main+0x47>
je     11de <main+0x5e>
xor    %ebx,%ebx
xor    %edi,%edi
call   1090 <wait@plt>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
jmp    1203 <main+0x83>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11fe <main+0x7e>
mov    0x8(%rbx),%rdi
call   1070 <atoi@plt>
lea    0xe56(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <fib@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2dcd(%rip),%rax
cmp    $0x1,%edi
jne    1235 <main+0xb5>
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
jmp    123e <main+0xbe>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
jmp    123e <main+0xbe>
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"No argument\0A\00"
@.str.1 = [19 x i8] c"One argument only\0A\00"
@.str.2 = [24 x i8] c"Only positive integers\0A\00"
@.str.3 = [12 x i8] c"Fork Failed\00"
@.str.4 = [60 x i8] c"Child: The first %d numbers in the Fibonacci sequence are: \00"
@.str.5 = [37 x i8] c"\0AParent: The child process is done!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
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 %22
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
%27 = icmp sle i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %22
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %6
%37 = call i64 (...) @fork()
store i64 %37, i64* %7
%38 = load i64, i64* %7
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %32
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %59
43: ; preds = %32
%44 = load i64, i64* %7
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @atoi(i8* %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %6
%53 = call i32 @fib(i32 %52)
store i32 1, i32* %3
br label %59
54: ; preds = %43
%55 = call i32 @wait(i32* null)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %54
br label %58
58: ; preds = %57
store i32 0, i32* %3
br label %59
59: ; preds = %58, %46, %40
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"No argument\0A\00"
@.str.1 = [19 x i8] c"One argument only\0A\00"
@.str.2 = [24 x i8] c"Only positive integers\0A\00"
@.str.3 = [12 x i8] c"Fork Failed\00"
@.str.4 = [60 x i8] c"Child: The first %d numbers in the Fibonacci sequence are: \00"
@str = [36 x i8] c"\0AParent: The child process is done!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %7 [
i32 2, label %11
i32 1, label %3
]
3: ; preds = %2
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = tail call i64 (...) @fork()
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %36
26: ; preds = %20
%27 = icmp eq i64 %21, 0
br i1 %27, label %28, label %33
28: ; preds = %26
%29 = load i8*, i8** %12
%30 = tail call i32 @atoi(i8* %29)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = tail call i32 @fib(i32 %14)
br label %36
33: ; preds = %26
%34 = tail call i32 @wait(i32* null)
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %36
36: ; preds = %33, %28, %23
%37 = phi i32 [ 1, %23 ], [ 1, %28 ], [ 0, %33 ]
ret i32 %37
}