#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 *);
int palindrome(int num) {
  char str[100];
  sprintf(str, "%d", num);
  size_t totlength = strlen(str);
  int halflength = totlength / 2;
  for (int i = 0; i <= halflength; i++) {
    if (str[totlength - i - 1] == str[i]) {
      ;
    } else {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<palindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xec4(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
shr    $0x1,%rax
mov    %eax,-0x7c(%rbp)
movl   $0x0,-0x80(%rbp)
mov    -0x80(%rbp),%eax
cmp    -0x7c(%rbp),%eax
jg     11b5 <palindrome+0x95>
mov    -0x78(%rbp),%rax
movslq -0x80(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
movsbl -0x70(%rbp,%rax,1),%eax
movslq -0x80(%rbp),%rcx
movsbl -0x70(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jne    1196 <palindrome+0x76>
jmp    11a2 <palindrome+0x82>
movl   $0x0,-0x4(%rbp)
jmp    11bc <palindrome+0x9c>
jmp    11a7 <palindrome+0x87>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    1160 <palindrome+0x40>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<palindrome>:
push   %rbx
sub    $0x70,%rsp
mov    %edi,%edx
lea    0xed2(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x1,%ecx
bt     $0x20,%rax
jb     1191 <palindrome+0x71>
mov    -0x1(%rax,%rbx,1),%dl
xor    %ecx,%ecx
cmp    (%rsp),%dl
jne    1191 <palindrome+0x71>
lea    (%rax,%rbx,1),%rcx
add    $0xfffffffffffffffe,%rcx
shr    %rax
cltq
lea    0x1(%rax),%edx
add    $0xffffffffffffffff,%rdx
xor    %edi,%edi
xchg   %ax,%ax
mov    %rdi,%rsi
cmp    %rdi,%rdx
je     1189 <palindrome+0x69>
movzbl (%rcx),%ebx
add    $0xffffffffffffffff,%rcx
lea    0x1(%rsi),%rdi
cmp    0x1(%rsp,%rsi,1),%bl
je     1170 <palindrome+0x50>
xor    %ecx,%ecx
cmp    %rax,%rsi
setge  %cl
mov    %ecx,%eax
add    $0x70,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @palindrome(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 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 = lshr i64 %5, 1
%7 = and i64 %5, 4294967296
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %35
9: ; preds = %1
%10 = shl i64 %6, 32
%11 = ashr exact i64 %10, 32
%12 = add nuw i64 %6, 1
%13 = and i64 %12, 4294967295
%14 = add i64 %5, -1
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%18 = load i8, i8* %17
%19 = icmp eq i8 %16, %18
br i1 %19, label %20, label %35
20: ; preds = %9, %24
%21 = phi i64 [ %22, %24 ], [ 0, %9 ]
%22 = add nuw nsw i64 %21, 1
%23 = icmp eq i64 %22, %13
br i1 %23, label %32, label %24
24: ; preds = %20
%25 = sub nuw i64 -2, %21
%26 = add i64 %5, %25
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %22
%30 = load i8, i8* %29
%31 = icmp eq i8 %28, %30
br i1 %31, label %20, label %32
32: ; preds = %20, %24
%33 = icmp sge i64 %21, %11
%34 = zext i1 %33 to i32
br label %35
35: ; preds = %32, %9, %1
%36 = phi i32 [ 1, %1 ], [ 0, %9 ], [ %34, %32 ]
ret i32 %36
}