#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 towersHelper(int pegs, int origin, int dist) {
  if (pegs == 0) {
    return;
  }
  int rem = 6 - origin - dist;
  towersHelper(pegs - 1, origin, rem);
  printf("Move peg %d from tower %d to tower %d.\n", pegs, origin, dist);
  towersHelper(pegs - 1, rem, dist);
}


x86 assembly (clang, -O0):
<towersHelper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1140 <towersHelper+0x20>
jmp    1185 <towersHelper+0x65>
mov    $0x6,%eax
sub    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <towersHelper@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <towersHelper@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<towersHelper>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
je     1170 <towersHelper+0x50>
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
lea    0xec5(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    $0x6,%ebp
sub    %r15d,%ebp
sub    %r14d,%ebp
lea    -0x1(%rbx),%edi
mov    %r15d,%esi
mov    %ebp,%edx
call   1040 <towersHelper@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1030 <printf@plt>
mov    %ebp,%r15d
add    $0xffffffff,%ebx
jne    1140 <towersHelper+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Move peg %d from tower %d to tower %d.\0A\00"
define void @towersHelper(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %3
br label %28
11: ; preds = %3
%12 = load i32, i32* %5
%13 = sub nsw i32 6, %12
%14 = load i32, i32* %6
%15 = sub nsw i32 %13, %14
store i32 %15, i32* %7
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 1
%18 = load i32, i32* %5
%19 = load i32, i32* %7
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21, i32 %22)
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
%26 = load i32, i32* %7
%27 = load i32, i32* %6
br label %28
28: ; preds = %11, %10
ret void
}

LLVM IR (-O2):
@.str = [40 x i8] c"Move peg %d from tower %d to tower %d.\0A\00"
define void @towersHelper(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %0, 0
br i1 %4, label %13, label %5
5: ; preds = %3, %5
%6 = phi i32 [ %9, %5 ], [ %1, %3 ]
%7 = phi i32 [ %10, %5 ], [ %0, %3 ]
%8 = add i32 %6, %2
%9 = sub i32 6, %8
%10 = add nsw i32 %7, -1
tail call void @towersHelper(i32 %10, i32 %6, i32 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %6, i32 %2)
%12 = icmp eq i32 %10, 0
br i1 %12, label %13, label %5
13: ; preds = %5, %3
ret void
}