#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  int LEN = 5;
  int input_num, digits_array[LEN];
  int i;
  int reverse_index;
  printf("Please enter a number (maximum 5 digits):\n");
  scanf("%d", &input_num);
  while (input_num > 0) {
    digits_array[i] = input_num % 10;
    i++;
    input_num = input_num / 10;
  }
  for (i = 0; i < LEN; i++) {
    reverse_index = (LEN - 1) - i;
    if (digits_array[i] != digits_array[reverse_index])
      break;
  }
  if (i == LEN)
    printf("The reverse of the digits is the same\n");
  else
    printf("The reverse of the digits is NOT the same\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11b5 <main+0x95>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    1179 <main+0x59>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1204 <main+0xe4>
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
movslq -0x24(%rbp),%rax
mov    (%rcx,%rax,4),%eax
movslq -0x28(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
je     11f1 <main+0xd1>
jmp    1204 <main+0xe4>
jmp    11f6 <main+0xd6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11bc <main+0x9c>
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1221 <main+0x101>
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
jmp    122d <main+0x10d>
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%r14
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
lea    0xec3(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    118f <main+0x6f>
lea    0x10(%rsp),%rcx
mov    $0xcccccccd,%edx
nopl   0x0(%rax)
mov    %eax,%ebx
mov    %eax,%eax
imul   %rdx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %ebx,%esi
sub    %edi,%esi
mov    %esi,(%rcx)
add    $0x4,%rcx
cmp    $0xa,%ebx
jae    1160 <main+0x40>
mov    %eax,0xc(%rsp)
mov    0x10(%rsp),%eax
cmp    0x20(%rsp),%eax
jne    11a2 <main+0x82>
mov    0x14(%rsp),%eax
cmp    0x1c(%rsp),%eax
jne    11a2 <main+0x82>
lea    0xeb7(%rip),%rdi
jmp    11a9 <main+0x89>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rsp
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Please enter a number (maximum 5 digits):\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"The reverse of the digits is the same\0A\00"
@.str.3 = [43 x i8] c"The reverse of the digits is NOT the same\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 5, i32* %2
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i32, i64 %9
store i64 %9, i64* %5
%12 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %14
14: ; preds = %17, %0
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32, i32* %3
%19 = srem i32 %18, 10
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %11, i64 %21
store i32 %19, i32* %22
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
%25 = load i32, i32* %3
%26 = sdiv i32 %25, 10
store i32 %26, i32* %3
br label %14
27: ; preds = %14
store i32 0, i32* %6
br label %28
28: ; preds = %48, %27
%29 = load i32, i32* %6
%30 = load i32, i32* %2
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %51
32: ; preds = %28
%33 = load i32, i32* %2
%34 = sub nsw i32 %33, 1
%35 = load i32, i32* %6
%36 = sub nsw i32 %34, %35
store i32 %36, i32* %7
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %11, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %11, i64 %42
%44 = load i32, i32* %43
%45 = icmp ne i32 %40, %44
br i1 %45, label %46, label %47
46: ; preds = %32
br label %51
47: ; preds = %32
br label %48
48: ; preds = %47
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %28
51: ; preds = %46, %28
%52 = load i32, i32* %6
%53 = load i32, i32* %2
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %59
57: ; preds = %51
%58 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %57, %55
store i32 0, i32* %1
%60 = load i8*, i8** %4
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [42 x i8] c"Please enter a number (maximum 5 digits):\00"
@str.4 = [42 x i8] c"The reverse of the digits is NOT the same\00"
@str.5 = [38 x i8] c"The reverse of the digits is the same\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i8* @llvm.stacksave()
%4 = alloca [5 x i32]
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %15, label %23
9: ; preds = %15
store i32 %21, i32* %1
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 4
%13 = load i32, i32* %12
%14 = icmp eq i32 %11, %13
br i1 %14, label %23, label %29
15: ; preds = %0, %15
%16 = phi i64 [ %20, %15 ], [ 0, %0 ]
%17 = phi i32 [ %21, %15 ], [ %7, %0 ]
%18 = urem i32 %17, 10
%19 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 %16
store i32 %18, i32* %19
%20 = add i64 %16, 1
%21 = udiv i32 %17, 10
%22 = icmp ult i32 %17, 10
br i1 %22, label %9, label %15
23: ; preds = %0, %9
%24 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 3
%27 = load i32, i32* %26
%28 = icmp eq i32 %25, %27
br i1 %28, label %30, label %29
29: ; preds = %9, %23
br label %30
30: ; preds = %23, %29
%31 = phi i8* [ getelementptr inbounds ([42 x i8], [42 x i8]* @str.4, i64 0, i64 0), %29 ], [ getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0), %23 ]
%32 = call i32 @puts(i8* dereferenceable(1) %31)
ret i32 0
}