#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*/ free(int *);
scalar_t__ malloc(int);
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 *ex1, *ex2;
  intptr_t ex3;
  if (n == 0 || n == 1)
    pthread_exit((void *)n);
  ex1 = (int *)malloc(sizeof(int));
  ex2 = (int *)malloc(sizeof(int));
  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);
  *ex1 = ret1;
  *ex2 = ret2;
  ex3 = *ex1 + *ex2;
  free(ex1);
  free(ex2);
  pthread_exit((void *)ex3);
}


x86 assembly (clang, -O0):
<fib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     119a <fib+0x2a>
cmpq   $0x1,-0x40(%rbp)
jne    11a3 <fib+0x33>
mov    -0x40(%rbp),%rdi
call   1050 <pthread_exit@plt>
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
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    0x2dfe(%rip),%rdx
call   1070 <pthread_create@plt>
cmp    $0x0,%rax
je     1209 <fib+0x99>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <perror@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x28(%rbp),%rcx
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    0x2dcc(%rip),%rdx
call   1070 <pthread_create@plt>
cmp    $0x0,%rax
je     123b <fib+0xcb>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <perror@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1090 <pthread_join@plt>
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1090 <pthread_join@plt>
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    -0x50(%rbp),%rcx
add    (%rcx),%eax
cltq
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1050 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
cmp    $0x1,%rdi
ja     118a <fib+0x1a>
mov    %rbx,%rdi
call   1050 <pthread_exit@plt>
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    -0x1(%rbx),%rcx
mov    0x2e39(%rip),%rdx
lea    0xc(%rsp),%rdi
xor    %esi,%esi
call   1070 <pthread_create@plt>
test   %rax,%rax
jne    1232 <fib+0xc2>
add    $0xfffffffffffffffe,%rbx
mov    0x2e1d(%rip),%rdx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rcx
call   1070 <pthread_create@plt>
test   %rax,%rax
jne    1232 <fib+0xc2>
mov    0xc(%rsp),%edi
lea    0x18(%rsp),%rsi
call   1090 <pthread_join@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
call   1090 <pthread_join@plt>
mov    0x18(%rsp),%eax
mov    %eax,(%r15)
movslq 0x10(%rsp),%rax
mov    %eax,(%r14)
movslq (%r15),%rbx
add    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1050 <pthread_exit@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %edi,%edi
call   1080 <perror@plt>
xor    %eax,%eax
call   1040 <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*
%12 = alloca i32*
%13 = alloca i64
store i8* %0, i8** %3
%14 = load i8*, i8** %3
%15 = ptrtoint i8* %14 to i64
store i64 %15, i64* %10
%16 = load i64, i64* %10
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %1
%19 = load i64, i64* %10
%20 = icmp eq i64 %19, 1
br i1 %20, label %21, label %25
21: ; preds = %18, %1
%22 = load i64, i64* %10
%23 = inttoptr i64 %22 to i8*
%24 = call i32 @pthread_exit(i8* %23)
br label %25
25: ; preds = %21, %18
%26 = call i64 @malloc(i32 4)
%27 = inttoptr i64 %26 to i32*
store i32* %27, i32** %11
%28 = call i64 @malloc(i32 4)
%29 = inttoptr i64 %28 to i32*
store i32* %29, i32** %12
%30 = load i64, i64* %10
%31 = sub nsw i64 %30, 1
store i64 %31, i64* %6
%32 = load i64, i64* %10
%33 = sub nsw i64 %32, 2
store i64 %33, i64* %7
%34 = load i64, i64* %6
%35 = inttoptr i64 %34 to i8*
%36 = call i64 @pthread_create(i32* %4, i32* null, i8* (i8*)* @fib, i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %25
%39 = call i32 @perror(i32* null)
%40 = call i32 (...) @abort()
unreachable
41: ; preds = %25
%42 = load i64, i64* %7
%43 = inttoptr i64 %42 to i8*
%44 = call i64 @pthread_create(i32* %5, i32* null, i8* (i8*)* @fib, i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = call i32 @perror(i32* null)
%48 = call i32 (...) @abort()
unreachable
49: ; preds = %41
%50 = load i32, i32* %4
%51 = bitcast i64* %8 to i8**
%52 = call i32 @pthread_join(i32 %50, i8** %51)
%53 = load i32, i32* %5
%54 = bitcast i64* %9 to i8**
%55 = call i32 @pthread_join(i32 %53, i8** %54)
%56 = load i64, i64* %8
%57 = trunc i64 %56 to i32
%58 = load i32*, i32** %11
store i32 %57, i32* %58
%59 = load i64, i64* %9
%60 = trunc i64 %59 to i32
%61 = load i32*, i32** %12
store i32 %60, i32* %61
%62 = load i32*, i32** %11
%63 = load i32, i32* %62
%64 = load i32*, i32** %12
%65 = load i32, i32* %64
%66 = add nsw i32 %63, %65
%67 = sext i32 %66 to i64
store i64 %67, i64* %13
%68 = load i32*, i32** %11
%69 = call i32 @free(i32* %68)
%70 = load i32*, i32** %12
%71 = call i32 @free(i32* %70)
%72 = load i64, i64* %13
%73 = inttoptr i64 %72 to i8*
%74 = call i32 @pthread_exit(i8* %73)
%75 = load i8*, i8** %2
ret i8* %75
}

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 = tail call i64 @malloc(i32 4)
%16 = inttoptr i64 %15 to i32*
%17 = tail call i64 @malloc(i32 4)
%18 = inttoptr i64 %17 to i32*
%19 = add nsw i64 %10, -1
%20 = inttoptr i64 %19 to i8*
%21 = call i64 @pthread_create(i32* %2, i32* null, i8* (i8*)* @fib, i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %14
%24 = call i32 @perror(i32* null)
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %14
%27 = add nsw i64 %10, -2
%28 = inttoptr i64 %27 to i8*
%29 = call i64 @pthread_create(i32* %3, i32* null, i8* (i8*)* @fib, i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = call i32 @perror(i32* null)
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %26
%35 = load i32, i32* %2
%36 = bitcast i64* %4 to i8**
%37 = call i32 @pthread_join(i32 %35, i8** %36)
%38 = load i32, i32* %3
%39 = bitcast i64* %5 to i8**
%40 = call i32 @pthread_join(i32 %38, i8** %39)
%41 = load i64, i64* %4
%42 = trunc i64 %41 to i32
store i32 %42, i32* %16
%43 = load i64, i64* %5
%44 = trunc i64 %43 to i32
store i32 %44, i32* %18
%45 = load i32, i32* %16
%46 = add nsw i32 %45, %44
%47 = sext i32 %46 to i64
%48 = call i32 @free(i32* %16)
%49 = call i32 @free(i32* %18)
%50 = inttoptr i64 %47 to i8*
%51 = call i32 @pthread_exit(i8* %50)
ret i8* undef
}