#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 */
char EOF;
int EXIT_SUCCESS;
scalar_t__ SHRT_MAX;
char getchar();
int /*<<< orphan*/ printf(char *, int const, ...);
int /*<<< orphan*/ puts(char *);
int scanf(char *, int *);
int main(void) {
  const int LOWER_BOUND = 0;
  const int UPPER_BOUND = (int)SHRT_MAX;
  int n = 0;
  char c = '\0';
  printf("Please enter a number between %d and %d: ", LOWER_BOUND, UPPER_BOUND);
  while (scanf("%d", &n) < 1 || n < LOWER_BOUND || n >= UPPER_BOUND) {
    puts("Input invalid. Please try again.");
    while ((c = getchar()) != '\n' && c != EOF)
      continue;
  }
  while ((c = getchar()) != '\n' && c != EOF)
    continue;
  printf("In octal, your number is: %05o\n", n);
  getchar();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0xc(%rbp),%edx
lea    0xe88(%rip),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x1,%ecx
mov    %al,-0x12(%rbp)
jl     11bc <main+0x7c>
mov    $0x1,%al
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x12(%rbp)
jl     11bc <main+0x7c>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
setge  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    11cc <main+0x8c>
jmp    1223 <main+0xe3>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x13(%rbp)
je     1209 <main+0xc9>
movsbl -0x11(%rbp),%eax
mov    0x2dea(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
test   $0x1,%al
jne    1219 <main+0xd9>
jmp    121e <main+0xde>
jmp    11d8 <main+0x98>
jmp    1181 <main+0x41>
jmp    1228 <main+0xe8>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x14(%rbp)
je     1259 <main+0x119>
movsbl -0x11(%rbp),%eax
mov    0x2d9a(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x14(%rbp)
mov    -0x14(%rbp),%al
test   $0x1,%al
jne    1269 <main+0x129>
jmp    126e <main+0x12e>
jmp    1228 <main+0xe8>
mov    -0x10(%rbp),%esi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%ebp
movl   $0x0,0x4(%rsp)
lea    0xea5(%rip),%rdi
xor    %esi,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
lea    0xeb3(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
test   %eax,%eax
jle    1191 <main+0x51>
mov    0x4(%rsp),%eax
test   %eax,%eax
js     1191 <main+0x51>
cmp    %ebp,%eax
jl     11db <main+0x9b>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e44(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     1170 <main+0x30>
cmp    (%rbx),%al
jne    11b0 <main+0x70>
jmp    1170 <main+0x30>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%al
je     11e6 <main+0xa6>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    11d0 <main+0x90>
mov    0x4(%rsp),%esi
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SHRT_MAX = global i64 0
@.str = [42 x i8] c"Please enter a number between %d and %d: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"Input invalid. Please try again.\00"
@EOF = global i8 0
@.str.3 = [32 x i8] c"In octal, your number is: %05o\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
%6 = load i64, i64* @SHRT_MAX
%7 = trunc i64 %6 to i32
store i32 %7, i32* %3
store i32 0, i32* %4
store i8 0, i8* %5
%8 = load i32, i32* %3
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 0, i32 %8)
br label %10
10: ; preds = %37, %0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%12 = icmp slt i32 %11, 1
br i1 %12, label %20, label %13
13: ; preds = %10
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = icmp sge i32 %17, %18
br label %20
20: ; preds = %16, %13, %10
%21 = phi i1 [ true, %13 ], [ true, %10 ], [ %19, %16 ]
br i1 %21, label %22, label %38
22: ; preds = %20
%23 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %36, %22
%25 = call signext i8 (...) @getchar()
store i8 %25, i8* %5
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 10
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = load i8, i8* @EOF
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br label %34
34: ; preds = %28, %24
%35 = phi i1 [ false, %24 ], [ %33, %28 ]
br i1 %35, label %36, label %37
36: ; preds = %34
br label %24
37: ; preds = %34
br label %10
38: ; preds = %20
br label %39
39: ; preds = %51, %38
%40 = call signext i8 (...) @getchar()
store i8 %40, i8* %5
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 10
br i1 %42, label %43, label %49
43: ; preds = %39
%44 = load i8, i8* %5
%45 = sext i8 %44 to i32
%46 = load i8, i8* @EOF
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %45, %47
br label %49
49: ; preds = %43, %39
%50 = phi i1 [ false, %39 ], [ %48, %43 ]
br i1 %50, label %51, label %52
51: ; preds = %49
br label %39
52: ; preds = %49
%53 = load i32, i32* %4
%54 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %53)
%55 = call signext i8 (...) @getchar()
%56 = load i32, i32* @EXIT_SUCCESS
ret i32 %56
}

LLVM IR (-O2):
@SHRT_MAX = global i64 0
@.str = [42 x i8] c"Please enter a number between %d and %d: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"Input invalid. Please try again.\00"
@EOF = global i8 0
@.str.3 = [32 x i8] c"In octal, your number is: %05o\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = load i64, i64* @SHRT_MAX
%3 = trunc i64 %2 to i32
%4 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 0, i32 %3)
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = icmp sgt i32 %6, 0
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, -1
%10 = select i1 %7, i1 %9, i1 false
%11 = icmp slt i32 %8, %3
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %22
13: ; preds = %14, %0
br label %30
14: ; preds = %24
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%16 = icmp sgt i32 %15, 0
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, -1
%19 = select i1 %16, i1 %18, i1 false
%20 = icmp slt i32 %17, %3
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %13, label %22
22: ; preds = %0, %14
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %24, %22
%25 = call signext i8 (...) @getchar()
%26 = icmp ne i8 %25, 10
%27 = load i8, i8* @EOF
%28 = icmp ne i8 %25, %27
%29 = select i1 %26, i1 %28, i1 false
br i1 %29, label %24, label %14
30: ; preds = %13, %30
%31 = call signext i8 (...) @getchar()
%32 = icmp ne i8 %31, 10
%33 = load i8, i8* @EOF
%34 = icmp ne i8 %31, %33
%35 = select i1 %32, i1 %34, i1 false
br i1 %35, label %30, label %36
36: ; preds = %30
%37 = load i32, i32* %1
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = call signext i8 (...) @getchar()
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}