#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__ is_hex_palindrome(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ to_upper(char *);
int main() {
  char hex[8];
  int number;
  scanf("%d", &number);
  sprintf(hex, "%x", number);
  if (is_hex_palindrome(hex)) {
    to_upper(hex);
    printf("%s", hex);
  } else {
    do {
      number++;
      sprintf(hex, "%x", number);
    } while (!is_hex_palindrome(hex));
    to_upper(hex);
    printf("%s", hex);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
lea    -0xc(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe86(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0xc(%rbp),%rdi
call   1030 <is_hex_palindrome@plt>
cmp    $0x0,%rax
je     11b3 <main+0x63>
lea    -0xc(%rbp),%rdi
call   1070 <to_upper@plt>
lea    -0xc(%rbp),%rsi
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
jmp    1207 <main+0xb7>
jmp    11b8 <main+0x68>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
lea    -0xc(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe34(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0xc(%rbp),%rdi
call   1030 <is_hex_palindrome@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b8 <main+0x68>
lea    -0xc(%rbp),%rdi
call   1070 <to_upper@plt>
lea    -0xc(%rbp),%rsi
lea    0xe04(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xea2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%edx
lea    0xe90(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <is_hex_palindrome@plt>
test   %rax,%rax
jne    11c3 <main+0x73>
lea    0xe6f(%rip),%r14
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    0xc(%rsp),%edx
add    $0x1,%edx
mov    %edx,0xc(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <is_hex_palindrome@plt>
test   %rax,%rax
je     11a0 <main+0x50>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <to_upper@plt>
lea    0xe2f(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* %3
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%9 = call i64 @is_hex_palindrome(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%13 = call i32 @to_upper(i8* %12)
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %33
16: ; preds = %0
br label %17
17: ; preds = %23, %16
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %17
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%25 = call i64 @is_hex_palindrome(i8* %24)
%26 = icmp ne i64 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %17, label %28
28: ; preds = %23
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%30 = call i32 @to_upper(i8* %29)
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28, %11
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [8 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [8 x i8], [8 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 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = call i64 @is_hex_palindrome(i8* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %0, %10
%11 = load i32, i32* %2
%12 = add nsw i32 %11, 1
store i32 %12, i32* %2
%13 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = call i64 @is_hex_palindrome(i8* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %10, label %16
16: ; preds = %10, %0
%17 = call i32 @to_upper(i8* %3)
%18 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
ret i32 0
}