unsigned athena_can_build(unsigned n, struct Athena_Class **const buildable,
                          const struct Athena_Class *class) {
  if (n == 0)
    return 0;
  else {
    if (*buildable == class)
      return 1;
    else
      return athena_can_build(n - 1, buildable + 1, class);
  }
}


x86 assembly (clang, -O0):
<athena_can_build>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1139 <athena_can_build+0x29>
movl   $0x0,-0x4(%rbp)
jmp    1170 <athena_can_build+0x60>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jne    1156 <athena_can_build+0x46>
movl   $0x1,-0x4(%rbp)
jmp    1170 <athena_can_build+0x60>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
mov    -0x18(%rbp),%rdx
call   1030 <athena_can_build@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<athena_can_build>:
test   %edi,%edi
je     111e <athena_can_build+0x1e>
mov    %edi,%eax
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
cmp    %rdx,(%rsi,%rcx,8)
je     1121 <athena_can_build+0x21>
add    $0x1,%rcx
cmp    %ecx,%eax
jne    1110 <athena_can_build+0x10>
xor    %eax,%eax
ret
mov    $0x1,%eax
ret

LLVM IR (-O0):
%struct.Athena_Class = type opaque
define i32 @athena_can_build(i32 %0, %struct.Athena_Class** %1, %struct.Athena_Class* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.Athena_Class**
%7 = alloca %struct.Athena_Class*
store i32 %0, i32* %5
store %struct.Athena_Class** %1, %struct.Athena_Class*** %6
store %struct.Athena_Class* %2, %struct.Athena_Class** %7
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %3
store i32 0, i32* %4
br label %24
11: ; preds = %3
%12 = load %struct.Athena_Class**, %struct.Athena_Class*** %6
%13 = load %struct.Athena_Class*, %struct.Athena_Class** %12
%14 = load %struct.Athena_Class*, %struct.Athena_Class** %7
%15 = icmp eq %struct.Athena_Class* %13, %14
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 1, i32* %4
br label %24
17: ; preds = %11
%18 = load i32, i32* %5
%19 = sub i32 %18, 1
%20 = load %struct.Athena_Class**, %struct.Athena_Class*** %6
%21 = getelementptr inbounds %struct.Athena_Class*, %struct.Athena_Class** %20, i64 1
%22 = load %struct.Athena_Class*, %struct.Athena_Class** %7
%23 = call i32 @athena_can_build(i32 %19, %struct.Athena_Class** %21, %struct.Athena_Class* %22)
store i32 %23, i32* %4
br label %24
24: ; preds = %17, %16, %10
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
%struct.Athena_Class = type opaque
define i32 @athena_can_build(i32 %0, %struct.Athena_Class** nocapture %1, %struct.Athena_Class* readnone %2) {
%4 = icmp eq i32 %0, 0
br i1 %4, label %14, label %5
5: ; preds = %3, %10
%6 = phi %struct.Athena_Class** [ %12, %10 ], [ %1, %3 ]
%7 = phi i32 [ %11, %10 ], [ %0, %3 ]
%8 = load %struct.Athena_Class*, %struct.Athena_Class** %6
%9 = icmp eq %struct.Athena_Class* %8, %2
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = add i32 %7, -1
%12 = getelementptr inbounds %struct.Athena_Class*, %struct.Athena_Class** %6, i64 1
%13 = icmp eq i32 %11, 0
br i1 %13, label %14, label %5
14: ; preds = %10, %5, %3
%15 = phi i32 [ 0, %3 ], [ 1, %5 ], [ 0, %10 ]
ret i32 %15
}