#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 atoi(char const *);
int /*<<< orphan*/ hanoi(int, int, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int Hanoi(size_t argc, const char **argv) {
  if (argc <= (1)) {
    printf("Insufficient arguments. %d expected, %zd given.\n", (1), argc - 1);
    return -1;
  };
  int n = atoi(argv[1]);
  int MAXN = 15;
  if (n < 1 || n > MAXN) {
    printf("The argument must be between 1 and %d.\n", MAXN);
    return n;
  }
  printf("We shall move %d disks from tile 1 to tile 2 via tile 3.\n", n);
  hanoi(n, 1, 2, 3);
  return 0;
}


x86 assembly (clang, -O0):
<Hanoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x1,-0x10(%rbp)
ja     1172 <Hanoi+0x42>
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
lea    0xea6(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ea <Hanoi+0xba>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0xf,-0x20(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jl     119f <Hanoi+0x6f>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    11bb <Hanoi+0x8b>
mov    -0x20(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ea <Hanoi+0xba>
mov    -0x1c(%rbp),%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
mov    $0x2,%edx
mov    $0x3,%ecx
call   1050 <hanoi@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Hanoi>:
push   %rbx
cmp    $0x1,%rdi
ja     1158 <Hanoi+0x28>
mov    %rdi,%rdx
add    $0xffffffffffffffff,%rdx
lea    0xebb(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
jmp    11a8 <Hanoi+0x78>
mov    0x8(%rsi),%rdi
call   1040 <atoi@plt>
mov    %eax,%ebx
add    $0xfffffff0,%eax
cmp    $0xfffffff0,%eax
ja     1180 <Hanoi+0x50>
lea    0xebf(%rip),%rdi
mov    $0xf,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a8 <Hanoi+0x78>
lea    0xed2(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x2,%edx
mov    $0x3,%ecx
call   1050 <hanoi@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Insufficient arguments. %d expected, %zd given.\0A\00"
@.str.1 = [40 x i8] c"The argument must be between 1 and %d.\0A\00"
@.str.2 = [58 x i8] c"We shall move %d disks from tile 1 to tile 2 via tile 3.\0A\00"
define i32 @Hanoi(i64 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i64 %0, i64* %4
store i8** %1, i8*** %5
%8 = load i64, i64* %4
%9 = icmp ule i64 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i64, i64* %4
%12 = sub i64 %11, 1
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 1, i64 %12)
store i32 -1, i32* %3
br label %34
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
store i32 15, i32* %7
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 1
br i1 %20, label %25, label %21
21: ; preds = %14
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %29
25: ; preds = %21, %14
%26 = load i32, i32* %7
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %34
29: ; preds = %21
%30 = load i32, i32* %6
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %6
%33 = call i32 @hanoi(i32 %32, i32 1, i32 2, i32 3)
store i32 0, i32* %3
br label %34
34: ; preds = %29, %25, %10
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [49 x i8] c"Insufficient arguments. %d expected, %zd given.\0A\00"
@.str.1 = [40 x i8] c"The argument must be between 1 and %d.\0A\00"
@.str.2 = [58 x i8] c"We shall move %d disks from tile 1 to tile 2 via tile 3.\0A\00"
define i32 @Hanoi(i64 %0, i8** nocapture %1) {
%3 = icmp ult i64 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = add nsw i64 %0, -1
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 1, i64 %5)
br label %18
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = add i32 %10, -16
%12 = icmp ult i32 %11, -15
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 15)
br label %18
15: ; preds = %7
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%17 = tail call i32 @hanoi(i32 %10, i32 1, i32 2, i32 3)
br label %18
18: ; preds = %13, %15, %4
%19 = phi i32 [ -1, %4 ], [ %10, %13 ], [ 0, %15 ]
ret i32 %19
}