#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 /*<<< orphan*/ SYS_gettid;
int omp_get_thread_num();
int /*<<< orphan*/ printf(char *, int, int, int);
scalar_t__ syscall(int /*<<< orphan*/);
int fib(int n) {
  int my_id = omp_get_thread_num();
  int x, y;
  if (0) {
    printf("\t\t[%d][tid.%d] Calculating fib(%d)\n", my_id,
           (int)syscall(SYS_gettid), n);
  }
  if (n < 2) {
    return n;
  }
#pragma omp task shared(x)
  x = fib(n - 1);
#pragma omp task shared(y)
  y = fib(n - 2);
#pragma omp taskwait
  return x + y;
}


x86 assembly (clang, -O0):
<fib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    114a <fib+0x2a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    116f <fib+0x4f>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1040 <fib@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
call   1040 <fib@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
cmp    $0x2,%ebx
jge    1139 <fib+0x19>
mov    %ebx,%r14d
jmp    115d <fib+0x3d>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%edi
call   1040 <fib@plt>
lea    -0x2(%rbx),%r14d
add    %eax,%ebp
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
cmp    $0x3,%ebx
mov    %r14d,%ebx
ja     1140 <fib+0x20>
add    %r14d,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SYS_gettid = global i32 0
define i32 @fib(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = call i32 (...) @omp_get_thread_num()
store i32 %7, i32* %4
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %3
store i32 %11, i32* %2
br label %22
12: ; preds = %1
%13 = load i32, i32* %3
%14 = sub nsw i32 %13, 1
%15 = call i32 @fib(i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %3
%17 = sub nsw i32 %16, 2
%18 = call i32 @fib(i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = add nsw i32 %19, %20
store i32 %21, i32* %2
br label %22
22: ; preds = %12, %10
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@SYS_gettid = global i32 0
define i32 @fib(i32 %0) {
%2 = tail call i32 (...) @omp_get_thread_num()
%3 = icmp slt i32 %0, 2
br i1 %3, label %13, label %4
4: ; preds = %1, %4
%5 = phi i32 [ %9, %4 ], [ %0, %1 ]
%6 = phi i32 [ %10, %4 ], [ 0, %1 ]
%7 = add nsw i32 %5, -1
%8 = tail call i32 @fib(i32 %7)
%9 = add nsw i32 %5, -2
%10 = add nsw i32 %8, %6
%11 = tail call i32 (...) @omp_get_thread_num()
%12 = icmp ult i32 %5, 4
br i1 %12, label %13, label %4
13: ; preds = %4, %1
%14 = phi i32 [ 0, %1 ], [ %10, %4 ]
%15 = phi i32 [ %0, %1 ], [ %9, %4 ]
%16 = add nsw i32 %15, %14
ret i32 %16
}