#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;
int /*<<< orphan*/ StringReverse(char *, int /*<<< orphan*/, scalar_t__);
char getchar();
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ strlen(char *);
int main(void) {
  char buffer[16] = {0};
  const int DIGIT_COUNT = 2;
  int isInputValid = 0;
  printf("Please enter a %d-digit number: ", DIGIT_COUNT);
  while (!isInputValid) {
    isInputValid = 1;
    int i = 0;
    char c = '\0';
    while ((c = getchar()) != '\n' && c != EOF) {
      if (isdigit(c) && i < DIGIT_COUNT) {
        buffer[i] = c;
        ++i;
      } else {
        isInputValid = 0;
      }
    }
    buffer[i] = '\0';
    if (i == 0) {
      isInputValid = 0;
    }
    if (!isInputValid) {
      puts("Input invalid. Please try again.");
    }
  }
  StringReverse(buffer, 0, strlen(buffer) - 1);
  printf("The reversal is: %s\n", buffer);
  getchar();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
movl   $0x2,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xe5c(%rip),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x28(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c6 <main+0x56>
jmp    1290 <main+0x120>
movl   $0x1,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movb   $0x0,-0x2d(%rbp)
mov    $0x0,%al
call   1090 <getchar@plt>
mov    %al,-0x2d(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x2e(%rbp)
je     1209 <main+0x99>
movsbl -0x2d(%rbp),%eax
mov    0x2dea(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x2e(%rbp)
mov    -0x2e(%rbp),%al
test   $0x1,%al
jne    1219 <main+0xa9>
jmp    125b <main+0xeb>
movsbl -0x2d(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     124f <main+0xdf>
cmpl   $0x2,-0x2c(%rbp)
jge    124f <main+0xdf>
mov    -0x2d(%rbp),%cl
movslq -0x2c(%rbp),%rax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1256 <main+0xe6>
movl   $0x0,-0x28(%rbp)
jmp    11d8 <main+0x68>
movslq -0x2c(%rbp),%rax
movb   $0x0,-0x20(%rbp,%rax,1)
cmpl   $0x0,-0x2c(%rbp)
jne    1275 <main+0x105>
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    128b <main+0x11b>
lea    0xd9b(%rip),%rdi
call   1040 <puts@plt>
jmp    11b0 <main+0x40>
lea    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
sub    $0x1,%rdx
xor    %esi,%esi
call   1050 <StringReverse@plt>
lea    -0x20(%rbp),%rsi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1090 <getchar@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0xe86(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2e5b(%rip),%r15
lea    0xe8d(%rip),%r14
jmp    11ac <main+0x4c>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,(%rsp)
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%al
je     11a0 <main+0x40>
mov    %eax,%ebx
cmp    (%r15),%al
je     11a0 <main+0x40>
mov    $0x1,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movsbl %bl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11f0 <main+0x90>
cmp    $0x1,%ebp
jg     11f0 <main+0x90>
movslq %ebp,%rax
mov    %bl,(%rsp,%rax,1)
add    $0x1,%ebp
jmp    11f3 <main+0x93>
nopl   (%rax)
xor    %r12d,%r12d
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%al
je     1205 <main+0xa5>
mov    %eax,%ebx
cmp    (%r15),%al
jne    11d0 <main+0x70>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
test   %eax,%eax
je     11a4 <main+0x44>
test   %r12d,%r12d
je     11a4 <main+0x44>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    -0x1(%rax),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <StringReverse@plt>
lea    0xe0d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Please enter a %d-digit number: \00"
@EOF = global i8 0
@.str.1 = [33 x i8] c"Input invalid. Please try again.\00"
@.str.2 = [21 x i8] c"The reversal is: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 0, i32* %1
%7 = bitcast [16 x i8]* %2 to i8*
store i32 2, i32* %3
store i32 0, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 2)
br label %9
9: ; preds = %54, %0
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %55
13: ; preds = %9
store i32 1, i32* %4
store i32 0, i32* %5
store i8 0, i8* %6
br label %14
14: ; preds = %41, %13
%15 = call signext i8 (...) @getchar()
store i8 %15, i8* %6
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8, i8* %6
%20 = sext i8 %19 to i32
%21 = load i8, i8* @EOF
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br label %24
24: ; preds = %18, %14
%25 = phi i1 [ false, %14 ], [ %23, %18 ]
br i1 %25, label %26, label %42
26: ; preds = %24
%27 = load i8, i8* %6
%28 = call i64 @isdigit(i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = load i32, i32* %5
%32 = icmp slt i32 %31, 2
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load i8, i8* %6
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 %36
store i8 %34, i8* %37
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %41
40: ; preds = %30, %26
store i32 0, i32* %4
br label %41
41: ; preds = %40, %33
br label %14
42: ; preds = %24
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 %44
store i8 0, i8* %45
%46 = load i32, i32* %5
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %42
store i32 0, i32* %4
br label %49
49: ; preds = %48, %42
%50 = load i32, i32* %4
%51 = icmp ne i32 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %54
54: ; preds = %52, %49
br label %9
55: ; preds = %9
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%57 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%58 = call i64 @strlen(i8* %57)
%59 = sub nsw i64 %58, 1
%60 = call i32 @StringReverse(i8* %56, i32 0, i64 %59)
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %61)
%63 = call signext i8 (...) @getchar()
%64 = load i32, i32* @EXIT_SUCCESS
ret i32 %64
}

LLVM IR (-O2):
@.str = [33 x i8] c"Please enter a %d-digit number: \00"
@EOF = global i8 0
@.str.1 = [33 x i8] c"Input invalid. Please try again.\00"
@.str.2 = [21 x i8] c"The reversal is: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 2)
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
br label %5
5: ; preds = %38, %0
%6 = tail call signext i8 (...) @getchar()
%7 = icmp ne i8 %6, 10
%8 = load i8, i8* @EOF
%9 = icmp ne i8 %6, %8
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %12, label %11
11: ; preds = %5
store i8 0, i8* %4
br label %38
12: ; preds = %5, %24
%13 = phi i8 [ %27, %24 ], [ %6, %5 ]
%14 = phi i32 [ %26, %24 ], [ 0, %5 ]
%15 = phi i32 [ %25, %24 ], [ 1, %5 ]
%16 = tail call i64 @isdigit(i8 signext %13)
%17 = icmp ne i64 %16, 0
%18 = icmp slt i32 %14, 2
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %20, label %24
20: ; preds = %12
%21 = sext i32 %14 to i64
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 %21
store i8 %13, i8* %22
%23 = add nsw i32 %14, 1
br label %24
24: ; preds = %12, %20
%25 = phi i32 [ %15, %20 ], [ 0, %12 ]
%26 = phi i32 [ %23, %20 ], [ %14, %12 ]
%27 = tail call signext i8 (...) @getchar()
%28 = icmp ne i8 %27, 10
%29 = load i8, i8* @EOF
%30 = icmp ne i8 %27, %29
%31 = select i1 %28, i1 %30, i1 false
br i1 %31, label %12, label %32
32: ; preds = %24
%33 = sext i32 %26 to i64
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 %33
store i8 0, i8* %34
%35 = icmp eq i32 %26, 0
%36 = icmp eq i32 %25, 0
%37 = select i1 %35, i1 true, i1 %36
br i1 %37, label %38, label %40
38: ; preds = %11, %32
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %5
40: ; preds = %32
%41 = call i64 @strlen(i8* %2)
%42 = add nsw i64 %41, -1
%43 = call i32 @StringReverse(i8* %2, i32 0, i64 %42)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%45 = call signext i8 (...) @getchar()
%46 = load i32, i32* @EXIT_SUCCESS
ret i32 %46
}