int tower(int n, char beg, char end, char aux) {
  static int count = 0;
  if (n == 1) {
    count = count + 1;
  } else {
    tower(n - 1, beg, aux, end);
    tower(1, beg, end, aux);
    tower(n - 1, aux, end, beg);
  }
  return (count);
}


x86 assembly (clang, -O0):
<tower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %edi,-0x4(%rbp)
mov    %dl,-0x5(%rbp)
mov    %cl,-0x6(%rbp)
mov    %al,-0x7(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1149 <tower+0x39>
mov    0x2ef1(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ee8(%rip)
jmp    1199 <tower+0x89>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x5(%rbp),%cl
mov    -0x7(%rbp),%al
movsbl %cl,%esi
movsbl %al,%edx
movsbl -0x6(%rbp),%ecx
call   1030 <tower@plt>
mov    -0x5(%rbp),%cl
mov    -0x6(%rbp),%al
mov    $0x1,%edi
movsbl %cl,%esi
movsbl %al,%edx
movsbl -0x7(%rbp),%ecx
call   1030 <tower@plt>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x7(%rbp),%cl
mov    -0x6(%rbp),%al
movsbl %cl,%esi
movsbl %al,%edx
movsbl -0x5(%rbp),%ecx
call   1030 <tower@plt>
mov    0x2e8d(%rip),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tower>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    112d <tower+0x1d>
mov    0x2f0a(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2f01(%rip)
jmp    1168 <tower+0x58>
mov    %edi,%ebx
add    $0xffffffff,%ebx
movsbl %sil,%r14d
movsbl %cl,%ebp
movsbl %dl,%r15d
mov    %ebx,%edi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
call   1030 <tower@plt>
addl   $0x1,0x2ed9(%rip)
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1030 <tower@plt>
mov    0x2ec4(%rip),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@tower.count = internal unnamed_addr global i32 0
define i32 @tower(i32 %0, i8 signext %1, i8 signext %2, i8 signext %3) {
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %4
%7 = load i32, i32* @tower.count
%8 = add nsw i32 %7, 1
store i32 %8, i32* @tower.count
br label %16
9: ; preds = %4
%10 = add nsw i32 %0, -1
%11 = tail call i32 @tower(i32 %10, i8 signext %1, i8 signext %3, i8 signext %2)
%12 = load i32, i32* @tower.count
%13 = add nsw i32 %12, 1
store i32 %13, i32* @tower.count
%14 = tail call i32 @tower(i32 %10, i8 signext %3, i8 signext %2, i8 signext %1)
%15 = load i32, i32* @tower.count
br label %16
16: ; preds = %9, %6
%17 = phi i32 [ %15, %9 ], [ %8, %6 ]
ret i32 %17
}