#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ move(int **, int, int, int);
int /*<<< orphan*/ printHanoi(int **, int);
int save_which(int, int);
int /*<<< orphan*/ stderr;
void hanoi(int **state, int m, int from, int to, int n) {
  int save;
  if (m <= 0) {
    fprintf(stderr, "in hanoi, m should be positive integer.");
    exit(1);
  }
  if (m == 1) {
    move(state, from, to, n);
    printHanoi(state, n);
  } else {
    save = save_which(from, to);
    hanoi(state, m - 1, from, save, n);
    hanoi(state, 1, from, to, n);
    hanoi(state, m - 1, save, to, n);
  }
}


x86 assembly (clang, -O0):
<hanoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     11a2 <hanoi+0x42>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x1,-0xc(%rbp)
jne    11cf <hanoi+0x6f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1080 <move@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <printHanoi@plt>
jmp    1227 <hanoi+0xc7>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <save_which@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1060 <hanoi@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    $0x1,%esi
call   1060 <hanoi@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x1c(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1060 <hanoi@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hanoi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11fb <hanoi+0x9b>
mov    %r8d,%r15d
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r12
cmp    $0x1,%esi
jne    118a <hanoi+0x2a>
mov    %ebx,%r13d
jmp    11d1 <hanoi+0x71>
add    $0xffffffff,%ebp
nopl   (%rax)
mov    %ebx,%edi
mov    %r14d,%esi
call   1050 <save_which@plt>
mov    %eax,%r13d
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
mov    %r15d,%r8d
call   1060 <hanoi@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
call   1080 <move@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1030 <printHanoi@plt>
mov    %r13d,%ebx
add    $0xffffffff,%ebp
jne    1190 <hanoi+0x30>
mov    %r12,%rdi
mov    %r13d,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
call   1080 <move@plt>
mov    %r12,%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printHanoi@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"in hanoi, m should be positive integer.\00"
define void @hanoi(i32** %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32** %0, i32*** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %7
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %5
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %5
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = load i32**, i32*** %6
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = call i32 @move(i32** %22, i32 %23, i32 %24, i32 %25)
%27 = load i32**, i32*** %6
%28 = load i32, i32* %10
%29 = call i32 @printHanoi(i32** %27, i32 %28)
br label %50
30: ; preds = %18
%31 = load i32, i32* %8
%32 = load i32, i32* %9
%33 = call i32 @save_which(i32 %31, i32 %32)
store i32 %33, i32* %11
%34 = load i32**, i32*** %6
%35 = load i32, i32* %7
%36 = sub nsw i32 %35, 1
%37 = load i32, i32* %8
%38 = load i32, i32* %11
%39 = load i32, i32* %10
%40 = load i32**, i32*** %6
%41 = load i32, i32* %8
%42 = load i32, i32* %9
%43 = load i32, i32* %10
%44 = load i32**, i32*** %6
%45 = load i32, i32* %7
%46 = sub nsw i32 %45, 1
%47 = load i32, i32* %11
%48 = load i32, i32* %9
%49 = load i32, i32* %10
br label %50
50: ; preds = %30, %21
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"in hanoi, m should be positive integer.\00"
define void @hanoi(i32** %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp slt i32 %1, 1
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = icmp eq i32 %1, 1
br i1 %8, label %13, label %17
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %17, %7
%14 = phi i32 [ %2, %7 ], [ %20, %17 ]
%15 = tail call i32 @move(i32** %0, i32 %14, i32 %3, i32 %4)
%16 = tail call i32 @printHanoi(i32** %0, i32 %4)
ret void
17: ; preds = %7, %17
%18 = phi i32 [ %21, %17 ], [ %1, %7 ]
%19 = phi i32 [ %20, %17 ], [ %2, %7 ]
%20 = tail call i32 @save_which(i32 %19, i32 %3)
%21 = add nsw i32 %18, -1
tail call void @hanoi(i32** %0, i32 %21, i32 %19, i32 %20, i32 %4)
%22 = tail call i32 @move(i32** %0, i32 %19, i32 %3, i32 %4)
%23 = tail call i32 @printHanoi(i32** %0, i32 %4)
%24 = icmp eq i32 %21, 1
br i1 %24, label %13, label %17
}