#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 check_palindrome(char *);
unsigned is_bin_palindrome(unsigned num) {
  unsigned i = 0;
  char str[30] = {0};
  if (num == 0)
    str[i++] = '0';
  while (num) {
    if (num & 1)
      str[i++] = '1';
    else
      str[i++] = '0';
    num >>= 1;
  }
  str[i] = '\0';
  return check_palindrome(str);
}


x86 assembly (clang, -O0):
<is_bin_palindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1030 <memset@plt>
cmpl   $0x0,-0x4(%rbp)
jne    115e <is_bin_palindrome+0x3e>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
mov    %eax,%eax
movb   $0x30,-0x30(%rbp,%rax,1)
jmp    1163 <is_bin_palindrome+0x43>
cmpl   $0x0,-0x4(%rbp)
je     11b3 <is_bin_palindrome+0x93>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1193 <is_bin_palindrome+0x73>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
mov    %eax,%eax
movb   $0x31,-0x30(%rbp,%rax,1)
jmp    11a5 <is_bin_palindrome+0x85>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
mov    %eax,%eax
movb   $0x30,-0x30(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1163 <is_bin_palindrome+0x43>
mov    -0x8(%rbp),%eax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
call   1040 <check_palindrome@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_bin_palindrome>:
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0xe(%rsp)
movaps %xmm0,(%rsp)
test   %edi,%edi
je     114a <is_bin_palindrome+0x3a>
xor    %eax,%eax
mov    %edi,%ecx
nopl   0x0(%rax,%rax,1)
mov    %edi,%edx
and    $0x1,%dl
or     $0x30,%dl
mov    %dl,(%rsp,%rax,1)
add    $0x1,%rax
shr    %ecx
cmp    $0x1,%edi
mov    %ecx,%edi
ja     1130 <is_bin_palindrome+0x20>
jmp    1153 <is_bin_palindrome+0x43>
movb   $0x30,(%rsp)
mov    $0x1,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1030 <check_palindrome@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
define i32 @is_bin_palindrome(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [30 x i8]
store i32 %0, i32* %2
store i32 0, i32* %3
%5 = bitcast [30 x i8]* %4 to i8*
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* %3
%10 = add i32 %9, 1
store i32 %10, i32* %3
%11 = zext i32 %9 to i64
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %11
store i8 48, i8* %12
br label %13
13: ; preds = %8, %1
br label %14
14: ; preds = %31, %13
%15 = load i32, i32* %2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %34
17: ; preds = %14
%18 = load i32, i32* %2
%19 = and i32 %18, 1
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32, i32* %3
%23 = add i32 %22, 1
store i32 %23, i32* %3
%24 = zext i32 %22 to i64
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %24
store i8 49, i8* %25
br label %31
26: ; preds = %17
%27 = load i32, i32* %3
%28 = add i32 %27, 1
store i32 %28, i32* %3
%29 = zext i32 %27 to i64
%30 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %29
store i8 48, i8* %30
br label %31
31: ; preds = %26, %21
%32 = load i32, i32* %2
%33 = lshr i32 %32, 1
store i32 %33, i32* %2
br label %14
34: ; preds = %14
%35 = load i32, i32* %3
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %36
store i8 0, i8* %37
%38 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%39 = call i32 @check_palindrome(i8* %38)
ret i32 %39
}

LLVM IR (-O2):
define i32 @is_bin_palindrome(i32 %0) {
%2 = alloca [30 x i8]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%4 = icmp eq i32 %0, 0
br i1 %4, label %5, label %6
5: ; preds = %1
store i8 48, i8* %3
br label %18
6: ; preds = %1, %6
%7 = phi i64 [ %13, %6 ], [ 0, %1 ]
%8 = phi i32 [ %14, %6 ], [ %0, %1 ]
%9 = and i32 %8, 1
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i8 48, i8 49
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %7
store i8 %11, i8* %12
%13 = add nuw nsw i64 %7, 1
%14 = lshr i32 %8, 1
%15 = icmp ult i32 %8, 2
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = and i64 %13, 4294967295
br label %18
18: ; preds = %5, %16
%19 = phi i64 [ %17, %16 ], [ 1, %5 ]
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i32 @check_palindrome(i8* %3)
ret i32 %21
}