#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*/ move(int, int, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int ndisks;
  printf("Tower of Hanoi Recursive Function Example\n\n");
  do {
    printf("Enter the number of disks (1-8): ");
    scanf("%d", &ndisks);
    if (ndisks >= 0 && ndisks <= 8)
      break;
    printf("Please enter a value 1 to 8.\n");
  } while (1);
  move(ndisks, 1, 3, 2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
call   1030 <printf@plt>
lea    0xef0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jl     1180 <main+0x50>
cmpl   $0x8,-0x8(%rbp)
jg     1180 <main+0x50>
jmp    119b <main+0x6b>
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    114b <main+0x1b>
jmp    119b <main+0x6b>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
mov    $0x3,%edx
mov    $0x2,%ecx
call   1050 <move@plt>
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    0xed6(%rip),%rdi
call   1030 <puts@plt>
lea    0xea5(%rip),%rdi
call   1040 <printf@plt>
lea    0xebb(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
cmp    $0x9,%edi
jb     11c4 <main+0x84>
lea    0xecf(%rip),%r14
lea    0xe78(%rip),%r15
lea    0xe93(%rip),%r12
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
cmp    $0x8,%edi
ja     11a0 <main+0x60>
mov    $0x1,%esi
mov    $0x3,%edx
mov    $0x2,%ecx
call   1060 <move@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Tower of Hanoi Recursive Function Example\0A\0A\00"
@.str.1 = [34 x i8] c"Enter the number of disks (1-8): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [30 x i8] c"Please enter a value 1 to 8.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %15, %0
%5 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = load i32, i32* %2
%11 = icmp sle i32 %10, 8
br i1 %11, label %12, label %13
12: ; preds = %9
br label %16
13: ; preds = %9, %4
%14 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13
br i1 true, label %4, label %16
16: ; preds = %15, %12
%17 = load i32, i32* %2
%18 = call i32 @move(i32 %17, i32 1, i32 3, i32 2)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [34 x i8] c"Enter the number of disks (1-8): \00"
@.str.2 = [3 x i8] c"%d\00"
@str = [43 x i8] c"Tower of Hanoi Recursive Function Example\0A\00"
@str.4 = [29 x i8] c"Please enter a value 1 to 8.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%4 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp ult i32 %6, 9
br i1 %7, label %14, label %8
8: ; preds = %0, %8
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.4, i64 0, i64 0))
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = icmp ult i32 %12, 9
br i1 %13, label %14, label %8
14: ; preds = %8, %0
%15 = phi i32 [ %6, %0 ], [ %12, %8 ]
%16 = call i32 @move(i32 %15, i32 1, i32 3, i32 2)
ret i32 0
}