#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int atoi(char *);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int wait(int *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("\nusage: %s possitive_integer\n\n", argv[0]);
    exit(0);
  } else if (atoi(argv[1]) < 0) {
    printf("\nusage: %s possitive_integer", argv[0]);
    printf("\ninteger argument must be possitive!\n\n");
  } else {
    int number = atoi(argv[1]);
    int status;
    pid_t pid;
    pid = fork();
    if (pid == -1) {
      fprintf(stderr, "can't fork, error %d\n", errno);
      exit(EXIT_FAILURE);
    }
    if (pid == 0) {
      long fibseq[number];
      long fib0 = 0;
      long fib1 = 1;
      int i;
      for (i = 0; i <= number; i++) {
        long fibcurr = fib0;
        fib0 = fib1;
        fib1 = fibcurr + fib1;
        fibseq[i] = fibcurr;
      }
      for (i = 0; i <= number; i++) {
        printf("%ld ", fibseq[i]);
      }
      printf("\n");
      _exit(0);
    } else {
      if ((pid = wait(&status)) == -1) {
        printf("ERROR: Parent should be waiting.");
      }
      exit(0);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     11a5 <main+0x35>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
cmp    $0x0,%eax
jge    11e3 <main+0x73>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    133b <main+0x1cb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1233 <main+0xc3>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1311 <main+0x1a1>
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x1,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     12c1 <main+0x151>
mov    -0x58(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,-0x50(%rbp)
mov    -0x40(%rbp),%rcx
mov    %rcx,-0x38(%rbp)
mov    -0x50(%rbp),%rcx
add    -0x40(%rbp),%rcx
mov    %rcx,-0x40(%rbp)
mov    -0x50(%rbp),%rdx
movslq -0x44(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    127b <main+0x10b>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     12fc <main+0x18c>
mov    -0x58(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12c8 <main+0x158>
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
lea    -0x18(%rbp),%rdi
call   1080 <wait@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1334 <main+0x1c4>
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    1340 <main+0x1d0>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11e0 <main+0x50>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jns    11f8 <main+0x68>
mov    (%rbx),%rsi
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeac(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     1237 <main+0xa7>
cmp    $0xffffffff,%eax
jne    126b <main+0xdb>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
lea    0xe18(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %r15d,%edx
mov    %rsp,%r12
lea    0xf(,%rdx,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
add    $0x1,%rdx
mov    %edx,%r8d
and    $0x3,%r8d
cmp    $0x3,%r15d
jae    128e <main+0xfe>
mov    $0x1,%ecx
xor    %edi,%edi
xor    %esi,%esi
jmp    12c6 <main+0x136>
lea    -0x24(%rbp),%rdi
call   10a0 <wait@plt>
cmp    $0xffffffff,%eax
jne    1287 <main+0xf7>
lea    0xdd7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
and    $0xfffffffc,%edx
mov    $0x1,%ecx
xor    %edi,%edi
xor    %esi,%esi
lea    (%rcx,%rsi,1),%rbx
mov    %rsi,(%r12,%rdi,8)
lea    (%rbx,%rcx,1),%rax
mov    %rcx,0x8(%r12,%rdi,8)
lea    (%rax,%rbx,1),%rsi
mov    %rbx,0x10(%r12,%rdi,8)
lea    (%rsi,%rax,1),%rcx
mov    %rax,0x18(%r12,%rdi,8)
add    $0x4,%rdi
cmp    %rdi,%rdx
jne    129a <main+0x10a>
test   %r8,%r8
je     12e7 <main+0x157>
lea    (%r12,%rdi,8),%rdx
xor    %edi,%edi
mov    %rcx,%rbx
add    %rsi,%rcx
mov    %rsi,(%rdx,%rdi,8)
add    $0x1,%rdi
mov    %rbx,%rsi
cmp    %rdi,%r8
jne    12d1 <main+0x141>
add    $0x1,%r15d
lea    0xd60(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%rbx,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1300 <main+0x170>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"\0Ausage: %s possitive_integer\0A\0A\00"
@.str.1 = [29 x i8] c"\0Ausage: %s possitive_integer\00"
@.str.2 = [39 x i8] c"\0Ainteger argument must be possitive!\0A\0A\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"can't fork, error %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [5 x i8] c"%ld \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [33 x i8] c"ERROR: Parent should be waiting.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %97
34: ; preds = %22
%35 = load i8**, i8*** %4
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %5
%39 = call i32 (...) @fork()
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %48
42: ; preds = %34
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %34
%49 = load i32, i32* %7
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %90
51: ; preds = %48
%52 = load i32, i32* %5
%53 = zext i32 %52 to i64
%54 = call i8* @llvm.stacksave()
store i8* %54, i8** %8
%55 = alloca i64, i64 %53
store i64 %53, i64* %9
store i64 0, i64* %10
store i64 1, i64* %11
store i32 0, i32* %12
br label %56
56: ; preds = %70, %51
%57 = load i32, i32* %12
%58 = load i32, i32* %5
%59 = icmp sle i32 %57, %58
br i1 %59, label %60, label %73
60: ; preds = %56
%61 = load i64, i64* %10
store i64 %61, i64* %13
%62 = load i64, i64* %11
store i64 %62, i64* %10
%63 = load i64, i64* %13
%64 = load i64, i64* %11
%65 = add nsw i64 %63, %64
store i64 %65, i64* %11
%66 = load i64, i64* %13
%67 = load i32, i32* %12
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i64, i64* %55, i64 %68
store i64 %66, i64* %69
br label %70
70: ; preds = %60
%71 = load i32, i32* %12
%72 = add nsw i32 %71, 1
store i32 %72, i32* %12
br label %56
73: ; preds = %56
store i32 0, i32* %12
br label %74
74: ; preds = %84, %73
%75 = load i32, i32* %12
%76 = load i32, i32* %5
%77 = icmp sle i32 %75, %76
br i1 %77, label %78, label %87
78: ; preds = %74
%79 = load i32, i32* %12
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i64, i64* %55, i64 %80
%82 = load i64, i64* %81
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %82)
br label %84
84: ; preds = %78
%85 = load i32, i32* %12
%86 = add nsw i32 %85, 1
store i32 %86, i32* %12
br label %74
87: ; preds = %74
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%89 = call i32 @_exit(i32 0)
unreachable
90: ; preds = %48
%91 = call i32 @wait(i32* %6)
store i32 %91, i32* %7
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %95
93: ; preds = %90
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %95
95: ; preds = %93, %90
%96 = call i32 @exit(i32 0)
unreachable
97: ; preds = %28
br label %98
98: ; preds = %97
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"\0Ausage: %s possitive_integer\0A\0A\00"
@.str.1 = [29 x i8] c"\0Ausage: %s possitive_integer\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"can't fork, error %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [5 x i8] c"%ld \00"
@.str.6 = [33 x i8] c"ERROR: Parent should be waiting.\00"
@str = [38 x i8] c"\0Ainteger argument must be possitive!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 0)
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 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i8*, i8** %1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
ret i32 0
18: ; preds = %9
%19 = bitcast i32* %3 to i8*
%20 = tail call i32 (...) @fork()
switch i32 %20, label %84 [
i32 -1, label %21
i32 0, label %27
]
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %18
%28 = zext i32 %12 to i64
%29 = alloca i64, i64 %28
%30 = add nuw i32 %12, 1
%31 = zext i32 %30 to i64
%32 = add nsw i64 %31, -1
%33 = and i64 %31, 3
%34 = icmp ult i64 %32, 3
br i1 %34, label %37, label %35
35: ; preds = %27
%36 = and i64 %31, 4294967292
br label %55
37: ; preds = %55, %27
%38 = phi i64 [ 0, %27 ], [ %71, %55 ]
%39 = phi i64 [ 1, %27 ], [ %69, %55 ]
%40 = phi i64 [ 0, %27 ], [ %66, %55 ]
%41 = icmp eq i64 %33, 0
br i1 %41, label %52, label %42
42: ; preds = %37, %42
%43 = phi i64 [ %49, %42 ], [ %38, %37 ]
%44 = phi i64 [ %47, %42 ], [ %39, %37 ]
%45 = phi i64 [ %44, %42 ], [ %40, %37 ]
%46 = phi i64 [ %50, %42 ], [ 0, %37 ]
%47 = add nsw i64 %44, %45
%48 = getelementptr inbounds i64, i64* %29, i64 %43
store i64 %45, i64* %48
%49 = add nuw nsw i64 %43, 1
%50 = add i64 %46, 1
%51 = icmp eq i64 %50, %33
br i1 %51, label %52, label %42
52: ; preds = %42, %37
%53 = add i32 %12, 1
%54 = zext i32 %53 to i64
br label %74
55: ; preds = %55, %35
%56 = phi i64 [ 0, %35 ], [ %71, %55 ]
%57 = phi i64 [ 1, %35 ], [ %69, %55 ]
%58 = phi i64 [ 0, %35 ], [ %66, %55 ]
%59 = phi i64 [ 0, %35 ], [ %72, %55 ]
%60 = add nsw i64 %57, %58
%61 = getelementptr inbounds i64, i64* %29, i64 %56
store i64 %58, i64* %61
%62 = or i64 %56, 1
%63 = add nsw i64 %60, %57
%64 = getelementptr inbounds i64, i64* %29, i64 %62
store i64 %57, i64* %64
%65 = or i64 %56, 2
%66 = add nsw i64 %63, %60
%67 = getelementptr inbounds i64, i64* %29, i64 %65
store i64 %60, i64* %67
%68 = or i64 %56, 3
%69 = add nsw i64 %66, %63
%70 = getelementptr inbounds i64, i64* %29, i64 %68
store i64 %63, i64* %70
%71 = add nuw nsw i64 %56, 4
%72 = add i64 %59, 4
%73 = icmp eq i64 %72, %36
br i1 %73, label %37, label %55
74: ; preds = %52, %74
%75 = phi i64 [ 0, %52 ], [ %79, %74 ]
%76 = getelementptr inbounds i64, i64* %29, i64 %75
%77 = load i64, i64* %76
%78 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %77)
%79 = add nuw nsw i64 %75, 1
%80 = icmp eq i64 %79, %54
br i1 %80, label %81, label %74
81: ; preds = %74
%82 = tail call i32 @putchar(i32 10)
%83 = tail call i32 @_exit(i32 0)
unreachable
84: ; preds = %18
%85 = call i32 @wait(i32* %3)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %89
87: ; preds = %84
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %89
89: ; preds = %87, %84
%90 = call i32 @exit(i32 0)
unreachable
}