#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 pow(int, int);
int /*<<< orphan*/ printf(char *, int, int, int);
void toh(int n) {
  int steps, start, end, i;
  steps = pow(2, n);
  for (i = 1; i < steps; i++) {
    start = (i & (i - 1)) % 3;
    end = (1 + (i | (i - 1))) % 3;
    printf("Disc %d shifted from %d to %d\n", i, start + 1, end + 1);
  }
}


x86 assembly (clang, -O0):
<toh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %eax,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a6 <toh+0x86>
mov    -0x14(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
and    %ecx,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
or     %ecx,%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1142 <toh+0x22>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toh>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%esi
mov    $0x2,%edi
call   1040 <pow@plt>
cmp    $0x2,%eax
jl     11a1 <toh+0x81>
mov    %eax,%ebp
mov    $0x1,%ebx
mov    $0xaaaaaaab,%r15d
lea    0xeb4(%rip),%r14
nopl   0x0(%rax)
lea    -0x1(%rbx),%ecx
mov    %ecx,%eax
and    %ebx,%eax
mov    %rax,%rdx
imul   %r15,%rdx
shr    $0x21,%rdx
lea    (%rdx,%rdx,2),%edx
or     %ebx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
imul   $0x55555556,%rcx,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
shr    $0x20,%rsi
add    %edi,%esi
lea    (%rsi,%rsi,2),%esi
sub    %esi,%ecx
neg    %edx
add    %eax,%edx
add    $0x1,%edx
add    $0x1,%ecx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1150 <toh+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [31 x i8] c"Disc %d shifted from %d to %d\0A\00"
define void @toh(i32 %0) {
%2 = tail call i32 @pow(i32 2, i32 %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 ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %5, 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
}