#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int get_n_from_user(void) {
  int n;
  printf("%s", "---\n"
               "TOWERS OF HANOI:\n"
               "\n"
               "There are three towers: A, B, and C.\n"
               "\n"
               "The disks on tower A must be moved to tower C.  Only one\n"
               "disk can be moved at a time, and the order on each tower\n"
               "must be preserved at each step.  Any of the towers A, B,\n"
               "or C can be used for intermediate placement of a disk.\n"
               "\n"
               "The problem starts with n disks on Tower A.\n"
               "\n"
               "Input n: ");
  if (scanf("%d", &n) != 1 || n < 1) {
    printf("\nERROR: Positive integer not found - bye!\n\n");
    exit(1);
  }
  printf("\n");
  return n;
}


x86 assembly (clang, -O0):
<get_n_from_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    0xebd(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0x1005(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    1170 <get_n_from_user+0x40>
cmpl   $0x1,-0x4(%rbp)
jge    1188 <get_n_from_user+0x58>
lea    0xfe5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xff7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_n_from_user>:
push   %rax
lea    0xea8(%rip),%rdi
lea    0xea4(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xfec(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1193 <get_n_from_user+0x43>
cmpl   $0x0,0x4(%rsp)
jle    1193 <get_n_from_user+0x43>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%eax
pop    %rcx
ret
lea    0xfc2(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [342 x i8] c"---\0ATOWERS OF HANOI:\0A\0AThere are three towers: A, B, and C.\0A\0AThe disks on tower A must be moved to tower C. Only one\0Adisk can be moved at a time, and the order on each tower\0Amust be preserved at each step. Any of the towers A, B,\0Aor C can be used for intermediate placement of a disk.\0A\0AThe problem starts with n disks on Tower A.\0A\0AInput n: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [44 x i8] c"\0AERROR: Positive integer not found - bye!\0A\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @get_n_from_user() {
%1 = alloca i32
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([342 x i8], [342 x i8]* @.str.1, i64 0, i64 0))
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%4 = icmp ne i32 %3, 1
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %5, %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%13 = load i32, i32* %1
ret i32 %13
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [342 x i8] c"---\0ATOWERS OF HANOI:\0A\0AThere are three towers: A, B, and C.\0A\0AThe disks on tower A must be moved to tower C. Only one\0Adisk can be moved at a time, and the order on each tower\0Amust be preserved at each step. Any of the towers A, B,\0Aor C can be used for intermediate placement of a disk.\0A\0AThe problem starts with n disks on Tower A.\0A\0AInput n: \00"
@.str.2 = [3 x i8] c"%d\00"
@str = [43 x i8] c"\0AERROR: Positive integer not found - bye!\0A\00"
define i32 @get_n_from_user() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([342 x i8], [342 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%5 = icmp ne i32 %4, 1
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 1
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i32 @putchar(i32 10)
%14 = load i32, i32* %1
ret i32 %14
}