#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__ is_palindrome(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int problem4(void) {
  int i, j, largest, product;
  char buffer[256];
  for (largest = 0, i = 100; i < 1000; i++) {
    for (j = 100; j < 1000; j++) {
      product = i * j;
      snprintf(buffer, 256, "%d", product);
      if (is_palindrome(buffer) && product > largest)
        largest = product;
    }
  }
  printf("The largest palindrome made from the product of two 3 digit numbers "
         "is %d\n",
         largest);
  return 0;
}


x86 assembly (clang, -O0):
<problem4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x64,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jge    11dd <problem4+0xad>
movl   $0x64,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    11ca <problem4+0x9a>
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%ecx
mov    $0x100,%esi
lea    0xe76(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <is_palindrome@plt>
cmp    $0x0,%rax
je     11b7 <problem4+0x87>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11b7 <problem4+0x87>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11bc <problem4+0x8c>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115d <problem4+0x2d>
jmp    11cf <problem4+0x9f>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1149 <problem4+0x19>
mov    -0xc(%rbp),%esi
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<problem4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
xor    %ebx,%ebx
mov    $0x64,%r12d
mov    $0x2710,%ebp
lea    0xeab(%rip),%r14
lea    0x10(%rsp),%r15
jmp    1174 <problem4+0x44>
nopl   0x0(%rax)
add    $0x1,%r12d
mov    0xc(%rsp),%ebp
add    $0x64,%ebp
cmp    $0x3e8,%r12d
je     11b3 <problem4+0x83>
mov    $0x384,%r13d
mov    %ebp,0xc(%rsp)
jmp    118f <problem4+0x5f>
test   %rax,%rax
cmovne %ecx,%ebx
add    %r12d,%ebp
add    $0xffffffff,%r13d
je     1160 <problem4+0x30>
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1050 <snprintf@plt>
mov    %r15,%rdi
call   1030 <is_palindrome@plt>
mov    %ebp,%ecx
cmp    %ebx,%ebp
jg     1180 <problem4+0x50>
mov    %ebx,%ecx
jmp    1180 <problem4+0x50>
lea    0xe49(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [75 x i8] c"The largest palindrome made from the product of two 3 digit numbers is %d\0A\00"
define i32 @problem4() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
store i32 0, i32* %3
store i32 100, i32* %1
br label %6
6: ; preds = %34, %0
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1000
br i1 %8, label %9, label %37
9: ; preds = %6
store i32 100, i32* %2
br label %10
10: ; preds = %30, %9
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 1000
br i1 %12, label %13, label %33
13: ; preds = %10
%14 = load i32, i32* %1
%15 = load i32, i32* %2
%16 = mul nsw i32 %14, %15
store i32 %16, i32* %4
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32 @snprintf(i8* %17, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%21 = call i64 @is_palindrome(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %13
%24 = load i32, i32* %4
%25 = load i32, i32* %3
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i32, i32* %4
store i32 %28, i32* %3
br label %29
29: ; preds = %27, %23, %13
br label %30
30: ; preds = %29
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 1
store i32 %32, i32* %2
br label %10
33: ; preds = %10
br label %34
34: ; preds = %33
%35 = load i32, i32* %1
%36 = add nsw i32 %35, 1
store i32 %36, i32* %1
br label %6
37: ; preds = %6
%38 = load i32, i32* %3
%39 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i32 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [75 x i8] c"The largest palindrome made from the product of two 3 digit numbers is %d\0A\00"
define i32 @problem4() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %18
%4 = phi i32 [ 100, %0 ], [ %19, %18 ]
%5 = phi i32 [ 0, %0 ], [ %15, %18 ]
br label %6
6: ; preds = %3, %6
%7 = phi i32 [ %5, %3 ], [ %15, %6 ]
%8 = phi i32 [ 100, %3 ], [ %16, %6 ]
%9 = mul nuw nsw i32 %8, %4
%10 = call i32 @snprintf(i8* %2, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i64 @is_palindrome(i8* %2)
%12 = icmp ne i64 %11, 0
%13 = icmp sgt i32 %9, %7
%14 = select i1 %12, i1 %13, i1 false
%15 = select i1 %14, i32 %9, i32 %7
%16 = add nuw nsw i32 %8, 1
%17 = icmp eq i32 %16, 1000
br i1 %17, label %18, label %6
18: ; preds = %6
%19 = add nuw nsw i32 %4, 1
%20 = icmp eq i32 %19, 1000
br i1 %20, label %21, label %3
21: ; preds = %18
%22 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i32 %15)
ret i32 0
}