#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 palindrome(long long);
int prime(long long);
int /*<<< orphan*/ printf(char *, long long);
int scanf(char *, long long *);
int main() {
  long long n;
  while (scanf("%lld", &n) == 1) {
    if (prime(n) == 1 && palindrome(n) == 1) {
      printf("%lld\n", n * 2);
      break;
    }
    printf("%lld\n", n * 2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11be <main+0x7e>
mov    -0x10(%rbp),%rdi
call   1060 <prime@plt>
cmp    $0x1,%eax
jne    11a5 <main+0x65>
mov    -0x10(%rbp),%rdi
call   1040 <palindrome@plt>
cmp    $0x1,%eax
jne    11a5 <main+0x65>
mov    -0x10(%rbp),%rsi
shl    $0x1,%rsi
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
jmp    11be <main+0x7e>
mov    -0x10(%rbp),%rsi
shl    $0x1,%rsi
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
jmp    114f <main+0xf>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11d2 <main+0x92>
lea    0xe9f(%rip),%r14
lea    0xe93(%rip),%r15
lea    0x8(%rsp),%rbx
jmp    11a0 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rsp),%rsi
add    %rsi,%rsi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11d2 <main+0x92>
mov    0x8(%rsp),%rdi
call   1060 <prime@plt>
cmp    $0x1,%eax
jne    1180 <main+0x40>
mov    0x8(%rsp),%rdi
call   1040 <palindrome@plt>
cmp    $0x1,%eax
jne    1180 <main+0x40>
mov    0x8(%rsp),%rsi
add    %rsi,%rsi
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
br label %3
3: ; preds = %18, %0
%4 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %22
6: ; preds = %3
%7 = load i64, i64* %2
%8 = call i32 @prime(i64 %7)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = load i64, i64* %2
%12 = call i32 @palindrome(i64 %11)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i64, i64* %2
%16 = mul nsw i64 %15, 2
%17 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %16)
br label %22
18: ; preds = %10, %6
%19 = load i64, i64* %2
%20 = mul nsw i64 %19, 2
%21 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %20)
br label %3
22: ; preds = %14, %3
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %23
5: ; preds = %0, %17
%6 = load i64, i64* %1
%7 = call i32 @prime(i64 %6)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %17
9: ; preds = %5
%10 = load i64, i64* %1
%11 = call i32 @palindrome(i64 %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i64, i64* %1
%15 = shl nsw i64 %14, 1
%16 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %15)
br label %23
17: ; preds = %9, %5
%18 = load i64, i64* %1
%19 = shl nsw i64 %18, 1
%20 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %19)
%21 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%22 = icmp eq i32 %21, 1
br i1 %22, label %5, label %23
23: ; preds = %17, %0, %13
ret i32 0
}