#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 */
scalar_t__ digit(int, int);
int nr_of_digits(int);
bool is_palindrome(int n) {
  int nr = nr_of_digits(n);
  int i;
  for (i = 0; i < nr / 2; i++) {
    if (digit(i, n) != digit(nr - 1 - i, n)) {
      return false;
    }
  }
  return true;
}


x86 assembly (clang, -O0):
<is_palindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <nr_of_digits@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11aa <is_palindrome+0x8a>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <digit@plt>
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
sub    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <digit@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     1197 <is_palindrome+0x77>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <is_palindrome+0x91>
jmp    119c <is_palindrome+0x7c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113d <is_palindrome+0x1d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_palindrome>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
call   1040 <nr_of_digits@plt>
mov    $0x1,%r14d
cmp    $0x2,%eax
jl     118c <is_palindrome+0x6c>
mov    %eax,%ebx
mov    %eax,%r13d
shr    $0x1f,%r13d
add    %eax,%r13d
sar    %r13d
add    $0xffffffff,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r15d,%esi
call   1030 <digit@plt>
mov    %rax,%r12
mov    %ebx,%edi
mov    %r15d,%esi
call   1030 <digit@plt>
cmp    %rax,%r12
jne    1189 <is_palindrome+0x69>
add    $0x1,%ebp
add    $0xffffffff,%ebx
cmp    %ebp,%r13d
jne    1160 <is_palindrome+0x40>
jmp    118c <is_palindrome+0x6c>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @is_palindrome(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = call i32 @nr_of_digits(i32 %6)
store i32 %7, i32* %4
store i32 0, i32* %5
br label %8
8: ; preds = %26, %1
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = sdiv i32 %10, 2
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %29
13: ; preds = %8
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = call i64 @digit(i32 %14, i32 %15)
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
%19 = load i32, i32* %5
%20 = sub nsw i32 %18, %19
%21 = load i32, i32* %3
%22 = call i64 @digit(i32 %20, i32 %21)
%23 = icmp ne i64 %16, %22
br i1 %23, label %24, label %25
24: ; preds = %13
store i32 0, i32* %2
br label %30
25: ; preds = %13
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %8
29: ; preds = %8
store i32 1, i32* %2
br label %30
30: ; preds = %29, %24
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @is_palindrome(i32 %0) {
%2 = tail call i32 @nr_of_digits(i32 %0)
%3 = sdiv i32 %2, 2
%4 = icmp sgt i32 %2, 1
br i1 %4, label %7, label %15
5: ; preds = %7
%6 = icmp eq i32 %14, %3
br i1 %6, label %15, label %7
7: ; preds = %1, %5
%8 = phi i32 [ %14, %5 ], [ 0, %1 ]
%9 = tail call i64 @digit(i32 %8, i32 %0)
%10 = xor i32 %8, -1
%11 = add i32 %2, %10
%12 = tail call i64 @digit(i32 %11, i32 %0)
%13 = icmp eq i64 %9, %12
%14 = add nuw nsw i32 %8, 1
br i1 %13, label %5, label %15
15: ; preds = %7, %5, %1
%16 = phi i32 [ 1, %1 ], [ 1, %5 ], [ 0, %7 ]
ret i32 %16
}