#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 */
long __fib(int, int);
long __fibOfDepth(int, long, int);
long fib(int first, int diff, int depth) {
  return depth <= 0   ? -1
         : depth == 1 ? first
         : depth == 2 ? __fib(first, diff)
                      : __fibOfDepth(first, __fib(first, diff), depth - 3);
}


x86 assembly (clang, -O0):
<fib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     114b <fib+0x2b>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11b6 <fib+0x96>
cmpl   $0x1,-0xc(%rbp)
jne    1162 <fib+0x42>
movslq -0x4(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11ae <fib+0x8e>
cmpl   $0x2,-0xc(%rbp)
jne    1180 <fib+0x60>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <__fib@plt>
mov    %rax,-0x28(%rbp)
jmp    11a6 <fib+0x86>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <__fib@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rsi
mov    -0xc(%rbp),%edx
sub    $0x3,%edx
call   1030 <__fibOfDepth@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib>:
push   %rbp
push   %rbx
push   %rax
test   %edx,%edx
jle    113a <fib+0x1a>
mov    %edx,%ebx
mov    %edi,%ebp
cmp    $0x2,%edx
je     1148 <fib+0x28>
cmp    $0x1,%ebx
jne    1155 <fib+0x35>
movslq %ebp,%rax
jmp    1141 <fib+0x21>
mov    $0xffffffffffffffff,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <__fib@plt>
mov    %ebp,%edi
call   1040 <__fib@plt>
add    $0xfffffffd,%ebx
mov    %ebp,%edi
mov    %rax,%rsi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <__fibOfDepth@plt>

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

LLVM IR (-O2):
define i64 @fib(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %2, 1
br i1 %4, label %14, label %5
5: ; preds = %3
switch i32 %2, label %10 [
i32 1, label %6
i32 2, label %8
]
6: ; preds = %5
%7 = sext i32 %0 to i64
br label %14
8: ; preds = %5
%9 = tail call i64 @__fib(i32 %0, i32 %1)
br label %14
10: ; preds = %5
%11 = tail call i64 @__fib(i32 %0, i32 %1)
%12 = add nsw i32 %2, -3
%13 = tail call i64 @__fibOfDepth(i32 %0, i64 %11, i32 %12)
br label %14
14: ; preds = %6, %10, %8, %3
%15 = phi i64 [ -1, %3 ], [ %7, %6 ], [ %9, %8 ], [ %13, %10 ]
ret i64 %15
}