#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 */
typedef int /*<<< orphan*/ pthread_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          void *(*)(void *), void *);
scalar_t__ pthread_join(int /*<<< orphan*/, void **);
void *tfib(void *n) {
  if ((int)n < 2)
    return (void *)1;
  else {
    pthread_t x;
    void *y;
    void *z;
    if (pthread_create(&x, NULL, tfib, (void *)((int)n - 2)) != 0)
      exit(1);
    y = tfib((void *)((int)n - 1));
    if (pthread_join(x, &z) != 0)
      exit(1);
    return (void *)((int)y + (int)z);
  }
}


x86 assembly (clang, -O0):
<tfib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    $0x2,%eax
jge    1157 <tfib+0x27>
mov    $0x1,%eax
mov    %rax,-0x8(%rbp)
jmp    11cc <tfib+0x9c>
mov    -0x10(%rbp),%rax
sub    $0x2,%eax
movslq %eax,%rcx
lea    -0x14(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    0x2e70(%rip),%rdx
call   1030 <pthread_create@plt>
cmp    $0x0,%rax
je     1189 <tfib+0x59>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x10(%rbp),%rax
sub    $0x1,%eax
movslq %eax,%rdi
call   1060 <tfib@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1050 <pthread_join@plt>
cmp    $0x0,%rax
je     11bc <tfib+0x8c>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    %ecx,%eax
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tfib>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    $0x1,%eax
cmp    $0x2,%ebx
jl     118f <tfib+0x5f>
mov    $0xfffffffe,%r14d
lea    (%rbx,%r14,1),%ecx
mov    0x2e8b(%rip),%rdx
lea    0xc(%rsp),%rdi
xor    %esi,%esi
call   1030 <pthread_create@plt>
test   %rax,%rax
jne    1197 <tfib+0x67>
lea    (%r14,%rbx,1),%edi
add    $0x1,%edi
call   1060 <tfib@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
call   1050 <pthread_join@plt>
test   %rax,%rax
jne    1197 <tfib+0x67>
add    0x10(%rsp),%ebx
movslq %ebx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
define i8* @tfib(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = ptrtoint i8* %7 to i32
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* inttoptr (i64 1 to i8*), i8** %2
br label %41
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = ptrtoint i8* %12 to i32
%14 = sub nsw i32 %13, 2
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i8*
%17 = call i64 @pthread_create(i32* %4, i32* null, i8* (i8*)* @tfib, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %11
%22 = load i8*, i8** %3
%23 = ptrtoint i8* %22 to i32
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i8*
%27 = call i8* @tfib(i8* %26)
store i8* %27, i8** %5
%28 = load i32, i32* %4
%29 = call i64 @pthread_join(i32 %28, i8** %6)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %21
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %21
%34 = load i8*, i8** %5
%35 = ptrtoint i8* %34 to i32
%36 = load i8*, i8** %6
%37 = ptrtoint i8* %36 to i32
%38 = add nsw i32 %35, %37
%39 = sext i32 %38 to i64
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %2
br label %41
41: ; preds = %33, %10
%42 = load i8*, i8** %2
ret i8* %42
}

LLVM IR (-O2):
define i8* @tfib(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = ptrtoint i8* %0 to i64
%5 = trunc i64 %4 to i32
%6 = icmp slt i32 %5, 2
br i1 %6, label %35, label %7
7: ; preds = %1
%8 = bitcast i32* %2 to i8*
%9 = bitcast i8** %3 to i8*
%10 = add i64 %4, 4294967294
%11 = and i64 %10, 4294967295
%12 = inttoptr i64 %11 to i8*
%13 = call i64 @pthread_create(i32* %2, i32* null, i8* (i8*)* @tfib, i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %7
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %7
%18 = add i64 %4, 4294967295
%19 = and i64 %18, 4294967295
%20 = inttoptr i64 %19 to i8*
%21 = call i8* @tfib(i8* %20)
%22 = load i32, i32* %2
%23 = call i64 @pthread_join(i32 %22, i8** %3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %17
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17
%28 = ptrtoint i8* %21 to i64
%29 = load i8*, i8** %3
%30 = ptrtoint i8* %29 to i64
%31 = add i64 %30, %28
%32 = shl i64 %31, 32
%33 = ashr exact i64 %32, 32
%34 = inttoptr i64 %33 to i8*
br label %35
35: ; preds = %1, %27
%36 = phi i8* [ %34, %27 ], [ inttoptr (i64 1 to i8*), %1 ]
ret i8* %36
}