int count_bsts(int nodes) {
  if (nodes <= 1) {
    return 1;
  }
  int sum = 0;
  int left, right;
  for (int i = 1; i <= nodes; i++) {
    left = count_bsts(i - 1);
    right = count_bsts(nodes - i);
    sum += (left * right);
  }
  return sum;
}


x86 assembly (clang, -O0):
<count_bsts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1131 <count_bsts+0x21>
movl   $0x1,-0x4(%rbp)
jmp    1188 <count_bsts+0x78>
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1182 <count_bsts+0x72>
mov    -0x18(%rbp),%edi
sub    $0x1,%edi
call   1030 <count_bsts@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
sub    -0x18(%rbp),%edi
call   1030 <count_bsts@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113f <count_bsts+0x2f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_bsts>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%r14d
cmp    $0x2,%edi
jl     1150 <count_bsts+0x40>
mov    %edi,%ebx
add    $0xffffffff,%ebx
xor    %ebp,%ebp
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %ebp,%edi
call   1030 <count_bsts@plt>
mov    %eax,%r15d
mov    %ebx,%edi
call   1030 <count_bsts@plt>
imul   %r15d,%eax
add    %eax,%r14d
add    $0x1,%ebp
add    $0xffffffff,%ebx
jb     1130 <count_bsts+0x20>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @count_bsts(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %14, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %12, %3 ], [ 1, %1 ]
%5 = phi i32 [ %11, %3 ], [ 0, %1 ]
%6 = add nsw i32 %4, -1
%7 = tail call i32 @count_bsts(i32 %6)
%8 = sub nsw i32 %0, %4
%9 = tail call i32 @count_bsts(i32 %8)
%10 = mul nsw i32 %9, %7
%11 = add nsw i32 %10, %5
%12 = add nuw i32 %4, 1
%13 = icmp eq i32 %4, %0
br i1 %13, label %14, label %3
14: ; preds = %3, %1
%15 = phi i32 [ 1, %1 ], [ %11, %3 ]
ret i32 %15
}