#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, int);
void hanoi(int a, int n1, int n2) {
  if (a == 1) {
    printf("%d %d %d\n", a, n1, n2);
  } else {
    int x, na;
    for (x = 1; x <= 3; x++) {
      if ((x != n1) && (x != n2)) {
        na = x;
        break;
      }
    }
    hanoi(a - 1, n1, na);
    printf("%d %d %d\n", a, n1, n2);
    hanoi(a - 1, na, n2);
  }
}


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)
cmpl   $0x1,-0x4(%rbp)
jne    1155 <hanoi+0x35>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
jmp    11d3 <hanoi+0xb3>
movl   $0x1,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jg     119c <hanoi+0x7c>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     1189 <hanoi+0x69>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1189 <hanoi+0x69>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    119c <hanoi+0x7c>
jmp    118e <hanoi+0x6e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115c <hanoi+0x3c>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <hanoi@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
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
mov    %edx,%r14d
mov    %esi,%ebp
cmp    $0x1,%edi
jne    115d <hanoi+0x3d>
mov    %ebp,%r12d
lea    0xec1(%rip),%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
mov    %edi,%ebx
add    $0xffffffff,%ebx
lea    0xe97(%rip),%r15
jmp    11ab <hanoi+0x8b>
nopl   0x0(%rax,%rax,1)
cmp    $0x3,%r14d
sete   %al
cmp    $0x3,%ebp
sete   %cl
or     %al,%cl
movzbl %cl,%r12d
add    $0x3,%r12d
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r12d,%edx
call   1040 <hanoi@plt>
mov    %r15,%rdi
mov    %r13d,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1030 <printf@plt>
mov    %r12d,%ebp
add    $0xffffffff,%ebx
je     1138 <hanoi+0x18>
lea    0x1(%rbx),%r13d
cmp    $0x1,%ebp
je     11c0 <hanoi+0xa0>
mov    $0x1,%r12d
cmp    $0x1,%r14d
jne    1187 <hanoi+0x67>
cmp    $0x2,%ebp
je     1170 <hanoi+0x50>
mov    $0x2,%r12d
cmp    $0x2,%r14d
jne    1187 <hanoi+0x67>
jmp    1170 <hanoi+0x50>

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

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