#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  printf("Enter the number of Disks");
  int n;
  scanf("%d", &n);
  for (int i = 1; i < (1 << n); i++)
    printf("\nMove from Peg %d to Peg %d", (i & i - 1) % 3 + 1,
           ((i | i - 1) + 1) % 3 + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeef(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jge    11b8 <main+0x98>
mov    -0xc(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
and    %ecx,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
add    $0x1,%esi
mov    -0xc(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
or     %ecx,%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1154 <main+0x34>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%cl
mov    $0x1,%ebx
mov    $0x1,%eax
shl    %cl,%eax
cmp    $0x2,%eax
jl     11ce <main+0xae>
mov    $0xaaaaaaab,%r15d
lea    0xeb0(%rip),%r14
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%eax
mov    %eax,%ecx
and    %ebx,%ecx
mov    %rcx,%rdx
imul   %r15,%rdx
shr    $0x21,%rdx
lea    (%rdx,%rdx,2),%edx
neg    %edx
lea    (%rcx,%rdx,1),%esi
add    $0x1,%esi
or     %ebx,%eax
add    $0x1,%eax
movslq %eax,%rdx
imul   $0x55555556,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%edx
add    $0x1,%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
movzbl 0xc(%rsp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cmp    %eax,%ebx
jl     1170 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [26 x i8] c"Enter the number of Disks\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"\0AMove from Peg %d to Peg %d\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl nuw i32 1, %5
%7 = icmp sgt i32 %6, 1
br i1 %7, label %9, label %8
8: ; preds = %9, %0
ret i32 0
9: ; preds = %0, %9
%10 = phi i32 [ %20, %9 ], [ 1, %0 ]
%11 = add nsw i32 %10, -1
%12 = and i32 %11, %10
%13 = urem i32 %12, 3
%14 = add nuw nsw i32 %13, 1
%15 = or i32 %11, %10
%16 = add nsw i32 %15, 1
%17 = srem i32 %16, 3
%18 = add nsw i32 %17, 1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %18)
%20 = add nuw nsw i32 %10, 1
%21 = load i32, i32* %1
%22 = shl nuw i32 1, %21
%23 = icmp slt i32 %20, %22
br i1 %23, label %9, label %8
}