#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 */
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
size_t strlen(char *);
bool is_palindrome(uint16_t num) {
  char num_as_str[30] = {'\0'};
  sprintf(num_as_str, "%u", num);
  size_t const end_of_str = strlen(num_as_str);
  for (size_t i = 0; i < end_of_str; ++i) {
    if (num_as_str[i] != num_as_str[end_of_str - i])
      return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<is_palindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1040 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xea7(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    11c1 <is_palindrome+0x91>
mov    -0x40(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
mov    -0x38(%rbp),%rcx
sub    -0x40(%rbp),%rcx
movsbl -0x30(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
je     11ab <is_palindrome+0x7b>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <is_palindrome+0x98>
jmp    11b0 <is_palindrome+0x80>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1173 <is_palindrome+0x43>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_palindrome>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%edx
xorps  %xmm0,%xmm0
movups %xmm0,0xe(%rsp)
movaps %xmm0,(%rsp)
lea    0xec6(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1193 <is_palindrome+0x73>
mov    (%rsp),%dl
xor    %ecx,%ecx
cmp    (%rsp,%rax,1),%dl
jne    1198 <is_palindrome+0x78>
lea    -0x1(%rax),%rcx
mov    $0x1,%edi
mov    %rcx,%rsi
nopl   0x0(%rax,%rax,1)
mov    %rdi,%rdx
sub    $0x1,%rsi
jb     1189 <is_palindrome+0x69>
movzbl (%rsp,%rdx,1),%ebx
lea    0x1(%rdx),%rdi
cmp    (%rsp,%rcx,1),%bl
mov    %rsi,%rcx
je     1170 <is_palindrome+0x50>
xor    %ecx,%ecx
cmp    %rdx,%rax
setbe  %cl
jmp    1198 <is_palindrome+0x78>
mov    $0x1,%ecx
mov    %ecx,%eax
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
define i32 @is_palindrome(i32 %0) {
%2 = alloca [30 x i8]
%3 = getelementptr inbounds [30 x i8], [30 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 i64 @strlen(i8* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %27, label %7
7: ; preds = %1
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%9 = load i8, i8* %8
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %5
%11 = load i8, i8* %10
%12 = icmp eq i8 %9, %11
br i1 %12, label %13, label %27
13: ; preds = %7, %16
%14 = phi i64 [ %23, %16 ], [ 1, %7 ]
%15 = icmp eq i64 %5, %14
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %14
%18 = load i8, i8* %17
%19 = sub i64 %5, %14
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %18, %21
%23 = add nuw i64 %14, 1
br i1 %22, label %13, label %24
24: ; preds = %13, %16
%25 = icmp ule i64 %5, %14
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %24, %7, %1
%28 = phi i32 [ 1, %1 ], [ 0, %7 ], [ %26, %24 ]
ret i32 %28
}