#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 */
int possible_trees(size_t);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, size_t *);
int main(void) {
  printf("Enter a tree size N to see how many trees exist such that\n"
         "the inorder traversal yields [0, 1, ... N-1]\n");
  printf("> ");
  size_t tree_sz;
  while (scanf("%zu", &tree_sz) == 1) {
    printf("%u\n", possible_trees(tree_sz));
    printf("> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf09(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11a0 <main+0x70>
mov    -0x10(%rbp),%rdi
call   1040 <possible_trees@plt>
mov    %eax,%esi
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    115b <main+0x2b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9a(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11bf <main+0x7f>
lea    0xe8a(%rip),%r14
lea    0xe7c(%rip),%r15
lea    0xe78(%rip),%r12
mov    %rsp,%rbx
xchg   %ax,%ax
mov    (%rsp),%rdi
call   1050 <possible_trees@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     1190 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [104 x i8] c"Enter a tree size N to see how many trees exist such that\0Athe inorder traversal yields [0, 1, ... N-1]\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c"%zu\00"
@.str.3 = [4 x i8] c"%u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([104 x i8], [104 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %8, %0
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i64, i64* %2
%10 = call i32 @possible_trees(i64 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %5
13: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c"%zu\00"
@.str.3 = [4 x i8] c"%u\0A\00"
@str = [103 x i8] c"Enter a tree size N to see how many trees exist such that\0Athe inorder traversal yields [0, 1, ... N-1]\00"
define i32 @main() {
%1 = alloca i64
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([103 x i8], [103 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast i64* %1 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %14
7: ; preds = %0, %7
%8 = load i64, i64* %1
%9 = call i32 @possible_trees(i64 %8)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%13 = icmp eq i32 %12, 1
br i1 %13, label %7, label %14
14: ; preds = %7, %0
ret i32 0
}