#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*/ MyThreadCreate(void (*)(void *), void *);
int /*<<< orphan*/ MyThreadExit();
int /*<<< orphan*/ MyThreadJoinAll();
void fib(void *in) {
  int *n = (int *)in;
  if (*n == 0)
    ;
  else if (*n == 1)
    ;
  else {
    int n1 = *n - 1;
    int n2 = *n - 2;
    MyThreadCreate(fib, (void *)&n1);
    MyThreadCreate(fib, (void *)&n2);
    MyThreadJoinAll();
    *n = n1 + n2;
  }
  MyThreadExit();
}


x86 assembly (clang, -O0):
<fib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1156 <fib+0x26>
jmp    11b8 <fib+0x88>
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jne    1168 <fib+0x38>
jmp    11b3 <fib+0x83>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x2,%eax
mov    %eax,-0x18(%rbp)
lea    -0x14(%rbp),%rsi
mov    0x2e5d(%rip),%rdi
call   1030 <MyThreadCreate@plt>
lea    -0x18(%rbp),%rsi
mov    0x2e4d(%rip),%rdi
call   1030 <MyThreadCreate@plt>
mov    $0x0,%al
call   1040 <MyThreadJoinAll@plt>
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11b8 <fib+0x88>
mov    $0x0,%al
call   1050 <MyThreadExit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%eax
cmp    $0x2,%eax
jb     117a <fib+0x4a>
mov    %rdi,%rbx
lea    -0x1(%rax),%ecx
mov    %ecx,0x4(%rsp)
add    $0xfffffffe,%eax
mov    %eax,(%rsp)
mov    0x2e96(%rip),%r14
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
call   1030 <MyThreadCreate@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <MyThreadCreate@plt>
xor    %eax,%eax
call   1040 <MyThreadJoinAll@plt>
mov    (%rsp),%eax
add    0x4(%rsp),%eax
mov    %eax,(%rbx)
xor    %eax,%eax
call   1050 <MyThreadExit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @fib(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
br label %34
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %12
br label %33
17: ; preds = %12
%18 = load i32*, i32** %3
%19 = load i32, i32* %18
%20 = sub nsw i32 %19, 1
store i32 %20, i32* %4
%21 = load i32*, i32** %3
%22 = load i32, i32* %21
%23 = sub nsw i32 %22, 2
store i32 %23, i32* %5
%24 = bitcast i32* %4 to i8*
%25 = call i32 @MyThreadCreate(void (i8*)* @fib, i8* %24)
%26 = bitcast i32* %5 to i8*
%27 = call i32 @MyThreadCreate(void (i8*)* @fib, i8* %26)
%28 = call i32 (...) @MyThreadJoinAll()
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = add nsw i32 %29, %30
%32 = load i32*, i32** %3
store i32 %31, i32* %32
br label %33
33: ; preds = %17, %16
br label %34
34: ; preds = %33, %11
%35 = call i32 (...) @MyThreadExit()
ret void
}

LLVM IR (-O2):
define void @fib(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i8* %0 to i32*
%5 = load i32, i32* %4
%6 = icmp ult i32 %5, 2
br i1 %6, label %18, label %7
7: ; preds = %1
%8 = bitcast i32* %2 to i8*
%9 = add nsw i32 %5, -1
store i32 %9, i32* %2
%10 = bitcast i32* %3 to i8*
%11 = add nsw i32 %5, -2
store i32 %11, i32* %3
%12 = call i32 @MyThreadCreate(void (i8*)* @fib, i8* %8)
%13 = call i32 @MyThreadCreate(void (i8*)* @fib, i8* %10)
%14 = call i32 (...) @MyThreadJoinAll()
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = add nsw i32 %16, %15
store i32 %17, i32* %4
br label %18
18: ; preds = %1, %7
%19 = call i32 (...) @MyThreadExit()
ret void
}