#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);
size_t strlen(char *);
bool isPalindrome(int x) {
  if (x < 0) {
    return false;
  }
  char buffer[64] = {0};
  sprintf(buffer, "%d", x);
  size_t bl = strlen(buffer);
  char *start = buffer;
  char *end = buffer + bl - 1;
  while (start < end) {
    if (*start != *end) {
      return false;
    }
    start++;
    end--;
  }
  return true;
}


x86 assembly (clang, -O0):
<isPalindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1151 <isPalindrome+0x21>
movl   $0x0,-0x4(%rbp)
jmp    11ed <isPalindrome+0xbd>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe91(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x50(%rbp),%rax
add    -0x58(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x68(%rbp)
mov    -0x60(%rbp),%rax
cmp    -0x68(%rbp),%rax
jae    11e6 <isPalindrome+0xb6>
mov    -0x60(%rbp),%rax
movsbl (%rax),%eax
mov    -0x68(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11c9 <isPalindrome+0x99>
movl   $0x0,-0x4(%rbp)
jmp    11ed <isPalindrome+0xbd>
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
mov    -0x68(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x68(%rbp)
jmp    1199 <isPalindrome+0x69>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isPalindrome>:
test   %edi,%edi
js     119a <isPalindrome+0x7a>
push   %rbx
sub    $0x40,%rsp
mov    %edi,%edx
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xeb8(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    (%rsp,%rax,1),%rcx
add    $0xffffffffffffffff,%rcx
mov    $0x1,%eax
cmp    %rcx,%rbx
jae    119f <isPalindrome+0x7f>
lea    0x1(%rsp),%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl -0x1(%rdx),%ebx
cmp    (%rcx),%bl
jne    119d <isPalindrome+0x7d>
add    $0xffffffffffffffff,%rcx
lea    0x1(%rdx),%rsi
cmp    %rcx,%rdx
mov    %rsi,%rdx
jb     1180 <isPalindrome+0x60>
jmp    119f <isPalindrome+0x7f>
xor    %eax,%eax
ret
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

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

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