#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ is_palind(char *, int);
int /*<<< orphan*/ transfrom_base_k(int, int, char *, int *);
int main() {
  FILE *fin = fopen("palsquare.in", "r");
  FILE *fout = fopen("palsquare.out", "w");
  int i, n, k, len;
  char s[30];
  fscanf(fin, "%d", &k);
  for (i = 1; i <= 300; i++) {
    n = i * i;
    transfrom_base_k(n, k, s, &len);
    if (is_palind(s, len)) {
      transfrom_base_k(i, k, s, &len);
      fprintf(fout, "%s ", s);
      transfrom_base_k(n, k, s, &len);
      fprintf(fout, "%s\n", s);
    }
  }
  fclose(fin);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe82(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe77(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <fscanf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x12c,-0x1c(%rbp)
jg     1259 <main+0xf9>
mov    -0x1c(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
lea    -0x50(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1080 <transfrom_base_k@plt>
lea    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1040 <is_palind@plt>
cmp    $0x0,%rax
je     1246 <main+0xe6>
mov    -0x1c(%rbp),%edi
mov    -0x24(%rbp),%esi
lea    -0x50(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1080 <transfrom_base_k@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe08(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
lea    -0x50(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1080 <transfrom_base_k@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xde5(%rip),%rsi
call   1060 <fprintf@plt>
jmp    124b <main+0xeb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b8 <main+0x58>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe84(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xe7e(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <fscanf@plt>
mov    $0x1,%ebp
lea    0x10(%rsp),%rbx
lea    0x4(%rsp),%r12
lea    0xe5f(%rip),%r14
jmp    11db <main+0x7b>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x12d,%ebp
je     1247 <main+0xe7>
mov    %ebp,%r13d
imul   %ebp,%r13d
mov    (%rsp),%esi
mov    %r13d,%edi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1080 <transfrom_base_k@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <is_palind@plt>
test   %rax,%rax
je     11d0 <main+0x70>
mov    (%rsp),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1080 <transfrom_base_k@plt>
mov    %r15,%rdi
lea    0xe04(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    (%rsp),%esi
mov    %r13d,%edi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1080 <transfrom_base_k@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
jmp    11d0 <main+0x70>
mov    0x8(%rsp),%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"palsquare.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"palsquare.out\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%s \00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [30 x i8]
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %2
%12 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %6)
store i32 1, i32* %4
br label %13
13: ; preds = %44, %0
%14 = load i32, i32* %4
%15 = icmp sle i32 %14, 300
br i1 %15, label %16, label %47
16: ; preds = %13
%17 = load i32, i32* %4
%18 = load i32, i32* %4
%19 = mul nsw i32 %17, %18
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%23 = call i32 @transfrom_base_k(i32 %20, i32 %21, i8* %22, i32* %7)
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%25 = load i32, i32* %7
%26 = call i64 @is_palind(i8* %24, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %43
28: ; preds = %16
%29 = load i32, i32* %4
%30 = load i32, i32* %6
%31 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%32 = call i32 @transfrom_base_k(i32 %29, i32 %30, i8* %31, i32* %7)
%33 = load i32*, i32** %3
%34 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%35 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%39 = call i32 @transfrom_base_k(i32 %36, i32 %37, i8* %38, i32* %7)
%40 = load i32*, i32** %3
%41 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%42 = call i32 @fprintf(i32* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %28, %16
br label %44
44: ; preds = %43
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %13
47: ; preds = %13
%48 = load i32*, i32** %2
%49 = call i32 @fclose(i32* %48)
%50 = load i32*, i32** %3
%51 = call i32 @fclose(i32* %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"palsquare.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"palsquare.out\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%s \00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [30 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%9 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
br label %10
10: ; preds = %0, %25
%11 = phi i32 [ 1, %0 ], [ %26, %25 ]
%12 = mul nuw nsw i32 %11, %11
%13 = load i32, i32* %1
%14 = call i32 @transfrom_base_k(i32 %12, i32 %13, i8* %8, i32* %2)
%15 = load i32, i32* %2
%16 = call i64 @is_palind(i8* %8, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %10
%19 = load i32, i32* %1
%20 = call i32 @transfrom_base_k(i32 %11, i32 %19, i8* %8, i32* %2)
%21 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%22 = load i32, i32* %1
%23 = call i32 @transfrom_base_k(i32 %12, i32 %22, i8* %8, i32* %2)
%24 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %8)
br label %25
25: ; preds = %10, %18
%26 = add nuw nsw i32 %11, 1
%27 = icmp eq i32 %26, 301
br i1 %27, label %28, label %10
28: ; preds = %25
%29 = call i32 @fclose(i32* %4)
%30 = call i32 @fclose(i32* %5)
ret i32 0
}