#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(2);
  printf(
      "enter the no of terms of fibonacci series which have to be generated\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 - 2] + a[i - 1];
      printf("id of thread involved in the computation of fib no %d is=%d\n",
             i + 1, omp_get_thread_num());
    }
#pragma omp barrier
#pragma omp single
    {
      printf("the elements of fib series are\n");
      for (i = 0; i < n; i++)
        printf("%d,id of the thread displaying this no is =  %d\n", a[i],
               omp_get_thread_num());
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x2,%edi
call   1050 <omp_set_num_threads@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed5(%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    1219 <main+0xd9>
mov    -0x1a4(%rbp),%eax
sub    $0x2,%eax
cltq
mov    -0x1a0(%rbp,%rax,4),%ecx
mov    -0x1a4(%rbp),%eax
sub    $0x1,%eax
cltq
add    -0x1a0(%rbp,%rax,4),%ecx
movslq -0x1a4(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    -0x1a8(%rbp),%esi
mov    %eax,%edx
lea    0xe4b(%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    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1285 <main+0x145>
movslq -0x1a4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x1ac(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    -0x1ac(%rbp),%esi
mov    %eax,%edx
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1231 <main+0xf1>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1a8,%rsp
mov    $0x2,%edi
call   1060 <omp_set_num_threads@plt>
lea    0xf03(%rip),%rdi
call   1030 <puts@plt>
lea    0xe86(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
movabs $0x100000000,%rax
mov    %rax,0x10(%rsp)
cmpl   $0x3,0xc(%rsp)
jl     11e1 <main+0x91>
mov    $0x2,%ebx
mov    $0x1,%eax
lea    0xe58(%rip),%r14
xor    %ebp,%ebp
nopl   (%rax)
mov    %eax,%r15d
add    %eax,%ebp
mov    %ebp,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0xc(%rsp),%rcx
mov    %ebp,%eax
mov    %r15d,%ebp
cmp    %rcx,%rbx
jl     11b0 <main+0x60>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    1247 <main+0xf7>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
lea    0xe3e(%rip),%rdi
xor    %esi,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x2,0xc(%rsp)
jl     1247 <main+0xf7>
mov    $0x1,%ebx
lea    0xe20(%rip),%r14
mov    0x10(%rsp,%rbx,4),%ebp
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1220 <main+0xd0>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [70 x i8] c"enter the no of terms of fibonacci series which have to be generated\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [61 x i8] c"id of thread involved in the computation of fib no %d is=%d\0A\00"
@.str.3 = [32 x i8] c"the elements of fib series are\0A\00"
@.str.4 = [49 x i8] c"%d,id of the thread displaying this no is = %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 2)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 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, 2
%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, 1
%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 = load i32, i32* %4
%30 = add nsw i32 %29, 1
%31 = call i32 (...) @omp_get_thread_num()
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i32 %30, 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 ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %38
38: ; preds = %49, %36
%39 = load i32, i32* %4
%40 = load i32, i32* %2
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = call i32 (...) @omp_get_thread_num()
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %38
52: ; preds = %38
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [61 x i8] c"id of thread involved in the computation of fib no %d is=%d\0A\00"
@.str.4 = [49 x i8] c"%d,id of the thread displaying this no is = %d\0A\00"
@str = [69 x i8] c"enter the no of terms of fibonacci series which have to be generated\00"
@str.5 = [31 x i8] c"the elements of fib series are\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 2)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 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 %25
12: ; preds = %0, %12
%13 = phi i32 [ %16, %12 ], [ 1, %0 ]
%14 = phi i32 [ %13, %12 ], [ 0, %0 ]
%15 = phi i64 [ %18, %12 ], [ 2, %0 ]
%16 = add nsw i32 %13, %14
%17 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %15
store i32 %16, i32* %17
%18 = add nuw nsw i64 %15, 1
%19 = call i32 (...) @omp_get_thread_num()
%20 = trunc i64 %18 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %19)
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %18, %23
br i1 %24, label %12, label %25
25: ; preds = %12, %0
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0))
%27 = load i32, i32* %1
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %44
29: ; preds = %25
%30 = call i32 (...) @omp_get_thread_num()
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 %30)
%32 = load i32, i32* %1
%33 = icmp sgt i32 %32, 1
br i1 %33, label %34, label %44
34: ; preds = %29, %34
%35 = phi i64 [ %40, %34 ], [ 1, %29 ]
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (...) @omp_get_thread_num()
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 %37, i32 %38)
%40 = add nuw nsw i64 %35, 1
%41 = load i32, i32* %1
%42 = sext i32 %41 to i64
%43 = icmp slt i64 %40, %42
br i1 %43, label %34, label %44
44: ; preds = %34, %29, %25
ret i32 0
}