#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ tower(int, int, int, int);
int main() {
  int numDiscs;
  do {
    printf("Enter the number of discs: ");
    scanf("%d", &numDiscs);
    getchar();
    if (numDiscs <= 0)
      fprintf(stderr, "Error.\n");
  } while (numDiscs <= 0);
  tower(numDiscs, 1, 2, 3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
cmpl   $0x0,-0x8(%rbp)
jg     11a1 <main+0x51>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11a6 <main+0x56>
cmpl   $0x0,-0x8(%rbp)
jle    115f <main+0xf>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
mov    $0x2,%edx
mov    $0x3,%ecx
call   1070 <tower@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9c(%rip),%r14
lea    0xeb1(%rip),%r15
lea    0xc(%rsp),%r12
mov    0x2e69(%rip),%r13
lea    0xea1(%rip),%rbx
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0xc(%rsp),%edi
test   %edi,%edi
jg     11b6 <main+0x66>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
call   1050 <fprintf@plt>
mov    0xc(%rsp),%edi
test   %edi,%edi
jle    1180 <main+0x30>
mov    $0x1,%esi
mov    $0x2,%edx
mov    $0x3,%ecx
call   1070 <tower@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Enter the number of discs: \00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [8 x i8] c"Error.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %13, %0
%4 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 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)
%6 = call i32 (...) @getchar()
%7 = load i32, i32* %2
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %9, %3
br label %13
13: ; preds = %12
%14 = load i32, i32* %2
%15 = icmp sle i32 %14, 0
br i1 %15, label %3, label %16
16: ; preds = %13
%17 = load i32, i32* %2
%18 = call i32 @tower(i32 %17, i32 1, i32 2, i32 3)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Enter the number of discs: \00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [8 x i8] c"Error.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %9, %0
%4 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 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* %1)
%6 = call i32 (...) @getchar()
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* %1
%13 = icmp slt i32 %12, 1
br i1 %13, label %3, label %14
14: ; preds = %3, %9
%15 = phi i32 [ %12, %9 ], [ %7, %3 ]
%16 = call i32 @tower(i32 %15, i32 1, i32 2, i32 3)
ret i32 0
}