#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
jge    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
jge    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,%r14d
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     1237 <main+0xa7>
cmp    $0xffffffff,%eax
jne    1274 <main+0xe4>
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    %r14d,%r15d
mov    %rsp,%r12
lea    0xf(,%r15,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
test   %r14d,%r14d
je     1318 <main+0x188>
lea    -0x1(%r15),%rcx
mov    %r15d,%r8d
and    $0x3,%r8d
cmp    $0x3,%rcx
jae    1297 <main+0x107>
mov    $0x1,%ecx
xor    %esi,%esi
xor    %edx,%edx
jmp    12d2 <main+0x142>
lea    -0x24(%rbp),%rdi
call   10a0 <wait@plt>
cmp    $0xffffffff,%eax
jne    1290 <main+0x100>
lea    0xdce(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    %r15d,%edi
and    $0xfffffffc,%edi
mov    $0x1,%ecx
xor    %esi,%esi
xor    %edx,%edx
lea    (%rcx,%rdx,1),%rbx
mov    %rdx,(%r12,%rsi,8)
lea    (%rbx,%rcx,1),%rax
mov    %rcx,0x8(%r12,%rsi,8)
lea    (%rax,%rbx,1),%rdx
mov    %rbx,0x10(%r12,%rsi,8)
lea    (%rdx,%rax,1),%rcx
mov    %rax,0x18(%r12,%rsi,8)
add    $0x4,%rsi
cmp    %rsi,%rdi
jne    12a6 <main+0x116>
test   %r8,%r8
je     12f3 <main+0x163>
lea    (%r12,%rsi,8),%rsi
xor    %edi,%edi
mov    %rcx,%rbx
add    %rdx,%rcx
mov    %rdx,(%rsi,%rdi,8)
add    $0x1,%rdi
mov    %rbx,%rdx
cmp    %rdi,%r8
jne    12dd <main+0x14d>
test   %r14d,%r14d
je     1318 <main+0x188>
lea    0xd53(%rip),%r14
xor    %ebx,%ebx
mov    (%r12,%rbx,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1301 <main+0x171>
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 slt 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 slt 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 %82 [
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 = icmp eq i32 %12, 0
br i1 %30, label %79, label %31
31: ; preds = %27
%32 = add nsw i64 %28, -1
%33 = and i64 %28, 3
%34 = icmp ult i64 %32, 3
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = and i64 %28, 4294967292
br label %53
37: ; preds = %53, %31
%38 = phi i64 [ 0, %31 ], [ %69, %53 ]
%39 = phi i64 [ 1, %31 ], [ %67, %53 ]
%40 = phi i64 [ 0, %31 ], [ %64, %53 ]
%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
br i1 %30, label %79, label %72
53: ; preds = %53, %35
%54 = phi i64 [ 0, %35 ], [ %69, %53 ]
%55 = phi i64 [ 1, %35 ], [ %67, %53 ]
%56 = phi i64 [ 0, %35 ], [ %64, %53 ]
%57 = phi i64 [ 0, %35 ], [ %70, %53 ]
%58 = add nsw i64 %55, %56
%59 = getelementptr inbounds i64, i64* %29, i64 %54
store i64 %56, i64* %59
%60 = or i64 %54, 1
%61 = add nsw i64 %58, %55
%62 = getelementptr inbounds i64, i64* %29, i64 %60
store i64 %55, i64* %62
%63 = or i64 %54, 2
%64 = add nsw i64 %61, %58
%65 = getelementptr inbounds i64, i64* %29, i64 %63
store i64 %58, i64* %65
%66 = or i64 %54, 3
%67 = add nsw i64 %64, %61
%68 = getelementptr inbounds i64, i64* %29, i64 %66
store i64 %61, i64* %68
%69 = add nuw nsw i64 %54, 4
%70 = add i64 %57, 4
%71 = icmp eq i64 %70, %36
br i1 %71, label %37, label %53
72: ; preds = %52, %72
%73 = phi i64 [ %77, %72 ], [ 0, %52 ]
%74 = getelementptr inbounds i64, i64* %29, i64 %73
%75 = load i64, i64* %74
%76 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %75)
%77 = add nuw nsw i64 %73, 1
%78 = icmp eq i64 %77, %28
br i1 %78, label %79, label %72
79: ; preds = %72, %27, %52
%80 = tail call i32 @putchar(i32 10)
%81 = tail call i32 @_exit(i32 0)
unreachable
82: ; preds = %18
%83 = call i32 @wait(i32* %3)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %87
85: ; preds = %82
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %87
87: ; preds = %85, %82
%88 = call i32 @exit(i32 0)
unreachable
}