long countCombinations(int n, int restriction) {
  long result;
  if (n == 0) {
    return 1;
  }
  if (n == 1) {
    return (1 + (restriction == 0));
  }
  result = 0;
  if (restriction != 1) {
    result = result + countCombinations(n - 1, 1);
  }
  if (restriction != 2) {
    result = result + countCombinations(n - 1, 2);
  }
  if (restriction == 1) {
    result = result + countCombinations(n - 2, 2);
  }
  if (restriction == 2) {
    result = result + countCombinations(n - 2, 1);
  }
  return result;
}


x86 assembly (clang, -O0):
<countCombinations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1135 <countCombinations+0x25>
movq   $0x1,-0x8(%rbp)
jmp    1229 <countCombinations+0x119>
cmpl   $0x1,-0xc(%rbp)
jne    1159 <countCombinations+0x49>
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    1229 <countCombinations+0x119>
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x10(%rbp)
je     1191 <countCombinations+0x81>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
mov    $0x1,%esi
call   1030 <countCombinations@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x10(%rbp)
je     11c1 <countCombinations+0xb1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
mov    $0x2,%esi
call   1030 <countCombinations@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    11f1 <countCombinations+0xe1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x2,%edi
mov    $0x2,%esi
call   1030 <countCombinations@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x10(%rbp)
jne    1221 <countCombinations+0x111>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x2,%edi
mov    $0x1,%esi
call   1030 <countCombinations@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countCombinations>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
xor    %r12d,%r12d
test   %r14d,%r14d
je     1166 <countCombinations+0x56>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x1,%r14d
je     117b <countCombinations+0x6b>
cmp    $0x1,%r15d
je     118d <countCombinations+0x7d>
lea    -0x1(%r14),%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <countCombinations@plt>
mov    %rax,%rbx
cmp    $0x2,%r15d
je     116d <countCombinations+0x5d>
add    %rbx,%r12
mov    $0x2,%r15d
mov    %ebp,%r14d
test   %r14d,%r14d
jne    1130 <countCombinations+0x20>
mov    $0x1,%ebx
jmp    1188 <countCombinations+0x78>
add    $0xfffffffe,%r14d
mov    %r14d,%edi
mov    $0x1,%esi
jmp    11aa <countCombinations+0x9a>
cmp    $0x1,%r15d
mov    $0x1,%ebx
adc    $0x0,%rbx
add    %r12,%rbx
jmp    11b5 <countCombinations+0xa5>
lea    -0x1(%r14),%edi
mov    $0x2,%esi
call   1030 <countCombinations@plt>
mov    %rax,%rbx
add    $0xfffffffe,%r14d
mov    %r14d,%edi
mov    $0x2,%esi
call   1030 <countCombinations@plt>
add    %r12,%rbx
add    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @countCombinations(i32 %0, i32 %1) {
br label %3
3: ; preds = %16, %2
%4 = phi i64 [ 0, %2 ], [ %17, %16 ]
%5 = phi i32 [ %0, %2 ], [ %12, %16 ]
%6 = phi i32 [ %1, %2 ], [ 2, %16 ]
switch i32 %5, label %10 [
i32 0, label %31
i32 1, label %7
]
7: ; preds = %3
%8 = icmp eq i32 %6, 0
%9 = select i1 %8, i64 2, i64 1
br label %31
10: ; preds = %3
%11 = icmp eq i32 %6, 1
%12 = add nsw i32 %5, -1
br i1 %11, label %20, label %13
13: ; preds = %10
%14 = tail call i64 @countCombinations(i32 %12, i32 1)
%15 = icmp eq i32 %6, 2
br i1 %15, label %26, label %16
16: ; preds = %13
%17 = add nsw i64 %14, %4
br label %3
18: ; preds = %31, %26, %20
%19 = phi i64 [ %25, %20 ], [ %30, %26 ], [ %33, %31 ]
ret i64 %19
20: ; preds = %10
%21 = tail call i64 @countCombinations(i32 %12, i32 2)
%22 = add nsw i32 %5, -2
%23 = tail call i64 @countCombinations(i32 %22, i32 2)
%24 = add i64 %21, %4
%25 = add i64 %24, %23
br label %18
26: ; preds = %13
%27 = add nsw i32 %5, -2
%28 = tail call i64 @countCombinations(i32 %27, i32 1)
%29 = add i64 %14, %4
%30 = add i64 %29, %28
br label %18
31: ; preds = %3, %7
%32 = phi i64 [ %9, %7 ], [ 1, %3 ]
%33 = add nsw i64 %32, %4
br label %18
}