#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(void) {
  int number_of_terms;
  int i;
  int array[10];
  omp_set_num_threads(2);
  printf("Enter the number of terms: ");
  scanf("%d", &number_of_terms);
  array[0] = 0;
  array[1] = 1;
#pragma omp parallel
  {
#pragma omp single
    for (i = 2; i < number_of_terms; i++) {
      array[i] = array[i - 1] + array[i - 2];
      printf("Thread %d -- generated term number %d\n", omp_get_thread_num(),
             i + 1);
    }
#pragma omp single
    {
      printf("\nThe series is:\n");
      for (i = 0; i < number_of_terms; i++) {
        printf("Thread %d -- generated term %d\n", omp_get_thread_num(),
               array[i]);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x2,%edi
call   1050 <omp_set_num_threads@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x0,-0x40(%rbp)
movl   $0x1,-0x3c(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e3 <main+0xa3>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x40(%rbp,%rax,4),%ecx
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
cltq
add    -0x40(%rbp,%rax,4),%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118c <main+0x4c>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1231 <main+0xf1>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
movslq -0xc(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11f8 <main+0xb8>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    $0x2,%edi
call   1060 <omp_set_num_threads@plt>
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea5(%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    0xe72(%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    0xe4c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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    0xe54(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    1255 <main+0x105>
lea    0xe21(%rip),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
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     1230 <main+0xe0>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Enter the number of terms: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"Thread %d -- generated term number %d\0A\00"
@.str.3 = [17 x i8] c"\0AThe series is:\0A\00"
@.str.4 = [32 x i8] c"Thread %d -- generated term %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i32]
store i32 0, i32* %1
%5 = call i32 @omp_set_num_threads(i32 2)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 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 [10 x i32], [10 x i32]* %4, i64 0, i64 0
store i32 0, i32* %8
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 1
store i32 1, i32* %9
store i32 2, i32* %3
br label %10
10: ; preds = %33, %0
%11 = load i32, i32* %3
%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* %3
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %19, %24
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %27
store i32 %25, i32* %28
%29 = call i32 (...) @omp_get_thread_num()
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %31)
br label %33
33: ; preds = %14
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %10
36: ; preds = %10
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %38
38: ; preds = %49, %36
%39 = load i32, i32* %3
%40 = load i32, i32* %2
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = call i32 (...) @omp_get_thread_num()
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %43, i32 %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %38
52: ; preds = %38
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Enter the number of terms: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"Thread %d -- generated term number %d\0A\00"
@.str.4 = [32 x i8] c"Thread %d -- generated term %d\0A\00"
@str = [16 x i8] c"\0AThe series is:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [10 x i32]* %2 to i8*
%5 = tail call i32 @omp_set_num_threads(i32 2)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 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 [10 x i32], [10 x i32]* %2, i64 0, i64 0
store i32 0, i32* %8
%9 = getelementptr inbounds [10 x i32], [10 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 [10 x i32], [10 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 ([39 x i8], [39 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 [10 x i32], [10 x i32]* %2, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %24, %20
%26 = getelementptr inbounds [10 x i32], [10 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 ([39 x i8], [39 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 ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%36 = load i32, i32* %1
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %34, %38
%39 = phi i64 [ %44, %38 ], [ 0, %34 ]
%40 = call i32 (...) @omp_get_thread_num()
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %39
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %40, i32 %42)
%44 = add nuw nsw i64 %39, 1
%45 = load i32, i32* %1
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %44, %46
br i1 %47, label %38, label %48
48: ; preds = %38, %34
ret i32 0
}