#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*/ moves(int, char, char, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int n;
  printf("Enter the number of disks: ");
  scanf("%d", &n);
  int i;
  int m = 1;
  for (i = 1; i < n + 1; i++) {
    m = 2 * m;
  }
  m = m - 1;
  printf("The Tower of Hanoi is solved in %d moves. \n", m);
  printf("This involves the moves: \n \n");
  moves(n, 'A', 'C', 'B');
  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    0xec8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1193 <main+0x63>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116b <main+0x3b>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x41,%esi
mov    $0x43,%edx
mov    $0x42,%ecx
call   1040 <moves@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec0(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
jle    11aa <main+0x6a>
lea    -0x1(%rcx),%edx
mov    %ecx,%eax
and    $0x7,%eax
cmp    $0x7,%edx
jae    1182 <main+0x42>
mov    $0x1,%ebx
jmp    1198 <main+0x58>
and    $0xfffffff8,%ecx
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
shl    $0x8,%ebx
add    $0xfffffff8,%ecx
jne    1190 <main+0x50>
test   %eax,%eax
je     11a7 <main+0x67>
nopl   0x0(%rax)
add    %ebx,%ebx
add    $0xffffffff,%eax
jne    11a0 <main+0x60>
add    $0xffffffff,%ebx
lea    0xe6e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
mov    $0x41,%esi
mov    $0x43,%edx
mov    $0x42,%ecx
call   1050 <moves@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Enter the number of disks: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [44 x i8] c"The Tower of Hanoi is solved in %d moves. \0A\00"
@.str.3 = [29 x i8] c"This involves the moves: \0A \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 1, i32* %4
store i32 1, i32* %3
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = load i32, i32* %4
%14 = mul nsw i32 2, %13
store i32 %14, i32* %4
br label %15
15: ; preds = %12
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %7
18: ; preds = %7
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* %2
%25 = call i32 @moves(i32 %24, i8 signext 65, i8 signext 67, i8 signext 66)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Enter the number of disks: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [44 x i8] c"The Tower of Hanoi is solved in %d moves. \0A\00"
@str = [28 x i8] c"This involves the moves: \0A \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 1
br i1 %6, label %32, label %7
7: ; preds = %0
%8 = add i32 %5, -1
%9 = and i32 %5, 7
%10 = icmp ult i32 %8, 7
br i1 %10, label %19, label %11
11: ; preds = %7
%12 = and i32 %5, -8
br label %13
13: ; preds = %13, %11
%14 = phi i32 [ 1, %11 ], [ %16, %13 ]
%15 = phi i32 [ 0, %11 ], [ %17, %13 ]
%16 = shl i32 %14, 8
%17 = add i32 %15, 8
%18 = icmp eq i32 %17, %12
br i1 %18, label %19, label %13
19: ; preds = %13, %7
%20 = phi i32 [ undef, %7 ], [ %16, %13 ]
%21 = phi i32 [ 1, %7 ], [ %16, %13 ]
%22 = icmp eq i32 %9, 0
br i1 %22, label %29, label %23
23: ; preds = %19, %23
%24 = phi i32 [ %26, %23 ], [ %21, %19 ]
%25 = phi i32 [ %27, %23 ], [ 0, %19 ]
%26 = shl nsw i32 %24, 1
%27 = add i32 %25, 1
%28 = icmp eq i32 %27, %9
br i1 %28, label %29, label %23
29: ; preds = %23, %19
%30 = phi i32 [ %20, %19 ], [ %26, %23 ]
%31 = add i32 %30, -1
br label %32
32: ; preds = %29, %0
%33 = phi i32 [ 0, %0 ], [ %31, %29 ]
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%36 = load i32, i32* %1
%37 = call i32 @moves(i32 %36, i8 signext 65, i8 signext 67, i8 signext 66)
ret i32 0
}