#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 convert_to_hex(char *, int);
int /*<<< orphan*/ find_palindrome(char *, int);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  char hex[200];
  int n;
  scanf("%d", &n);
  int j = convert_to_hex(hex, n);
  while (!find_palindrome(hex, j)) {
    n += 1;
    j = convert_to_hex(hex, n);
  }
  while (j > 0) {
    j--;
    printf("%c", hex[j]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0xd4(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%esi
call   1030 <convert_to_hex@plt>
mov    %eax,-0xd8(%rbp)
lea    -0xd0(%rbp),%rdi
mov    -0xd8(%rbp),%esi
call   1050 <find_palindrome@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a4 <main+0x64>
jmp    11d0 <main+0x90>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%esi
call   1030 <convert_to_hex@plt>
mov    %eax,-0xd8(%rbp)
jmp    117d <main+0x3d>
jmp    11d5 <main+0x95>
cmpl   $0x0,-0xd8(%rbp)
jle    1211 <main+0xd1>
mov    -0xd8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xd8(%rbp)
movslq -0xd8(%rbp),%rax
lea    0xe04(%rip),%rdi
movsbl -0xd0(%rbp,%rax,1),%esi
ff
call   1040 <printf@plt>
jmp    11d5 <main+0x95>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xd8,%rsp
lea    0xeaf(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1030 <convert_to_hex@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <find_palindrome@plt>
test   %eax,%eax
jne    11b3 <main+0x73>
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
add    $0x1,%esi
mov    %esi,0xc(%rsp)
mov    %r14,%rdi
call   1030 <convert_to_hex@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <find_palindrome@plt>
test   %eax,%eax
je     1190 <main+0x50>
test   %ebx,%ebx
jle    11ea <main+0xaa>
mov    %ebx,%ebx
add    $0x1,%rbx
lea    0xe3f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    -0x2(%rbx),%eax
movsbl 0x10(%rsp,%rax,1),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11d0 <main+0x90>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r14
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 [200 x i8]
%3 = alloca i32
%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* %3)
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* %3
%8 = call i32 @convert_to_hex(i8* %6, i32 %7)
store i32 %8, i32* %4
br label %9
9: ; preds = %15, %0
%10 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%11 = load i32, i32* %4
%12 = call i32 @find_palindrome(i8* %10, i32 %11)
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
%18 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%19 = load i32, i32* %3
%20 = call i32 @convert_to_hex(i8* %18, i32 %19)
store i32 %20, i32* %4
br label %9
21: ; preds = %9
br label %22
22: ; preds = %25, %21
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = load i32, i32* %4
%27 = add nsw i32 %26, -1
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, 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 %22
33: ; preds = %22
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 [200 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = call i32 @convert_to_hex(i8* %3, i32 %6)
%8 = call i32 @find_palindrome(i8* %3, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %15, %0
%11 = phi i32 [ %7, %0 ], [ %18, %15 ]
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = zext i32 %11 to i64
br label %21
15: ; preds = %0, %15
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
%18 = call i32 @convert_to_hex(i8* %3, i32 %17)
%19 = call i32 @find_palindrome(i8* %3, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %15, label %10
21: ; preds = %13, %21
%22 = phi i64 [ %14, %13 ], [ %23, %21 ]
%23 = add nsw i64 %22, -1
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %26)
%28 = icmp ugt i64 %22, 1
br i1 %28, label %21, label %29
29: ; preds = %21, %10
ret i32 0
}