#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*/ convert(int, char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ is_palindrome(char *);
int /*<<< orphan*/ perror(char *);
int main() {
  FILE *fin, *fout;
  int base, mod;
  fin = fopen("palsquare.in", "r");
  if (!fin) {
    perror("open file palsquare.in failed");
    return -1;
  }
  fscanf(fin, "%d", &base);
  fclose(fin);
  fout = fopen("palsquare.out", "w");
  char orig[15];
  char list[15];
  int i, j;
  for (i = 1; i <= 300; ++i) {
    convert(i * i, list, base);
    if (is_palindrome(list)) {
      convert(i, orig, base);
      fprintf(fin, "%s %s\n", orig, list);
    }
  }
  fclose(fin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b9 <main+0x49>
lea    0xe67(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1271 <main+0x101>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe53(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x44(%rbp)
cmpl   $0x12c,-0x44(%rbp)
jg     1261 <main+0xf1>
mov    -0x44(%rbp),%edi
imul   -0x44(%rbp),%edi
lea    -0x3e(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <convert@plt>
lea    -0x3e(%rbp),%rdi
call   1050 <is_palindrome@plt>
cmp    $0x0,%rax
je     124e <main+0xde>
mov    -0x44(%rbp),%edi
lea    -0x2f(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <convert@plt>
mov    -0x10(%rbp),%rdi
lea    -0x2f(%rbp),%rdx
lea    -0x3e(%rbp),%rcx
lea    0xdf7(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1253 <main+0xe3>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11f4 <main+0x84>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
lea    0xe7d(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1251 <main+0xe1>
mov    %rax,%r14
lea    0xe8b(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xe72(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1080 <fopen@plt>
mov    $0x1,%ebp
lea    0x12(%rsp),%rbx
lea    0x21(%rsp),%r15
lea    0xe60(%rip),%r12
jmp    11fb <main+0x8b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x12d,%ebp
je     123a <main+0xca>
mov    %ebp,%edi
imul   %ebp,%edi
mov    0xc(%rsp),%edx
mov    %rbx,%rsi
call   1030 <convert@plt>
mov    %rbx,%rdi
call   1050 <is_palindrome@plt>
test   %rax,%rax
je     11f0 <main+0x80>
mov    0xc(%rsp),%edx
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <convert@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1070 <fprintf@plt>
jmp    11f0 <main+0x80>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb7(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
jmp    1244 <main+0xd4>

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

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