#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 */
scalar_t__ isPalindrome(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int i, j, largest = 0, product;
  printf("\n\n\nI will now calculate the largest palindrome product of 2 "
         "three-digit numbers.");
  for (i = 100; i <= 999; i++) {
    for (j = 100; j <= 999; j++) {
      product = i * j;
      if (isPalindrome(product) && product > largest) {
        largest = product;
        printf("\n%d x %d = %d", i, j, product);
      }
    }
  }
  printf("\n\nThe answer is %d.\n\n\n", largest);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x64,-0x8(%rbp)
cmpl   $0x3e7,-0x8(%rbp)
jg     11d7 <main+0xb7>
movl   $0x64,-0xc(%rbp)
cmpl   $0x3e7,-0xc(%rbp)
jg     11c4 <main+0xa4>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <isPalindrome@plt>
cmp    $0x0,%rax
je     11b1 <main+0x91>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11b1 <main+0x91>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <main+0x96>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115f <main+0x3f>
jmp    11c9 <main+0xa9>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114b <main+0x2b>
mov    -0x10(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x64,%r12d
mov    $0x2710,%r13d
lea    0xf05(%rip),%r14
xor    %r15d,%r15d
jmp    1171 <main+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12d
add    $0x64,%r13d
cmp    $0x3e8,%r12d
je     11b5 <main+0x95>
mov    %r13d,%ebp
mov    $0x64,%ebx
jmp    118e <main+0x6e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
add    %r12d,%ebp
cmp    $0x3e8,%ebx
je     1160 <main+0x40>
mov    %ebp,%edi
call   1040 <isPalindrome@plt>
test   %rax,%rax
je     1180 <main+0x60>
cmp    %r15d,%ebp
jle    1180 <main+0x60>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%r15d
jmp    1180 <main+0x60>
lea    0xea3(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [81 x i8] c"\0A\0A\0AI will now calculate the largest palindrome product of 2 three-digit numbers.\00"
@.str.1 = [14 x i8] c"\0A%d x %d = %d\00"
@.str.2 = [23 x i8] c"\0A\0AThe answer is %d.\0A\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
store i32 100, i32* %2
br label %7
7: ; preds = %36, %0
%8 = load i32, i32* %2
%9 = icmp sle i32 %8, 999
br i1 %9, label %10, label %39
10: ; preds = %7
store i32 100, i32* %3
br label %11
11: ; preds = %32, %10
%12 = load i32, i32* %3
%13 = icmp sle i32 %12, 999
br i1 %13, label %14, label %35
14: ; preds = %11
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = mul nsw i32 %15, %16
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = call i64 @isPalindrome(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %14
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i32, i32* %5
store i32 %26, i32* %4
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = load i32, i32* %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %28, i32 %29)
br label %31
31: ; preds = %25, %21, %14
br label %32
32: ; preds = %31
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %11
35: ; preds = %11
br label %36
36: ; preds = %35
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %7
39: ; preds = %7
%40 = load i32, i32* %4
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [81 x i8] c"\0A\0A\0AI will now calculate the largest palindrome product of 2 three-digit numbers.\00"
@.str.1 = [14 x i8] c"\0A%d x %d = %d\00"
@.str.2 = [23 x i8] c"\0A\0AThe answer is %d.\0A\0A\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
br label %2
2: ; preds = %0, %19
%3 = phi i32 [ 100, %0 ], [ %20, %19 ]
%4 = phi i32 [ 0, %0 ], [ %16, %19 ]
br label %5
5: ; preds = %2, %15
%6 = phi i32 [ %4, %2 ], [ %16, %15 ]
%7 = phi i32 [ 100, %2 ], [ %17, %15 ]
%8 = mul nuw nsw i32 %7, %3
%9 = tail call i64 @isPalindrome(i32 %8)
%10 = icmp ne i64 %9, 0
%11 = icmp sgt i32 %8, %6
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %7, i32 %8)
br label %15
15: ; preds = %5, %13
%16 = phi i32 [ %8, %13 ], [ %6, %5 ]
%17 = add nuw nsw i32 %7, 1
%18 = icmp eq i32 %17, 1000
br i1 %18, label %19, label %5
19: ; preds = %15
%20 = add nuw nsw i32 %3, 1
%21 = icmp eq i32 %20, 1000
br i1 %21, label %22, label %2
22: ; preds = %19
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %16)
ret i32 0
}