#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*/ sprintf(char *, char *, int);
int strlen(char *);
int is_palindrome(int n) {
  char pStr[10];
  sprintf(pStr, "%d", n);
  int nLength = strlen(pStr);
  int i;
  for (i = 0; i <= nLength / 2; i += 1)
    if (pStr[i] != pStr[nLength - i - 1])
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_palindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x12(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xec7(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x12(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jg     11b0 <is_palindrome+0x90>
movslq -0x1c(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%eax
mov    -0x18(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl -0x12(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
je     119d <is_palindrome+0x7d>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <is_palindrome+0x97>
jmp    11a2 <is_palindrome+0x82>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1151 <is_palindrome+0x31>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_palindrome>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%edx
lea    0xed2(%rip),%rsi
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
jl     117e <is_palindrome+0x5e>
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
add    $0x1,%edx
add    $0xffffffff,%ecx
xor    %esi,%esi
movzbl 0x6(%rsp,%rsi,1),%ebx
movslq %ecx,%rdi
cmp    0x6(%rsp,%rdi,1),%bl
jne    117c <is_palindrome+0x5c>
add    $0x1,%rsi
add    $0xffffffff,%ecx
cmp    %rsi,%rdx
jne    1160 <is_palindrome+0x40>
jmp    117e <is_palindrome+0x5e>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @is_palindrome(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %5
store i32 0, i32* %6
br label %12
12: ; preds = %34, %1
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = sdiv i32 %14, 2
%16 = icmp sle i32 %13, %15
br i1 %16, label %17, label %37
17: ; preds = %12
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = sub nsw i32 %23, %24
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %22, %30
br i1 %31, label %32, label %33
32: ; preds = %17
store i32 0, i32* %2
br label %38
33: ; preds = %17
br label %34
34: ; preds = %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %12
37: ; preds = %12
store i32 1, i32* %2
br label %38
38: ; preds = %37, %32
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @is_palindrome(i32 %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = call i32 @strlen(i8* %3)
%6 = icmp slt i32 %5, -1
br i1 %6, label %25, label %7
7: ; preds = %1
%8 = sdiv i32 %5, 2
%9 = add nuw nsw i32 %8, 1
%10 = zext i32 %9 to i64
br label %14
11: ; preds = %14
%12 = add nuw nsw i64 %15, 1
%13 = icmp eq i64 %12, %10
br i1 %13, label %25, label %14
14: ; preds = %7, %11
%15 = phi i64 [ 0, %7 ], [ %12, %11 ]
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = trunc i64 %15 to i32
%19 = xor i32 %18, -1
%20 = add i32 %5, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %17, %23
br i1 %24, label %11, label %25
25: ; preds = %14, %11, %1
%26 = phi i32 [ 1, %1 ], [ 1, %11 ], [ 0, %14 ]
ret i32 %26
}