#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 base2_len(int const);
int chk_base2_palin(const int n) {
  int right = 0;
  int left = base2_len(n) - 1;
  while (left > right) {
    if (((n >> left) & 1) != ((n >> right) & 1))
      return 0;
    --left;
    ++right;
  }
  return 1;
}


x86 assembly (clang, -O0):
<chk_base2_palin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <base2_len@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    117f <chk_base2_palin+0x6f>
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
sar    %cl,%edx
mov    %edx,%ecx
and    $0x1,%ecx
cmp    %ecx,%eax
je     1168 <chk_base2_palin+0x58>
movl   $0x0,-0x4(%rbp)
jmp    1186 <chk_base2_palin+0x76>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1130 <chk_base2_palin+0x20>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chk_base2_palin>:
push   %rbx
mov    %edi,%ebx
call   1030 <base2_len@plt>
mov    %eax,%edx
mov    $0x1,%eax
cmp    $0x2,%edx
jl     115a <chk_base2_palin+0x4a>
add    $0xffffffff,%edx
mov    $0x1,%eax
nopl   0x0(%rax)
mov    %ebx,%esi
mov    %edx,%ecx
shr    %cl,%esi
lea    -0x1(%rax),%ecx
mov    %ebx,%edi
shr    %cl,%edi
xor    %esi,%edi
test   $0x1,%dil
jne    1158 <chk_base2_palin+0x48>
add    $0xffffffff,%edx
lea    0x1(%rax),%ecx
cmp    %eax,%edx
mov    %ecx,%eax
jg     1130 <chk_base2_palin+0x20>
mov    $0x1,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

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