#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, ...);
void hanoi(int n, int a, int b, long *steps) {
  int c = 6 - a - b;
  if (n != 0) {
    hanoi(n - 1, a, c, steps);
    if (steps != NULL) {
      (*steps)++;
      printf("step %ld : %d --> %d\n", *steps, a, b);
    } else {
      printf("%d --> %d\n", a, b);
    }
    hanoi(n - 1, c, b, steps);
  }
}


x86 assembly (clang, -O0):
<hanoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    $0x6,%eax
sub    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11c6 <hanoi+0xa6>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <hanoi@plt>
cmpq   $0x0,-0x18(%rbp)
je     119d <hanoi+0x7d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b1 <hanoi+0x91>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <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   %edi,%edi
je     11a8 <hanoi+0x88>
mov    %rcx,%r13
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
add    $0xffffffff,%ebp
lea    0xebd(%rip),%r12
jmp    116b <hanoi+0x4b>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xeb4(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15d,%ebx
add    $0xffffffff,%ebp
jae    11a8 <hanoi+0x88>
mov    $0x6,%r15d
sub    %ebx,%r15d
sub    %r14d,%r15d
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r13,%rcx
call   1040 <hanoi@plt>
test   %r13,%r13
je     1150 <hanoi+0x30>
mov    0x0(%r13),%rsi
add    $0x1,%rsi
mov    %rsi,0x0(%r13)
mov    %r12,%rdi
mov    %ebx,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1163 <hanoi+0x43>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"step %ld : %d --> %d\0A\00"
@.str.1 = [11 x i8] c"%d --> %d\0A\00"
define void @hanoi(i32 %0, i32 %1, i32 %2, i64* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i64* %3, i64** %8
%10 = load i32, i32* %6
%11 = sub nsw i32 6, %10
%12 = load i32, i32* %7
%13 = sub nsw i32 %11, %12
store i32 %13, i32* %9
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %44
16: ; preds = %4
%17 = load i32, i32* %5
%18 = sub nsw i32 %17, 1
%19 = load i32, i32* %6
%20 = load i32, i32* %9
%21 = load i64*, i64** %8
%22 = load i64*, i64** %8
%23 = icmp ne i64* %22, null
br i1 %23, label %24, label %34
24: ; preds = %16
%25 = load i64*, i64** %8
%26 = load i64, i64* %25
%27 = add nsw i64 %26, 1
store i64 %27, i64* %25
%28 = load i64*, i64** %8
%29 = load i64, i64* %28
%30 = trunc i64 %29 to i32
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %31, i32 %32)
br label %38
34: ; preds = %16
%35 = load i32, i32* %6
%36 = load i32, i32* %7
%37 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %36)
br label %38
38: ; preds = %34, %24
%39 = load i32, i32* %5
%40 = sub nsw i32 %39, 1
%41 = load i32, i32* %9
%42 = load i32, i32* %7
%43 = load i64*, i64** %8
br label %44
44: ; preds = %38, %4
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"step %ld : %d --> %d\0A\00"
@.str.1 = [11 x i8] c"%d --> %d\0A\00"
define void @hanoi(i32 %0, i32 %1, i32 %2, i64* %3) {
%5 = icmp eq i32 %0, 0
br i1 %5, label %23, label %6
6: ; preds = %4
%7 = icmp eq i64* %3, null
br label %8
8: ; preds = %6, %21
%9 = phi i32 [ %1, %6 ], [ %12, %21 ]
%10 = phi i32 [ %0, %6 ], [ %13, %21 ]
%11 = add i32 %9, %2
%12 = sub i32 6, %11
%13 = add nsw i32 %10, -1
tail call void @hanoi(i32 %13, i32 %9, i32 %12, i64* %3)
br i1 %7, label %19, label %14
14: ; preds = %8
%15 = load i64, i64* %3
%16 = add nsw i64 %15, 1
store i64 %16, i64* %3
%17 = trunc i64 %16 to i32
%18 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %9, i32 %2)
br label %21
19: ; preds = %8
%20 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %2)
br label %21
21: ; preds = %19, %14
%22 = icmp eq i32 %13, 0
br i1 %22, label %23, label %8
23: ; preds = %21, %4
ret void
}