#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*/ F_OK;
scalar_t__ Reverse(unsigned int);
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ isPalindrome(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  unsigned int n_case;
  unsigned int N;
  unsigned int i;
  if (argc != 2) {
    printf("Usage: %s INPUT_FILE\n\n", argv[0]);
    exit(-1);
  }
  if (access(argv[1], F_OK)) {
    printf("Error: INPUT_FILE %s does not exist\n\n", argv[1]);
    exit(-1);
  }
  freopen(argv[1], "r", stdin);
  scanf("%d\n", &n_case);
  while (n_case--) {
    scanf("%d\n", &N);
    i = 0;
    while (!isPalindrome(N)) {
      N += Reverse(N);
      i++;
    }
    printf("%u %u\n", i, N);
  }
  fclose(stdin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bf <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0x0,%rax
je     11ff <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
lea    0xe26(%rip),%rsi
call   1050 <freopen@plt>
lea    0xe1c(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     12af <main+0x12f>
lea    0xdf8(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <isPalindrome@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1274 <main+0xf4>
jmp    1296 <main+0x116>
mov    -0x18(%rbp),%edi
call   1080 <Reverse@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1257 <main+0xd7>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122c <main+0xac>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1281 <main+0x101>
mov    0x8(%rbx),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
mov    0x8(%rbx),%rcx
test   %rax,%rax
jne    128d <main+0x10d>
mov    0x2e2a(%rip),%r12
mov    (%r12),%edx
lea    0xe74(%rip),%rsi
mov    %rcx,%rdi
call   1050 <freopen@plt>
lea    0xe67(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    1201 <main+0x81>
mov    (%r12),%edi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe37(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xe2f(%rip),%rbx
jmp    1237 <main+0xb7>
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
subl   $0x1,0xc(%rsp)
jb     11e9 <main+0x69>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%edi
call   1060 <isPalindrome@plt>
mov    $0x0,%ebp
test   %eax,%eax
jne    1220 <main+0xa0>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%edi
call   1080 <Reverse@plt>
add    0x8(%rsp),%eax
mov    %eax,0x8(%rsp)
add    $0x1,%ebp
mov    %eax,%edi
call   1060 <isPalindrome@plt>
test   %eax,%eax
je     1260 <main+0xe0>
jmp    1220 <main+0xa0>
mov    (%rbx),%rsi
lea    0xd75(%rip),%rdi
jmp    1297 <main+0x117>
lea    0xd83(%rip),%rdi
mov    %rcx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Usage: %s INPUT_FILE\0A\0A\00"
@F_OK = global i32 0
@.str.1 = [38 x i8] c"Error: INPUT_FILE %s does not exist\0A\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [7 x i8] c"%u %u\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @F_OK
%22 = call i64 @access(i8* %20, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %17
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i32, i32* @stdin
%35 = call i32 @freopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %6)
br label %37
37: ; preds = %57, %30
%38 = load i32, i32* %6
%39 = add i32 %38, -1
store i32 %39, i32* %6
%40 = icmp ne i32 %38, 0
br i1 %40, label %41, label %61
41: ; preds = %37
%42 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %7)
store i32 0, i32* %8
br label %43
43: ; preds = %48, %41
%44 = load i32, i32* %7
%45 = call i32 @isPalindrome(i32 %44)
%46 = icmp ne i32 %45, 0
%47 = xor i1 %46, true
br i1 %47, label %48, label %57
48: ; preds = %43
%49 = load i32, i32* %7
%50 = call i64 @Reverse(i32 %49)
%51 = load i32, i32* %7
%52 = zext i32 %51 to i64
%53 = add nsw i64 %52, %50
%54 = trunc i64 %53 to i32
store i32 %54, i32* %7
%55 = load i32, i32* %8
%56 = add i32 %55, 1
store i32 %56, i32* %8
br label %43
57: ; preds = %43
%58 = load i32, i32* %8
%59 = load i32, i32* %7
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %58, i32 %59)
br label %37
61: ; preds = %37
%62 = load i32, i32* @stdin
%63 = call i32 @fclose(i32 %62)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Usage: %s INPUT_FILE\0A\0A\00"
@F_OK = global i32 0
@.str.1 = [38 x i8] c"Error: INPUT_FILE %s does not exist\0A\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [7 x i8] c"%u %u\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @F_OK
%16 = tail call i64 @access(i8* %14, i32 %15)
%17 = icmp eq i64 %16, 0
%18 = load i8*, i8** %13
br i1 %17, label %22, label %19
19: ; preds = %12
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %12
%23 = load i32, i32* @stdin
%24 = tail call i32 @freopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%26 = load i32, i32* %3
%27 = add i32 %26, -1
store i32 %27, i32* %3
%28 = icmp eq i32 %26, 0
br i1 %28, label %51, label %29
29: ; preds = %22, %44
%30 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%31 = load i32, i32* %4
%32 = call i32 @isPalindrome(i32 %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %29, %34
%35 = phi i32 [ %41, %34 ], [ 0, %29 ]
%36 = load i32, i32* %4
%37 = call i64 @Reverse(i32 %36)
%38 = load i32, i32* %4
%39 = trunc i64 %37 to i32
%40 = add i32 %38, %39
store i32 %40, i32* %4
%41 = add i32 %35, 1
%42 = call i32 @isPalindrome(i32 %40)
%43 = icmp eq i32 %42, 0
br i1 %43, label %34, label %44
44: ; preds = %34, %29
%45 = phi i32 [ 0, %29 ], [ %41, %34 ]
%46 = load i32, i32* %4
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %45, i32 %46)
%48 = load i32, i32* %3
%49 = add i32 %48, -1
store i32 %49, i32* %3
%50 = icmp eq i32 %48, 0
br i1 %50, label %51, label %29
51: ; preds = %44, %22
%52 = load i32, i32* @stdin
%53 = call i32 @fclose(i32 %52)
ret i32 0
}