#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 /*<<< orphan*/ printf(char *, int, int, int);
void towers(int n, int start, int end) {
  int mid = 6 - start - end;
  if (n > 0) {
    towers(n - 1, start, mid);
    printf("Move disk #%d from tower #%d to tower #%d.\n", n, start, end);
    towers(n - 1, mid, end);
  }
}


x86 assembly (clang, -O0):
<towers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0x6,%eax
sub    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1180 <towers+0x60>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <towers@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <towers@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<towers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    1175 <towers+0x55>
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%r15d
lea    0xec2(%rip),%r12
xchg   %ax,%ax
mov    $0x6,%ebp
sub    %ebx,%ebp
sub    %r14d,%ebp
lea    -0x1(%r15),%r13d
mov    %r13d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
call   1040 <towers@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
call   1030 <printf@plt>
mov    %ebp,%ebx
cmp    $0x1,%r15d
mov    %r13d,%r15d
ja     1140 <towers+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Move disk #%d from tower #%d to tower #%d.\0A\00"
define void @towers(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = sub nsw i32 6, %8
%10 = load i32, i32* %6
%11 = sub nsw i32 %9, %10
store i32 %11, i32* %7
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %3
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = load i32, i32* %5
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20, i32 %21)
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
%25 = load i32, i32* %7
%26 = load i32, i32* %6
br label %27
27: ; preds = %14, %3
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"Move disk #%d from tower #%d to tower #%d.\0A\00"
define void @towers(i32 %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %13
5: ; preds = %3, %5
%6 = phi i32 [ %9, %5 ], [ %1, %3 ]
%7 = phi i32 [ %10, %5 ], [ %0, %3 ]
%8 = add i32 %6, %2
%9 = sub i32 6, %8
%10 = add nsw i32 %7, -1
tail call void @towers(i32 %10, i32 %6, i32 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %6, i32 %2)
%12 = icmp ugt i32 %7, 1
br i1 %12, label %5, label %13
13: ; preds = %5, %3
ret void
}