#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 /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  printf("I begin");
  int n = atoi(argv[1]);
  if (argc != 2) {
    printf("\nusage: %s possitive_integer\n\n", argv[0]);
  } else if (n < 0) {
    printf("\ninteger argument must be possitive!\n\n");
  } else {
    pid_t pid;
    printf("\ncreating fork\n%d\n", n);
    pid = fork();
    if (pid == -1) {
      fprintf(stderr, "can't fork, error %d\n", errno);
      exit(EXIT_FAILURE);
    }
    if (pid == 0) {
      int fib0 = 0, fib1 = 1, i;
      for (i = 0; i <= n; i++) {
        int fibcurr = fib0;
        fib0 = fib1;
        fib1 = fibcurr + fib1;
        printf("%d, ", fibcurr);
      }
      _exit(0);
    } else {
      wait(&pid);
      exit(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)
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c8 <main+0x58>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b1 <main+0x141>
cmpl   $0x0,-0x14(%rbp)
jge    11e5 <main+0x75>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ac <main+0x13c>
mov    -0x14(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1236 <main+0xc6>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
lea    0xe3e(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    129c <main+0x12c>
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1295 <main+0x125>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1255 <main+0xe5>
xor    %edi,%edi
call   1030 <_exit@plt>
lea    -0x18(%rbp),%rdi
call   1080 <wait@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    12b1 <main+0x141>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rdi
call   1070 <atoi@plt>
cmp    $0x2,%ebp
jne    11bd <main+0x3d>
mov    %eax,%r15d
test   %eax,%eax
jns    11db <main+0x5b>
lea    0xe9f(%rip),%rdi
call   1040 <puts@plt>
jmp    11ce <main+0x4e>
mov    (%rbx),%rsi
lea    0xe41(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe45(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
mov    %eax,0x4(%rsp)
cmp    $0xffffffff,%eax
je     1233 <main+0xb3>
mov    %eax,%esi
test   %eax,%eax
jne    125f <main+0xdf>
sub    %esi,%r15d
add    $0x1,%r15d
mov    $0x1,%ebx
lea    0xe3b(%rip),%r14
lea    (%rsi,%rbx,1),%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%esi
mov    %ebp,%ebx
add    $0xffffffff,%r15d
jne    1215 <main+0x95>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
lea    0xdee(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0x4(%rsp),%rdi
call   1090 <wait@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"I begin\00"
@.str.1 = [31 x i8] c"\0Ausage: %s possitive_integer\0A\0A\00"
@.str.2 = [39 x i8] c"\0Ainteger argument must be possitive!\0A\0A\00"
@.str.3 = [19 x i8] c"\0Acreating fork\0A%d\0A\00"
@stderr = global i32 0
@.str.4 = [22 x i8] c"can't fork, error %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.5 = [5 x i8] c"%d, \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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%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* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %66
24: ; preds = %2
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %65
29: ; preds = %24
%30 = load i32, i32* %6
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = call i32 (...) @fork()
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %41
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %29
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %62
44: ; preds = %41
store i32 0, i32* %8
store i32 1, i32* %9
store i32 0, i32* %10
br label %45
45: ; preds = %57, %44
%46 = load i32, i32* %10
%47 = load i32, i32* %6
%48 = icmp sle i32 %46, %47
br i1 %48, label %49, label %60
49: ; preds = %45
%50 = load i32, i32* %8
store i32 %50, i32* %11
%51 = load i32, i32* %9
store i32 %51, i32* %8
%52 = load i32, i32* %11
%53 = load i32, i32* %9
%54 = add nsw i32 %52, %53
store i32 %54, i32* %9
%55 = load i32, i32* %11
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %49
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 1
store i32 %59, i32* %10
br label %45
60: ; preds = %45
%61 = call i32 @_exit(i32 0)
unreachable
62: ; preds = %41
%63 = call i32 @wait(i32* %7)
%64 = call i32 @exit(i32 0)
unreachable
65: ; preds = %27
br label %66
66: ; preds = %65, %19
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [8 x i8] c"I begin\00"
@.str.1 = [31 x i8] c"\0Ausage: %s possitive_integer\0A\0A\00"
@.str.3 = [19 x i8] c"\0Acreating fork\0A%d\0A\00"
@stderr = global i32 0
@.str.4 = [22 x i8] c"can't fork, error %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.5 = [5 x i8] c"%d, \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 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp eq i32 %0, 2
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %39
12: ; preds = %2
%13 = icmp slt i32 %7, 0
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %39
16: ; preds = %12
%17 = bitcast i32* %3 to i8*
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%19 = tail call i32 (...) @fork()
store i32 %19, i32* %3
switch i32 %19, label %36 [
i32 -1, label %20
i32 0, label %26
]
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %16, %26
%27 = phi i32 [ %29, %26 ], [ %19, %16 ]
%28 = phi i32 [ %32, %26 ], [ %19, %16 ]
%29 = phi i32 [ %30, %26 ], [ 1, %16 ]
%30 = add nsw i32 %27, %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %27)
%32 = add nuw i32 %28, 1
%33 = icmp eq i32 %28, %7
br i1 %33, label %34, label %26
34: ; preds = %26
%35 = tail call i32 @_exit(i32 0)
unreachable
36: ; preds = %16
%37 = call i32 @wait(i32* %3)
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %14, %9
ret i32 0
}