#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*/ abort();
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
scalar_t__ pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          void *(*)(void *), void *);
int /*<<< orphan*/ pthread_exit(void *);
int /*<<< orphan*/ pthread_join(int /*<<< orphan*/, void **);
void *fib(void *args) {
  pthread_t th1, th2;
  intptr_t arg1, arg2;
  intptr_t ret1, ret2;
  intptr_t n = (intptr_t)args;
  int status;
  if (n == 0 || n == 1)
    pthread_exit((void *)n);
  arg1 = n - 1;
  arg2 = n - 2;
  if (pthread_create(&th1, NULL, fib, (void *)arg1) != 0) {
    perror(NULL);
    abort();
  }
  if (pthread_create(&th2, NULL, fib, (void *)arg2) != 0) {
    perror(NULL);
    abort();
  }
  pthread_join(th1, (void **)&ret1);
  pthread_join(th2, (void **)&ret2);
  pthread_exit((void *)(ret1 + ret2));
}


x86 assembly (clang, -O0):
<fib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     117a <fib+0x2a>
cmpq   $0x1,-0x40(%rbp)
jne    1183 <fib+0x33>
mov    -0x40(%rbp),%rdi
call   1040 <pthread_exit@plt>
mov    -0x40(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x40(%rbp),%rax
sub    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x14(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    0x2e3a(%rip),%rdx
call   1050 <pthread_create@plt>
cmp    $0x0,%rax
je     11cd <fib+0x7d>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x28(%rbp),%rcx
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    0x2e08(%rip),%rdx
call   1050 <pthread_create@plt>
cmp    $0x0,%rax
je     11ff <fib+0xaf>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1070 <pthread_join@plt>
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1070 <pthread_join@plt>
mov    -0x30(%rbp),%rdi
add    -0x38(%rbp),%rdi
call   1040 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
cmp    $0x1,%rdi
ja     1166 <fib+0x16>
mov    %rbx,%rdi
call   1040 <pthread_exit@plt>
lea    -0x1(%rbx),%rcx
mov    0x2e77(%rip),%rdx
lea    0xc(%rsp),%rdi
xor    %esi,%esi
call   1050 <pthread_create@plt>
test   %rax,%rax
jne    11d2 <fib+0x82>
add    $0xfffffffffffffffe,%rbx
mov    0x2e5b(%rip),%rdx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rcx
call   1050 <pthread_create@plt>
test   %rax,%rax
jne    11d2 <fib+0x82>
mov    0xc(%rsp),%edi
lea    0x18(%rsp),%rsi
call   1070 <pthread_join@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
call   1070 <pthread_join@plt>
mov    0x10(%rsp),%rdi
add    0x18(%rsp),%rdi
call   1040 <pthread_exit@plt>
add    $0x20,%rsp
pop    %rbx
ret
xor    %edi,%edi
call   1060 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define i8* @fib(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %3
%12 = load i8*, i8** %3
%13 = ptrtoint i8* %12 to i64
store i64 %13, i64* %10
%14 = load i64, i64* %10
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %1
%17 = load i64, i64* %10
%18 = icmp eq i64 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %16, %1
%20 = load i64, i64* %10
%21 = inttoptr i64 %20 to i8*
%22 = call i32 @pthread_exit(i8* %21)
br label %23
23: ; preds = %19, %16
%24 = load i64, i64* %10
%25 = sub nsw i64 %24, 1
store i64 %25, i64* %6
%26 = load i64, i64* %10
%27 = sub nsw i64 %26, 2
store i64 %27, i64* %7
%28 = load i64, i64* %6
%29 = inttoptr i64 %28 to i8*
%30 = call i64 @pthread_create(i32* %4, i32* null, i8* (i8*)* @fib, i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %23
%33 = call i32 @perror(i32* null)
%34 = call i32 (...) @abort()
unreachable
35: ; preds = %23
%36 = load i64, i64* %7
%37 = inttoptr i64 %36 to i8*
%38 = call i64 @pthread_create(i32* %5, i32* null, i8* (i8*)* @fib, i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = call i32 @perror(i32* null)
%42 = call i32 (...) @abort()
unreachable
43: ; preds = %35
%44 = load i32, i32* %4
%45 = bitcast i64* %8 to i8**
%46 = call i32 @pthread_join(i32 %44, i8** %45)
%47 = load i32, i32* %5
%48 = bitcast i64* %9 to i8**
%49 = call i32 @pthread_join(i32 %47, i8** %48)
%50 = load i64, i64* %8
%51 = load i64, i64* %9
%52 = add nsw i64 %50, %51
%53 = inttoptr i64 %52 to i8*
%54 = call i32 @pthread_exit(i8* %53)
%55 = load i8*, i8** %2
ret i8* %55
}

LLVM IR (-O2):
define noalias i8* @fib(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = bitcast i64* %5 to i8*
%10 = ptrtoint i8* %0 to i64
%11 = icmp ult i8* %0, inttoptr (i64 2 to i8*)
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = tail call i32 @pthread_exit(i8* %0)
br label %14
14: ; preds = %1, %12
%15 = add nsw i64 %10, -1
%16 = inttoptr i64 %15 to i8*
%17 = call i64 @pthread_create(i32* %2, i32* null, i8* (i8*)* @fib, i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = call i32 @perror(i32* null)
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %14
%23 = add nsw i64 %10, -2
%24 = inttoptr i64 %23 to i8*
%25 = call i64 @pthread_create(i32* %3, i32* null, i8* (i8*)* @fib, i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = call i32 @perror(i32* null)
%29 = call i32 (...) @abort()
unreachable
30: ; preds = %22
%31 = load i32, i32* %2
%32 = bitcast i64* %4 to i8**
%33 = call i32 @pthread_join(i32 %31, i8** %32)
%34 = load i32, i32* %3
%35 = bitcast i64* %5 to i8**
%36 = call i32 @pthread_join(i32 %34, i8** %35)
%37 = load i64, i64* %4
%38 = load i64, i64* %5
%39 = add nsw i64 %38, %37
%40 = inttoptr i64 %39 to i8*
%41 = call i32 @pthread_exit(i8* %40)
ret i8* undef
}