#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 */

/* Variables and functions */
int omp_get_thread_num();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, a[100], i;
  omp_set_num_threads(5);
  printf("Enter n\n");
  scanf("%d", &n);
  a[0] = 0;
  a[1] = 1;
#pragma omp parallel
  {
#pragma omp single
    {
      for (i = 2; i < n; i++) {
        a[i] = a[i - 1] + a[i - 2];
        printf("Computation thread id = %d,\tfib num = %d\n",
               omp_get_thread_num(), i + 1);
      }
    }
  }
  printf("\nFibonacci Series\n");
#pragma omp barrier
#pragma omp single
  {
    printf("Fibonacci series : \n");
    for (i = 0; i < n; i++) {
      printf("%d - thread id, Fib num = %d \n", omp_get_thread_num(), a[i]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x5,%edi
call   1050 <omp_set_num_threads@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe98(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x0,-0x1a0(%rbp)
movl   $0x1,-0x19c(%rbp)
movl   $0x2,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120d <main+0xcd>
mov    -0x1a4(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x1a0(%rbp,%rax,4),%ecx
mov    -0x1a4(%rbp),%eax
sub    $0x2,%eax
cltq
add    -0x1a0(%rbp,%rax,4),%ecx
movslq -0x1a4(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0x1a4(%rbp),%edx
add    $0x1,%edx
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1198 <main+0x58>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127b <main+0x13b>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
movslq -0x1a4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edx
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1233 <main+0xf3>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1a0,%rsp
mov    $0x5,%edi
call   1060 <omp_set_num_threads@plt>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
lea    0xe88(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
movabs $0x100000000,%rax
mov    %rax,0x10(%rsp)
cmpl   $0x3,0xc(%rsp)
jl     120b <main+0xbb>
movl   $0x1,0x18(%rsp)
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
lea    0xe55(%rip),%rdi
mov    %eax,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x4,0xc(%rsp)
jl     120b <main+0xbb>
mov    $0x1,%ebp
mov    $0x3,%ebx
lea    0xe2f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    0x8(%rsp,%rbx,4),%ebp
mov    %ebp,0x10(%rsp,%rbx,4)
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
add    $0x1,%rbx
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11e0 <main+0x90>
lea    0xe42(%rip),%rdi
call   1030 <puts@plt>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    1265 <main+0x115>
lea    0xdfc(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    0x10(%rsp,%rbp,4),%edx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     1240 <main+0xf0>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Enter n\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [42 x i8] c"Computation thread id = %d,\09fib num = %d\0A\00"
@.str.3 = [19 x i8] c"\0AFibonacci Series\0A\00"
@.str.4 = [21 x i8] c"Fibonacci series : \0A\00"
@.str.5 = [31 x i8] c"%d - thread id, Fib num = %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i32]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @omp_set_num_threads(i32 5)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
store i32 0, i32* %8
%9 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 1
store i32 1, i32* %9
store i32 2, i32* %4
br label %10
10: ; preds = %33, %0
%11 = load i32, i32* %4
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %36
14: ; preds = %10
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %19, %24
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %27
store i32 %25, i32* %28
%29 = call i32 (...) @omp_get_thread_num()
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %31)
br label %33
33: ; preds = %14
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %10
36: ; preds = %10
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %39
39: ; preds = %50, %36
%40 = load i32, i32* %4
%41 = load i32, i32* %2
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %53
43: ; preds = %39
%44 = call i32 (...) @omp_get_thread_num()
%45 = load i32, i32* %4
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %44, i32 %48)
br label %50
50: ; preds = %43
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %39
53: ; preds = %39
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [42 x i8] c"Computation thread id = %d,\09fib num = %d\0A\00"
@.str.5 = [31 x i8] c"%d - thread id, Fib num = %d \0A\00"
@str = [8 x i8] c"Enter n\00"
@str.6 = [18 x i8] c"\0AFibonacci Series\00"
@str.7 = [20 x i8] c"Fibonacci series : \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [100 x i32]* %2 to i8*
%5 = tail call i32 @omp_set_num_threads(i32 5)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
store i32 0, i32* %8
%9 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 1
store i32 1, i32* %9
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %34
12: ; preds = %0
%13 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 2
store i32 1, i32* %13
%14 = call i32 (...) @omp_get_thread_num()
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 3)
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 3
br i1 %17, label %18, label %34
18: ; preds = %12, %18
%19 = phi i64 [ %28, %18 ], [ 3, %12 ]
%20 = phi i32 [ %25, %18 ], [ 1, %12 ]
%21 = phi i64 [ %19, %18 ], [ 2, %12 ]
%22 = add nsw i64 %21, -1
%23 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %24, %20
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %19
store i32 %25, i32* %26
%27 = call i32 (...) @omp_get_thread_num()
%28 = add nuw nsw i64 %19, 1
%29 = trunc i64 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %29)
%31 = load i32, i32* %1
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %28, %32
br i1 %33, label %18, label %34
34: ; preds = %18, %12, %0
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.7, i64 0, i64 0))
%37 = load i32, i32* %1
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %34, %39
%40 = phi i64 [ %45, %39 ], [ 0, %34 ]
%41 = call i32 (...) @omp_get_thread_num()
%42 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %40
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %41, i32 %43)
%45 = add nuw nsw i64 %40, 1
%46 = load i32, i32* %1
%47 = sext i32 %46 to i64
%48 = icmp slt i64 %45, %47
br i1 %48, label %39, label %49
49: ; preds = %39, %34
ret i32 0
}