#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 num(int);
int pal(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, temp = 1, i = 0, help[100];
  scanf("%d", &n);
  while (temp != 0) {
    temp = pal(n);
    n++;
  }
  n--;
  while (n != 0) {
    help[i] = n % 16;
    n = n / 16;
    i++;
  }
  i--;
  while (i != -1) {
    printf("%c", num(help[i]));
    i--;
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xe99(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
je     1193 <main+0x53>
mov    -0x8(%rbp),%edi
call   1050 <pal@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1170 <main+0x30>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11d8 <main+0x98>
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq -0x10(%rbp),%rax
mov    %edx,-0x1a0(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119c <main+0x5c>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
je     1219 <main+0xd9>
movslq -0x10(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edi
call   1030 <num@plt>
mov    %eax,%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11e1 <main+0xa1>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xead(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1050 <pal@plt>
mov    0xc(%rsp),%ecx
lea    0x1(%rcx),%edi
mov    %edi,0xc(%rsp)
test   %eax,%eax
jne    1170 <main+0x30>
mov    %ecx,0xc(%rsp)
test   %ecx,%ecx
je     11ef <main+0xaf>
xor    %r15d,%r15d
nop
lea    0xf(%rcx),%eax
test   %ecx,%ecx
mov    %ecx,%edx
cmovs  %eax,%edx
mov    %edx,%esi
and    $0xfffffff0,%esi
sub    %esi,%ecx
mov    %ecx,0x10(%rsp,%r15,4)
mov    %edx,%ecx
sar    $0x4,%ecx
add    $0x1,%r15
cmp    $0x1f,%eax
jae    1190 <main+0x50>
mov    %ecx,0xc(%rsp)
test   %r15d,%r15d
je     11ef <main+0xaf>
movslq %r15d,%rax
lea    (%rsp,%rax,4),%r14
add    $0xc,%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edi
call   1030 <num@plt>
mov    %eax,%edi
call   1040 <putchar@plt>
lea    -0x1(%rbx),%rax
add    %r15d,%ebx
cmp    $0x1,%ebx
mov    %rax,%rbx
jne    11d0 <main+0x90>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
add    $0x1a0,%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"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i32]
store i32 0, i32* %1
store i32 1, i32* %3
store i32 0, i32* %4
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %7
7: ; preds = %10, %0
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i32, i32* %2
%12 = call i32 @pal(i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %7
15: ; preds = %7
%16 = load i32, i32* %2
%17 = add nsw i32 %16, -1
store i32 %17, i32* %2
br label %18
18: ; preds = %21, %15
%19 = load i32, i32* %2
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i32, i32* %2
%23 = srem i32 %22, 16
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %25
store i32 %23, i32* %26
%27 = load i32, i32* %2
%28 = sdiv i32 %27, 16
store i32 %28, i32* %2
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %18
31: ; preds = %18
%32 = load i32, i32* %4
%33 = add nsw i32 %32, -1
store i32 %33, i32* %4
br label %34
34: ; preds = %37, %31
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, -1
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = call i32 @num(i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %4
%45 = add nsw i32 %44, -1
store i32 %45, i32* %4
br label %34
46: ; preds = %34
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [100 x i32]* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
br label %7
7: ; preds = %0, %7
%8 = phi i32 [ %6, %0 ], [ %11, %7 ]
%9 = call i32 @pal(i32 %8)
%10 = load i32, i32* %1
%11 = add nsw i32 %10, 1
store i32 %11, i32* %1
%12 = icmp eq i32 %9, 0
br i1 %12, label %13, label %7
13: ; preds = %7
store i32 %10, i32* %1
%14 = icmp eq i32 %10, 0
br i1 %14, label %39, label %21
15: ; preds = %21
%16 = trunc i64 %27 to i32
store i32 %26, i32* %1
%17 = icmp eq i32 %16, 0
br i1 %17, label %39, label %18
18: ; preds = %15
%19 = shl i64 %27, 32
%20 = ashr exact i64 %19, 32
br label %30
21: ; preds = %13, %21
%22 = phi i64 [ %27, %21 ], [ 0, %13 ]
%23 = phi i32 [ %26, %21 ], [ %10, %13 ]
%24 = srem i32 %23, 16
%25 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %22
store i32 %24, i32* %25
%26 = sdiv i32 %23, 16
%27 = add nuw i64 %22, 1
%28 = add i32 %23, 15
%29 = icmp ult i32 %28, 31
br i1 %29, label %15, label %21
30: ; preds = %18, %30
%31 = phi i64 [ %20, %18 ], [ %32, %30 ]
%32 = add nsw i64 %31, -1
%33 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @num(i32 %34)
%36 = call i32 @putchar(i32 %35)
%37 = trunc i64 %32 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %30
39: ; preds = %30, %13, %15
%40 = call i32 @putchar(i32 10)
ret i32 0
}