#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*/ free(char *);
int hextrlen(int);
int isPalindrome(int /*<<< orphan*/, char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int num;
  char *hex;
  scanf("%d", &num);
  do {
    hex = malloc(sizeof(int) * hextrlen(num));
  } while (isPalindrome(num++, hex) == -1);
  for (int i = 0; i < hextrlen(num - 1); i++) {
    printf("%c", hex[i]);
  }
  free(hex);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%edi
call   1040 <hextrlen@plt>
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rsi
call   1070 <isPalindrome@plt>
cmp    $0xffffffff,%eax
je     117f <main+0x1f>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1040 <hextrlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    1200 <main+0xa0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xe1a(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bc <main+0x5c>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
call   1040 <hextrlen@plt>
lea    0x0(,%rax,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    0xc(%rsp),%edi
lea    0x1(%rdi),%eax
mov    %eax,0xc(%rsp)
mov    %r15,%rsi
call   1070 <isPalindrome@plt>
cmp    $0xffffffff,%eax
je     1180 <main+0x20>
mov    0xc(%rsp),%edi
add    $0xffffffff,%edi
call   1040 <hextrlen@plt>
test   %eax,%eax
jle    11f4 <main+0x94>
xor    %ebx,%ebx
lea    0xe3a(%rip),%r14
nopl   0x0(%rax)
movsbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
add    $0x1,%rbx
mov    0xc(%rsp),%edi
add    $0xffffffff,%edi
call   1040 <hextrlen@plt>
cltq
cmp    %rax,%rbx
jl     11d0 <main+0x70>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %6
6: ; preds = %13, %0
%7 = load i32, i32* %2
%8 = call i32 @hextrlen(i32 %7)
%9 = sext i32 %8 to i64
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %3
br label %13
13: ; preds = %6
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
%16 = load i8*, i8** %3
%17 = call i32 @isPalindrome(i32 %14, i8* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %6, label %19
19: ; preds = %13
store i32 0, i32* %4
br label %20
20: ; preds = %33, %19
%21 = load i32, i32* %4
%22 = load i32, i32* %2
%23 = sub nsw i32 %22, 1
%24 = call i32 @hextrlen(i32 %23)
%25 = icmp slt i32 %21, %24
br i1 %25, label %26, label %36
26: ; preds = %20
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %31)
br label %33
33: ; preds = %26
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %20
36: ; preds = %20
%37 = load i8*, i8** %3
%38 = call i32 @free(i8* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
br label %4
4: ; preds = %4, %0
%5 = load i32, i32* %1
%6 = call i32 @hextrlen(i32 %5)
%7 = shl i32 %6, 2
%8 = call i8* @malloc(i32 %7)
%9 = load i32, i32* %1
%10 = add nsw i32 %9, 1
store i32 %10, i32* %1
%11 = call i32 @isPalindrome(i32 %9, i8* %8)
%12 = icmp eq i32 %11, -1
br i1 %12, label %4, label %13
13: ; preds = %4
%14 = load i32, i32* %1
%15 = add nsw i32 %14, -1
%16 = call i32 @hextrlen(i32 %15)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %20, %13
%19 = call i32 @free(i8* %8)
ret i32 0
20: ; preds = %13, %20
%21 = phi i64 [ %25, %20 ], [ 0, %13 ]
%22 = getelementptr inbounds i8, i8* %8, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %23)
%25 = add nuw nsw i64 %21, 1
%26 = load i32, i32* %1
%27 = add nsw i32 %26, -1
%28 = call i32 @hextrlen(i32 %27)
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %25, %29
br i1 %30, label %20, label %18
}