#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 */
scalar_t__ log10(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  int num, rev = 0, n;
  printf("Enter 4 digit number\n");
  scanf("%d", &num);
  int l = (int)log10(num) + 1;
  if (l == 4) {
    n = num;
    while (num != 0) {
      rev = rev * 10 + num % 10;
      num /= 10;
    }
    if (n == rev)
      printf("%d is a palindrome \n", n);
    else
      printf("%d is not a palindrome \n", n);
  } else
    printf("Not 4 digit \n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%edi
call   1050 <log10@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jne    11f1 <main+0xc1>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11b9 <main+0x89>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%eax
add    %edx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1182 <main+0x52>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11db <main+0xab>
mov    -0x10(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ec <main+0xbc>
mov    -0x10(%rbp),%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ff <main+0xcf>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
lea    0xeac(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
call   1060 <log10@plt>
cmp    $0x3,%eax
jne    11c2 <main+0x82>
mov    0x4(%rsp),%esi
test   %esi,%esi
je     11b9 <main+0x79>
xor    %edx,%edx
mov    %esi,%eax
nopl   0x0(%rax,%rax,1)
lea    (%rdx,%rdx,4),%r8d
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rax
add    %edi,%eax
lea    (%rax,%rax,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %ecx,%edx
sub    %edi,%edx
lea    (%rdx,%r8,2),%edx
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     1180 <main+0x40>
mov    %eax,0x4(%rsp)
cmp    %edx,%esi
jne    11d0 <main+0x90>
lea    0xe43(%rip),%rdi
jmp    11d7 <main+0x97>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
jmp    11de <main+0x9e>
lea    0xe41(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter 4 digit number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"%d is a palindrome \0A\00"
@.str.3 = [25 x i8] c"%d is not a palindrome \0A\00"
@.str.4 = [14 x i8] c"Not 4 digit \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = call i64 @log10(i32 %8)
%10 = trunc i64 %9 to i32
%11 = add nsw i32 %10, 1
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 4
br i1 %13, label %14, label %38
14: ; preds = %0
%15 = load i32, i32* %2
store i32 %15, i32* %4
br label %16
16: ; preds = %19, %14
%17 = load i32, i32* %2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i32, i32* %3
%21 = mul nsw i32 %20, 10
%22 = load i32, i32* %2
%23 = srem i32 %22, 10
%24 = add nsw i32 %21, %23
store i32 %24, i32* %3
%25 = load i32, i32* %2
%26 = sdiv i32 %25, 10
store i32 %26, i32* %2
br label %16
27: ; preds = %16
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %37
34: ; preds = %27
%35 = load i32, i32* %4
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %34, %31
br label %40
38: ; preds = %0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %37
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"%d is a palindrome \0A\00"
@.str.3 = [25 x i8] c"%d is not a palindrome \0A\00"
@str = [21 x i8] c"Enter 4 digit number\00"
@str.5 = [13 x i8] c"Not 4 digit \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i64 @log10(i32 %5)
%7 = trunc i64 %6 to i32
%8 = icmp eq i32 %7, 3
br i1 %8, label %9, label %27
9: ; preds = %0
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %9, %12
%13 = phi i32 [ %17, %12 ], [ 0, %9 ]
%14 = phi i32 [ %18, %12 ], [ %10, %9 ]
%15 = mul nsw i32 %13, 10
%16 = srem i32 %14, 10
%17 = add nsw i32 %15, %16
%18 = sdiv i32 %14, 10
%19 = add i32 %14, 9
%20 = icmp ult i32 %19, 19
br i1 %20, label %21, label %12
21: ; preds = %12
store i32 %18, i32* %1
%22 = icmp eq i32 %10, %17
br i1 %22, label %23, label %25
23: ; preds = %9, %21
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %29
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %10)
br label %29
27: ; preds = %0
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.5, i64 0, i64 0))
br label %29
29: ; preds = %23, %25, %27
ret i32 0
}