#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*/ exit(int /*<<< orphan*/);
int is_palindrome(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int main() {
  int i, j, cur1, cur2;
  i = 999;
  while (i > 1) {
    cur1 = i * i;
    cur2 = i * (i - 1);
    char cur_str1[7];
    char cur_str2[7];
    memset(cur_str1, 0, 7);
    memset(cur_str2, 0, 7);
    sprintf(cur_str1, "%d", cur1);
    sprintf(cur_str2, "%d", cur2);
    if (is_palindrome(cur_str1) == 1) {
      printf("Largest 3-digit palindrome: ");
      printf(cur_str1);
      printf("\n");
      printf("Found by multiplying %d and %d\n", i, i);
      exit(0);
    }
    if (is_palindrome(cur_str2) == 1) {
      printf("Largest 3-digit palindrome: ");
      printf(cur_str2);
      printf("\n");
      printf("Found by multiplying %d and %d\n", i, (i - 1));
      exit(0);
    }
    i--;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e7,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1288 <main+0x138>
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
mov    %eax,-0x14(%rbp)
lea    -0x1b(%rbp),%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1050 <memset@plt>
lea    -0x22(%rbp),%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1050 <memset@plt>
lea    -0x1b(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe49(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x22(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe36(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x1b(%rbp),%rdi
call   1030 <is_palindrome@plt>
cmp    $0x1,%eax
jne    1223 <main+0xd3>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1b(%rbp),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    -0x22(%rbp),%rdi
call   1030 <is_palindrome@plt>
cmp    $0x1,%eax
jne    127a <main+0x12a>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x22(%rbp),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1166 <main+0x16>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x3e8,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x1(%rax),%ebx
mov    %ebx,%r14d
imul   %ebx,%r14d
mov    %rax,0x8(%rsp)
lea    -0x2(%rax),%r12d
mov    %r12d,%ebp
imul   %ebx,%ebp
lea    0x1(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1060 <memset@plt>
lea    0x11(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
lea    0xe35(%rip),%r15
mov    %r15,%rsi
mov    %r14d,%edx
call   1070 <sprintf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1070 <sprintf@plt>
lea    0x1(%rsp),%rdi
call   1040 <is_palindrome@plt>
cmp    $0x1,%eax
je     121b <main+0xbb>
mov    %r13,%rdi
call   1040 <is_palindrome@plt>
cmp    $0x1,%eax
je     1252 <main+0xf2>
mov    %ebx,%eax
cmp    $0x2,%ebx
ja     1180 <main+0x20>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1(%rsp),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rdx
add    $0xffffffff,%edx
lea    0xdd2(%rip),%rdi
mov    %edx,%esi
jmp    1288 <main+0x128>
lea    0xdaa(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x11(%rsp),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rsi
add    $0xffffffff,%esi
lea    0xd9b(%rip),%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [29 x i8] c"Largest 3-digit palindrome: \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [32 x i8] c"Found by multiplying %d and %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [7 x i8]
%7 = alloca [7 x i8]
store i32 0, i32* %1
store i32 999, i32* %2
br label %8
8: ; preds = %55, %0
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %58
11: ; preds = %8
%12 = load i32, i32* %2
%13 = load i32, i32* %2
%14 = mul nsw i32 %12, %13
store i32 %14, i32* %4
%15 = load i32, i32* %2
%16 = load i32, i32* %2
%17 = sub nsw i32 %16, 1
%18 = mul nsw i32 %15, %17
store i32 %18, i32* %5
%19 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 7)
%21 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i32 0, i32 7)
%23 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%24 = load i32, i32* %4
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%27 = load i32, i32* %5
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%30 = call i32 @is_palindrome(i8* %29)
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %41
32: ; preds = %11
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%34 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32, i32* %2
%38 = load i32, i32* %2
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %37, i32 %38)
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %11
%42 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%43 = call i32 @is_palindrome(i8* %42)
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %55
45: ; preds = %41
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%47 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32, i32* %2
%51 = load i32, i32* %2
%52 = sub nsw i32 %51, 1
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %50, i32 %52)
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %41
%56 = load i32, i32* %2
%57 = add nsw i32 %56, -1
store i32 %57, i32* %2
br label %8
58: ; preds = %8
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [29 x i8] c"Largest 3-digit palindrome: \00"
@.str.3 = [32 x i8] c"Found by multiplying %d and %d\0A\00"
define i32 @main() {
%1 = alloca [7 x i8]
%2 = alloca [7 x i8]
%3 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %0, %31
%6 = phi i32 [ 999, %0 ], [ %8, %31 ]
%7 = mul nsw i32 %6, %6
%8 = add nsw i32 %6, -1
%9 = mul nsw i32 %8, %6
%10 = call i32 @memset(i8* %3, i32 0, i32 7)
%11 = call i32 @memset(i8* %4, i32 0, i32 7)
%12 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
%13 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%14 = call i32 @is_palindrome(i8* %3)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %22
16: ; preds = %5
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* %3)
%19 = call i32 @putchar(i32 10)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %6, i32 %6)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %5
%23 = call i32 @is_palindrome(i8* %4)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* %4)
%28 = call i32 @putchar(i32 10)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %6, i32 %8)
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %22
%32 = icmp ugt i32 %6, 2
br i1 %32, label %5, label %33
33: ; preds = %31
ret i32 0
}