#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 /*<<< orphan*/ close(int);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int, unsigned long);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *);
scalar_t__ wait(int *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  pid_t pid, wpid;
  int n = 0, status = 0, i = 0;
  unsigned short proceed = 0;
  printf("Fibchild - fibonacci series \n");
  printf("Give the length of fibonacci series to be printed: ");
  scanf("%d", &n);
  printf("\n");
  int arr[n + 1];
  char buff[80];
  i = 1;
  proceed = 1;
  int p[2];
  pipe(p);
  while (i <= n && proceed) {
    pid = fork();
    if (!pid) {
      proceed = 0;
      close(p[0]);
      printf("Child process executing: %d \n", getpid());
      int j = 0;
      unsigned long fib = 0, pre_fib = 0;
      for (j = 1; j <= i; j++) {
        if (j < 3) {
          fib = 1;
          pre_fib = 1;
        } else {
          unsigned long temp = fib;
          fib = pre_fib + fib;
          pre_fib = temp;
        }
      }
      sprintf(buff, "%d %lu", i, fib);
      write(p[1], buff, 80);
    } else if (pid > 0) {
      proceed = 1;
    }
    i++;
  }
  i = n;
  while (pid > 0 && i > 0) {
    sleep(1);
    int j, fib;
    read(p[0], buff, 80);
    sscanf(buff, "%d %d", &j, &fib);
    arr[j] = fib;
    wpid = wait(&status);
    printf("Child process ended: %d with status=%d\n", wpid, status);
    i--;
  }
  if (pid > 0) {
    int j;
    printf("The Fibonacci array : ");
    for (j = 1; j <= n; j++) {
      printf("%d \t", arr[j]);
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movw   $0x0,-0x26(%rbp)
lea    0xe0c(%rip),%rdi
xor    %eax,%eax
mov    %al,-0xd1(%rbp)
call   1050 <printf@plt>
mov    -0xd1(%rbp),%al
lea    0xe10(%rip),%rdi
call   1050 <printf@plt>
lea    0xe60(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0xd1(%rbp),%al
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xd0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x1,-0x24(%rbp)
movw   $0x1,-0x26(%rbp)
lea    -0x98(%rbp),%rdi
call   1070 <pipe@plt>
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0x1c(%rbp),%ecx
mov    %al,-0xd2(%rbp)
jg     129f <main+0xdf>
movzwl -0x26(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xd2(%rbp)
mov    -0xd2(%rbp),%al
test   $0x1,%al
jne    12b2 <main+0xf2>
jmp    13f8 <main+0x238>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    13d4 <main+0x214>
movw   $0x0,-0x26(%rbp)
mov    -0x98(%rbp),%edi
call   1060 <close@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x9c(%rbp)
movq   $0x0,-0xa8(%rbp)
movq   $0x0,-0xb0(%rbp)
movl   $0x1,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     139b <main+0x1db>
cmpl   $0x3,-0x9c(%rbp)
jge    1351 <main+0x191>
movq   $0x1,-0xa8(%rbp)
movq   $0x1,-0xb0(%rbp)
jmp    1382 <main+0x1c2>
mov    -0xa8(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0xb0(%rbp),%rax
add    -0xa8(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0xb8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
jmp    1387 <main+0x1c7>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    131a <main+0x15a>
lea    -0x90(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0xa8(%rbp),%rcx
lea    0xcbd(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x94(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x50,%edx
call   1030 <write@plt>
jmp    13ea <main+0x22a>
cmpq   $0x0,-0x10(%rbp)
jle    13e5 <main+0x225>
movw   $0x1,-0x26(%rbp)
jmp    13ea <main+0x22a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127b <main+0xbb>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0xd3(%rbp)
jle    141e <main+0x25e>
cmpl   $0x0,-0x24(%rbp)
setg   %al
mov    %al,-0xd3(%rbp)
mov    -0xd3(%rbp),%al
test   $0x1,%al
jne    1431 <main+0x271>
jmp    14ba <main+0x2fa>
mov    $0x1,%edi
call   10c0 <sleep@plt>
mov    -0x98(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x50,%edx
call   1080 <read@plt>
lea    -0x90(%rbp),%rdi
lea    0xc17(%rip),%rsi
lea    -0xbc(%rbp),%rdx
lea    -0xc0(%rbp),%rcx
call   1090 <sscanf@plt>
mov    -0xd0(%rbp),%rax
mov    -0xc0(%rbp),%edx
movslq -0xbc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
lea    -0x20(%rbp),%rdi
call   10d0 <wait@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xbd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    13fe <main+0x23e>
cmpq   $0x0,-0x10(%rbp)
jle    152d <main+0x36d>
lea    0xbd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0xc4(%rbp)
mov    -0xc4(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     151f <main+0x35f>
mov    -0xd0(%rbp),%rax
movslq -0xc4(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xbb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    14dd <main+0x31d>
lea    0xb48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
lea    0xdee(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe3c(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   10c0 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x40(%rbp),%rdi
call   1090 <pipe@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    1466 <main+0x286>
mov    %rbx,-0x48(%rbp)
mov    %r12,-0x50(%rbp)
mov    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1100 <fork@plt>
mov    %rax,%r14
test   %rax,%rax
je     12a5 <main+0xc5>
lea    0x1(%r12),%eax
mov    -0x2c(%rbp),%r13d
cmp    %r13d,%r12d
mov    %eax,%r12d
jl     1280 <main+0xa0>
jmp    138c <main+0x1ac>
mov    -0x40(%rbp),%edi
call   1080 <close@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xd77(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    -0x1(%r12),%eax
cmp    $0x3,%eax
jae    12d9 <main+0xf9>
mov    $0x1,%edx
xor    %eax,%eax
jmp    131e <main+0x13e>
mov    %r12d,%ecx
and    $0xfffffffc,%ecx
mov    $0x1,%edx
xor    %ebx,%ebx
mov    $0x1,%esi
xor    %eax,%eax
nopl   (%rax)
mov    %edx,%edi
add    %rax,%rbx
cmp    $0x3,%edx
cmovb  %rsi,%rbx
cmovb  %rsi,%rax
add    %rbx,%rax
cmp    $0x2,%edx
cmovb  %rsi,%rax
cmovb  %rsi,%rbx
add    %rax,%rbx
add    %rbx,%rax
lea    0x4(%rdi),%edx
add    $0x3,%edi
cmp    %ecx,%edi
jne    12f0 <main+0x110>
mov    %rax,%rcx
test   $0x3,%r12b
je     135f <main+0x17f>
movzbl %r12b,%esi
and    $0x3,%esi
mov    $0x1,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %rax,%rbx
cmp    $0x3,%edx
mov    %rbx,%rcx
cmovb  %rdi,%rcx
cmovb  %rdi,%rax
add    $0x1,%edx
mov    %rax,%rbx
mov    %rcx,%rax
add    $0xffffffff,%esi
jne    1340 <main+0x160>
lea    0xcec(%rip),%rsi
lea    -0xa0(%rbp),%r15
mov    %r15,%rdi
mov    %r12d,%edx
call   10d0 <sprintf@plt>
mov    -0x3c(%rbp),%edi
mov    %r15,%rsi
mov    $0x50,%edx
call   1050 <write@plt>
mov    -0x2c(%rbp),%r13d
test   %r14,%r14
mov    -0x48(%rbp),%r15
jle    140f <main+0x22f>
test   %r13d,%r13d
jle    140f <main+0x22f>
add    $0x1,%r13d
lea    -0xa0(%rbp),%rbx
lea    0xcb3(%rip),%r12
nopl   0x0(%rax)
mov    $0x1,%edi
call   10e0 <sleep@plt>
mov    -0x40(%rbp),%edi
mov    %rbx,%rsi
mov    $0x50,%edx
call   10a0 <read@plt>
mov    %rbx,%rdi
lea    0xc85(%rip),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   10b0 <sscanf@plt>
mov    -0x34(%rbp),%eax
movslq -0x38(%rbp),%rcx
mov    %eax,(%r15,%rcx,4)
lea    -0x30(%rbp),%rdi
call   10f0 <wait@plt>
mov    -0x30(%rbp),%edx
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0xffffffff,%r13d
cmp    $0x1,%r13d
ja     13b0 <main+0x1d0>
test   %r14,%r14
mov    -0x50(%rbp),%r12
jle    1466 <main+0x286>
lea    0xc68(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    145c <main+0x27c>
lea    0xc6b(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x4(%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movslq -0x2c(%rbp),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1440 <main+0x260>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Fibchild - fibonacci series \0A\00"
@.str.1 = [52 x i8] c"Give the length of fibonacci series to be printed: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [30 x i8] c"Child process executing: %d \0A\00"
@.str.5 = [7 x i8] c"%d %lu\00"
@.str.6 = [6 x i8] c"%d %d\00"
@.str.7 = [40 x i8] c"Child process ended: %d with status=%d\0A\00"
@.str.8 = [23 x i8] c"The Fibonacci array : \00"
@.str.9 = [5 x i8] c"%d \09\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i16
%8 = alloca i8*
%9 = alloca i64
%10 = alloca [80 x i8]
%11 = alloca [2 x i32]
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i16 0, i16* %7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %8
%27 = alloca i32, i64 %25
store i64 %25, i64* %9
store i32 1, i32* %6
store i16 1, i16* %7
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%29 = call i32 @pipe(i32* %28)
br label %30
30: ; preds = %82, %0
%31 = load i32, i32* %6
%32 = load i32, i32* %4
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i16, i16* %7
%36 = zext i16 %35 to i32
%37 = icmp ne i32 %36, 0
br label %38
38: ; preds = %34, %30
%39 = phi i1 [ false, %30 ], [ %37, %34 ]
br i1 %39, label %40, label %85
40: ; preds = %38
%41 = call i64 (...) @fork()
store i64 %41, i64* %2
%42 = load i64, i64* %2
%43 = icmp ne i64 %42, 0
br i1 %43, label %77, label %44
44: ; preds = %40
store i16 0, i16* %7
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%46 = load i32, i32* %45
%47 = call i32 @close(i32 %46)
%48 = call i32 (...) @getpid()
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %48)
store i32 0, i32* %12
store i64 0, i64* %13
store i64 0, i64* %14
store i32 1, i32* %12
br label %50
50: ; preds = %65, %44
%51 = load i32, i32* %12
%52 = load i32, i32* %6
%53 = icmp sle i32 %51, %52
br i1 %53, label %54, label %68
54: ; preds = %50
%55 = load i32, i32* %12
%56 = icmp slt i32 %55, 3
br i1 %56, label %57, label %58
57: ; preds = %54
store i64 1, i64* %13
store i64 1, i64* %14
br label %64
58: ; preds = %54
%59 = load i64, i64* %13
store i64 %59, i64* %15
%60 = load i64, i64* %14
%61 = load i64, i64* %13
%62 = add i64 %60, %61
store i64 %62, i64* %13
%63 = load i64, i64* %15
store i64 %63, i64* %14
br label %64
64: ; preds = %58, %57
br label %65
65: ; preds = %64
%66 = load i32, i32* %12
%67 = add nsw i32 %66, 1
store i32 %67, i32* %12
br label %50
68: ; preds = %50
%69 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%70 = load i32, i32* %6
%71 = load i64, i64* %13
%72 = call i32 @sprintf(i8* %69, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %70, i64 %71)
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%74 = load i32, i32* %73
%75 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%76 = call i32 @write(i32 %74, i8* %75, i32 80)
br label %82
77: ; preds = %40
%78 = load i64, i64* %2
%79 = icmp sgt i64 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %77
store i16 1, i16* %7
br label %81
81: ; preds = %80, %77
br label %82
82: ; preds = %81, %68
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
br label %30
85: ; preds = %38
%86 = load i32, i32* %4
store i32 %86, i32* %6
br label %87
87: ; preds = %95, %85
%88 = load i64, i64* %2
%89 = icmp sgt i64 %88, 0
br i1 %89, label %90, label %93
90: ; preds = %87
%91 = load i32, i32* %6
%92 = icmp sgt i32 %91, 0
br label %93
93: ; preds = %90, %87
%94 = phi i1 [ false, %87 ], [ %92, %90 ]
br i1 %94, label %95, label %113
95: ; preds = %93
%96 = call i32 @sleep(i32 1)
%97 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%98 = load i32, i32* %97
%99 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%100 = call i32 @read(i32 %98, i8* %99, i32 80)
%101 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%102 = call i32 @sscanf(i8* %101, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32* %16, i32* %17)
%103 = load i32, i32* %17
%104 = load i32, i32* %16
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i32, i32* %27, i64 %105
store i32 %103, i32* %106
%107 = call i64 @wait(i32* %5)
store i64 %107, i64* %3
%108 = load i64, i64* %3
%109 = load i32, i32* %5
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i64 %108, i32 %109)
%111 = load i32, i32* %6
%112 = add nsw i32 %111, -1
store i32 %112, i32* %6
br label %87
113: ; preds = %93
%114 = load i64, i64* %2
%115 = icmp sgt i64 %114, 0
br i1 %115, label %116, label %133
116: ; preds = %113
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %18
br label %118
118: ; preds = %128, %116
%119 = load i32, i32* %18
%120 = load i32, i32* %4
%121 = icmp sle i32 %119, %120
br i1 %121, label %122, label %131
122: ; preds = %118
%123 = load i32, i32* %18
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i32, i32* %27, i64 %124
%126 = load i32, i32* %125
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %126)
br label %128
128: ; preds = %122
%129 = load i32, i32* %18
%130 = add nsw i32 %129, 1
store i32 %130, i32* %18
br label %118
131: ; preds = %118
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %133
133: ; preds = %131, %113
store i32 0, i32* %1
%134 = load i8*, i8** %8
%135 = load i32, i32* %1
ret i32 %135
}

LLVM IR (-O2):
@.str.1 = [52 x i8] c"Give the length of fibonacci series to be printed: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.4 = [30 x i8] c"Child process executing: %d \0A\00"
@.str.5 = [7 x i8] c"%d %lu\00"
@.str.6 = [6 x i8] c"%d %d\00"
@.str.7 = [40 x i8] c"Child process ended: %d with status=%d\0A\00"
@.str.8 = [23 x i8] c"The Fibonacci array : \00"
@.str.9 = [5 x i8] c"%d \09\00"
@str = [29 x i8] c"Fibchild - fibonacci series \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [80 x i8]
%4 = alloca [2 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%8 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%12 = call i32 @putchar(i32 10)
%13 = load i32, i32* %1
%14 = add nsw i32 %13, 1
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
%17 = alloca i32, i64 %15
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%19 = bitcast [2 x i32]* %4 to i8*
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%21 = call i32 @pipe(i32* %20)
%22 = load i32, i32* %1
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %128
24: ; preds = %0
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
br label %34
26: ; preds = %92, %86
%27 = phi i32 [ %91, %86 ], [ %94, %92 ]
%28 = icmp sgt i64 %37, 0
%29 = icmp sgt i32 %27, 0
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %31, label %112
31: ; preds = %26
%32 = bitcast i32* %5 to i8*
%33 = bitcast i32* %6 to i8*
br label %97
34: ; preds = %24, %92
%35 = phi i32 [ 2, %24 ], [ %96, %92 ]
%36 = phi i32 [ 1, %24 ], [ %93, %92 ]
%37 = call i64 (...) @fork()
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %92
39: ; preds = %34
%40 = load i32, i32* %20
%41 = call i32 @close(i32 %40)
%42 = call i32 (...) @getpid()
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = add i32 %35, -1
%45 = add i32 %35, -2
%46 = and i32 %44, 3
%47 = icmp ult i32 %45, 3
br i1 %47, label %68, label %48
48: ; preds = %39
%49 = and i32 %44, -4
br label %50
50: ; preds = %50, %48
%51 = phi i64 [ 0, %48 ], [ %63, %50 ]
%52 = phi i64 [ 0, %48 ], [ %64, %50 ]
%53 = phi i32 [ 1, %48 ], [ %65, %50 ]
%54 = phi i32 [ 0, %48 ], [ %66, %50 ]
%55 = icmp ult i32 %53, 3
%56 = add i64 %51, %52
%57 = select i1 %55, i64 1, i64 %56
%58 = select i1 %55, i64 1, i64 %52
%59 = icmp ult i32 %53, 2
%60 = add i64 %58, %57
%61 = select i1 %59, i64 1, i64 %60
%62 = select i1 %59, i64 1, i64 %57
%63 = add i64 %62, %61
%64 = add i64 %61, %63
%65 = add nuw i32 %53, 4
%66 = add i32 %54, 4
%67 = icmp eq i32 %66, %49
br i1 %67, label %68, label %50
68: ; preds = %50, %39
%69 = phi i64 [ undef, %39 ], [ %64, %50 ]
%70 = phi i64 [ 0, %39 ], [ %63, %50 ]
%71 = phi i64 [ 0, %39 ], [ %64, %50 ]
%72 = phi i32 [ 1, %39 ], [ %65, %50 ]
%73 = icmp eq i32 %46, 0
br i1 %73, label %86, label %74
74: ; preds = %68, %74
%75 = phi i64 [ %82, %74 ], [ %70, %68 ]
%76 = phi i64 [ %81, %74 ], [ %71, %68 ]
%77 = phi i32 [ %83, %74 ], [ %72, %68 ]
%78 = phi i32 [ %84, %74 ], [ 0, %68 ]
%79 = icmp ult i32 %77, 3
%80 = add i64 %75, %76
%81 = select i1 %79, i64 1, i64 %80
%82 = select i1 %79, i64 1, i64 %76
%83 = add nuw i32 %77, 1
%84 = add i32 %78, 1
%85 = icmp eq i32 %84, %46
br i1 %85, label %86, label %74
86: ; preds = %74, %68
%87 = phi i64 [ %69, %68 ], [ %81, %74 ]
%88 = call i32 @sprintf(i8* %18, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %36, i64 %87)
%89 = load i32, i32* %25
%90 = call i32 @write(i32 %89, i8* %18, i32 80)
%91 = load i32, i32* %1
br label %26
92: ; preds = %34
%93 = add nuw nsw i32 %36, 1
%94 = load i32, i32* %1
%95 = icmp slt i32 %36, %94
%96 = add nuw i32 %35, 1
br i1 %95, label %34, label %26
97: ; preds = %31, %97
%98 = phi i32 [ %27, %31 ], [ %110, %97 ]
%99 = call i32 @sleep(i32 1)
%100 = load i32, i32* %20
%101 = call i32 @read(i32 %100, i8* %18, i32 80)
%102 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32* %5, i32* %6)
%103 = load i32, i32* %6
%104 = load i32, i32* %5
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i32, i32* %17, i64 %105
store i32 %103, i32* %106
%107 = call i64 @wait(i32* %2)
%108 = load i32, i32* %2
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i64 %107, i32 %108)
%110 = add nsw i32 %98, -1
%111 = icmp ugt i32 %98, 1
br i1 %111, label %97, label %112
112: ; preds = %97, %26
br i1 %28, label %113, label %128
113: ; preds = %112
%114 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
%115 = load i32, i32* %1
%116 = icmp slt i32 %115, 1
br i1 %116, label %126, label %117
117: ; preds = %113, %117
%118 = phi i64 [ %122, %117 ], [ 1, %113 ]
%119 = getelementptr inbounds i32, i32* %17, i64 %118
%120 = load i32, i32* %119
%121 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %120)
%122 = add nuw nsw i64 %118, 1
%123 = load i32, i32* %1
%124 = sext i32 %123 to i64
%125 = icmp slt i64 %118, %124
br i1 %125, label %117, label %126
126: ; preds = %117, %113
%127 = call i32 @putchar(i32 10)
br label %128
128: ; preds = %0, %126, %112
ret i32 0
}