#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*/ snprintf(char *, int, char *, int);
int strlen(char *);
int palindrome(int x) {
  char buffer[33];
  int length;
  int k;
  snprintf(buffer, 33, "%i", x);
  length = strlen(buffer);
  for (k = 0; buffer[k]; k++) {
    if (buffer[k] != buffer[length - k - 1]) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<palindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x21,%esi
lea    0xec2(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movslq -0x38(%rbp),%rax
cmpb   $0x0,-0x30(%rbp,%rax,1)
je     11a6 <palindrome+0x86>
movslq -0x38(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
mov    -0x34(%rbp),%ecx
sub    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl -0x30(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
je     1193 <palindrome+0x73>
movl   $0x0,-0x4(%rbp)
jmp    11ad <palindrome+0x8d>
jmp    1198 <palindrome+0x78>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1156 <palindrome+0x36>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<palindrome>:
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ecx
lea    0xed2(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x21,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    (%rsp),%dl
mov    $0x1,%eax
test   %dl,%dl
je     117d <palindrome+0x5d>
add    $0xffffffff,%ecx
mov    $0x1,%esi
nopl   0x0(%rax)
movslq %ecx,%rdi
cmp    (%rsp,%rdi,1),%dl
jne    117b <palindrome+0x5b>
mov    %esi,%edx
movzbl (%rsp,%rdx,1),%edx
add    $0xffffffff,%ecx
add    $0x1,%rsi
test   %dl,%dl
jne    1160 <palindrome+0x40>
jmp    117d <palindrome+0x5d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

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

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