#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*/ printf(char *, ...);
int main() {
  int x, y, z, i, bigpal, reverse = 0, palcount = 0;
  printf("Calculating the largest palindrome of the product of two 3-digit "
         "numbers...\n");
  for (x = 100; x < 1000; x++) {
    for (y = 100; y < 1000; y++) {
      z = x * y;
      i = z;
      while (i != 0) {
        reverse = reverse * 10;
        reverse = reverse + i % 10;
        i = i / 10;
      }
      if (reverse == z) {
        if (z > bigpal) {
          bigpal = z;
        }
        palcount++;
      }
      reverse = 0;
    }
  }
  printf("[+] Largest palindrome: %d\n", bigpal);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x64,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    11ff <main+0xef>
movl   $0x64,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jge    11ec <main+0xdc>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b0 <main+0xa0>
imul   $0xa,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x24(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    1173 <main+0x63>
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11d7 <main+0xc7>
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11ce <main+0xbe>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1156 <main+0x46>
jmp    11f1 <main+0xe1>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1142 <main+0x32>
mov    -0x18(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xef4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x64,%r8d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x64,%r9d
cs nopw 0x0(%rax,%rax,1)
mov    %r9d,%r10d
imul   %r8d,%r10d
xor    %ecx,%ecx
mov    %r10d,%edi
nopl   0x0(%rax)
lea    (%rcx,%rcx,4),%r11d
movslq %edi,%rax
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rdi
add    %edx,%edi
lea    (%rdi,%rdi,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %eax,%ecx
sub    %edx,%ecx
lea    (%rcx,%r11,2),%ecx
add    $0x9,%eax
cmp    $0x12,%eax
ja     1160 <main+0x40>
cmp    %esi,%r10d
mov    %esi,%eax
cmovg  %r10d,%eax
cmp    %r10d,%ecx
cmove  %eax,%esi
add    $0x1,%r9d
cmp    $0x3e8,%r9d
jne    1150 <main+0x30>
add    $0x1,%r8d
cmp    $0x3e8,%r8d
jne    1140 <main+0x20>
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [77 x i8] c"Calculating the largest palindrome of the product of two 3-digit numbers...\0A\00"
@.str.1 = [28 x i8] c"[+] Largest palindrome: %d\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 i32
store i32 0, i32* %1
store i32 0, i32* %7
store i32 0, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0))
store i32 100, i32* %2
br label %10
10: ; preds = %52, %0
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 1000
br i1 %12, label %13, label %55
13: ; preds = %10
store i32 100, i32* %3
br label %14
14: ; preds = %48, %13
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 1000
br i1 %16, label %17, label %51
17: ; preds = %14
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = mul nsw i32 %18, %19
store i32 %20, i32* %4
%21 = load i32, i32* %4
store i32 %21, i32* %5
br label %22
22: ; preds = %25, %17
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i32, i32* %7
%27 = mul nsw i32 %26, 10
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = load i32, i32* %5
%30 = srem i32 %29, 10
%31 = add nsw i32 %28, %30
store i32 %31, i32* %7
%32 = load i32, i32* %5
%33 = sdiv i32 %32, 10
store i32 %33, i32* %5
br label %22
34: ; preds = %22
%35 = load i32, i32* %7
%36 = load i32, i32* %4
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %47
38: ; preds = %34
%39 = load i32, i32* %4
%40 = load i32, i32* %6
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = load i32, i32* %4
store i32 %43, i32* %6
br label %44
44: ; preds = %42, %38
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %47
47: ; preds = %44, %34
store i32 0, i32* %7
br label %48
48: ; preds = %47
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %14
51: ; preds = %14
br label %52
52: ; preds = %51
%53 = load i32, i32* %2
%54 = add nsw i32 %53, 1
store i32 %54, i32* %2
br label %10
55: ; preds = %10
%56 = load i32, i32* %6
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %56)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [28 x i8] c"[+] Largest palindrome: %d\0A\00"
@str = [76 x i8] c"Calculating the largest palindrome of the product of two 3-digit numbers...\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %0, %25
%3 = phi i32 [ undef, %0 ], [ %22, %25 ]
%4 = phi i32 [ 100, %0 ], [ %26, %25 ]
br label %5
5: ; preds = %2, %18
%6 = phi i32 [ %3, %2 ], [ %22, %18 ]
%7 = phi i32 [ 100, %2 ], [ %23, %18 ]
%8 = mul nuw nsw i32 %7, %4
br label %9
9: ; preds = %5, %9
%10 = phi i32 [ 0, %5 ], [ %14, %9 ]
%11 = phi i32 [ %8, %5 ], [ %15, %9 ]
%12 = mul nsw i32 %10, 10
%13 = srem i32 %11, 10
%14 = add nsw i32 %12, %13
%15 = sdiv i32 %11, 10
%16 = add nsw i32 %11, 9
%17 = icmp ult i32 %16, 19
br i1 %17, label %18, label %9
18: ; preds = %9
%19 = icmp eq i32 %14, %8
%20 = icmp sgt i32 %8, %6
%21 = select i1 %19, i1 %20, i1 false
%22 = select i1 %21, i32 %8, i32 %6
%23 = add nuw nsw i32 %7, 1
%24 = icmp eq i32 %23, 1000
br i1 %24, label %25, label %5
25: ; preds = %18
%26 = add nuw nsw i32 %4, 1
%27 = icmp eq i32 %26, 1000
br i1 %27, label %28, label %2
28: ; preds = %25
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %22)
ret i32 0
}