#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 towerOfHanoi(int numDisks) {
  int i;
  int fromPeg, toPeg;
  int numPegs = 3;
  for (i = 1; i < (1 << numDisks); i++) {
    fromPeg = (i & i - 1) % numPegs;
    toPeg = ((i | i - 1) + 1) % numPegs;
    printf("%d --> %d\n", fromPeg + 1, toPeg + 1);
  }
}


x86 assembly (clang, -O0):
<towerOfHanoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x3,-0x14(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jge    118d <towerOfHanoi+0x7d>
mov    -0x8(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
and    %ecx,%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
or     %ecx,%eax
add    $0x1,%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <towerOfHanoi+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<towerOfHanoi>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ecx
mov    $0x1,%ebx
mov    $0x1,%ebp
shl    %cl,%ebp
cmp    $0x2,%ebp
jl     118f <towerOfHanoi+0x7f>
mov    $0xaaaaaaab,%r15d
lea    0xec9(%rip),%r14
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%ecx
mov    %ecx,%eax
and    %ebx,%eax
mov    %rax,%rdx
imul   %r15,%rdx
shr    $0x21,%rdx
lea    (%rdx,%rdx,2),%esi
or     %ebx,%ecx
add    $0x1,%ecx
movslq %ecx,%rdx
imul   $0x55555556,%rdx,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
shr    $0x20,%rcx
add    %edi,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%edx
neg    %esi
add    %eax,%esi
add    $0x1,%esi
add    $0x1,%edx
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1140 <towerOfHanoi+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%d --> %d\0A\00"
define void @towerOfHanoi(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 3, i32* %6
store i32 1, i32* %3
br label %7
7: ; preds = %31, %1
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = shl i32 1, %9
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %34
12: ; preds = %7
%13 = load i32, i32* %3
%14 = load i32, i32* %3
%15 = sub nsw i32 %14, 1
%16 = and i32 %13, %15
%17 = load i32, i32* %6
%18 = srem i32 %16, %17
store i32 %18, i32* %4
%19 = load i32, i32* %3
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 1
%22 = or i32 %19, %21
%23 = add nsw i32 %22, 1
%24 = load i32, i32* %6
%25 = srem i32 %23, %24
store i32 %25, i32* %5
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
%30 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %29)
br label %31
31: ; preds = %12
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %7
34: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"%d --> %d\0A\00"
define void @towerOfHanoi(i32 %0) {
%2 = shl nuw i32 1, %0
%3 = icmp sgt i32 %2, 1
br i1 %3, label %4, label %17
4: ; preds = %1, %4
%5 = phi i32 [ %15, %4 ], [ 1, %1 ]
%6 = add nsw i32 %5, -1
%7 = and i32 %6, %5
%8 = urem i32 %7, 3
%9 = or i32 %6, %5
%10 = add nsw i32 %9, 1
%11 = srem i32 %10, 3
%12 = add nuw nsw i32 %8, 1
%13 = add nsw i32 %11, 1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%15 = add nuw nsw i32 %5, 1
%16 = icmp eq i32 %15, %2
br i1 %16, label %17, label %4
17: ; preds = %4, %1
ret void
}