#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_palindromic(int);
int /*<<< orphan*/ printf(char *, int, int, int);
void p004() {
  int a, b, max_a, max_b, p;
  int max = 0;
  for (a = 100; a < 1000; a++) {
    for (b = a; b < 1000; b++) {
      p = a * b;
      if (is_palindromic(p) && p > max) {
        max = p;
        max_a = a;
        max_b = b;
      }
    }
  }
  printf("Largest palindromic product of two 3-digit numbers is %d * %d = %d.",
         max_a, max_b, max);
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x18(%rbp)
movl   $0x64,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jge    11b6 <p004+0x96>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    11a3 <p004+0x83>
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <is_palindromic@plt>
cmp    $0x0,%rax
je     1190 <p004+0x70>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1190 <p004+0x70>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1195 <p004+0x75>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1149 <p004+0x29>
jmp    11a8 <p004+0x88>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1136 <p004+0x16>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe3a(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x64,%r12d
xor    %ecx,%ecx
mov    $0xc9,%eax
mov    $0x2710,%ebx
jmp    1159 <p004+0x39>
nop
add    $0x1,%r12d
mov    0x4(%rsp),%eax
mov    (%rsp),%ebx
add    %eax,%ebx
add    $0x2,%eax
cmp    $0x3e8,%r12d
je     11b2 <p004+0x92>
mov    %eax,0x4(%rsp)
mov    %ebx,(%rsp)
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %esi,%r15d
mov    %r12d,%ebp
jmp    1187 <p004+0x67>
xchg   %ax,%ax
add    $0x1,%ebp
add    %r12d,%ebx
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %esi,%r15d
cmp    $0x3e8,%ebp
je     1140 <p004+0x20>
mov    %ebx,%edi
call   1030 <is_palindromic@plt>
test   %rax,%rax
setne  %dil
cmp    %r13d,%ebx
setg   %al
mov    %r12d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
test   %al,%dil
jne    1170 <p004+0x50>
mov    %r15d,%esi
mov    %r14d,%edx
mov    %r13d,%ecx
jmp    1170 <p004+0x50>
lea    0xe47(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

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

LLVM IR (-O2):
@.str = [68 x i8] c"Largest palindromic product of two 3-digit numbers is %d * %d = %d.\00"
define void @p004() {
br label %1
1: ; preds = %21, %0
%2 = phi i32 [ 0, %0 ], [ %18, %21 ]
%3 = phi i32 [ 100, %0 ], [ %22, %21 ]
%4 = phi i32 [ undef, %0 ], [ %17, %21 ]
%5 = phi i32 [ undef, %0 ], [ %16, %21 ]
br label %6
6: ; preds = %1, %6
%7 = phi i32 [ %18, %6 ], [ %2, %1 ]
%8 = phi i32 [ %17, %6 ], [ %4, %1 ]
%9 = phi i32 [ %16, %6 ], [ %5, %1 ]
%10 = phi i32 [ %19, %6 ], [ %3, %1 ]
%11 = mul nsw i32 %10, %3
%12 = tail call i64 @is_palindromic(i32 %11)
%13 = icmp ne i64 %12, 0
%14 = icmp sgt i32 %11, %7
%15 = select i1 %13, i1 %14, i1 false
%16 = select i1 %15, i32 %3, i32 %9
%17 = select i1 %15, i32 %10, i32 %8
%18 = select i1 %15, i32 %11, i32 %7
%19 = add nuw nsw i32 %10, 1
%20 = icmp eq i32 %19, 1000
br i1 %20, label %21, label %6
21: ; preds = %6
%22 = add nuw nsw i32 %3, 1
%23 = icmp eq i32 %22, 1000
br i1 %23, label %24, label %1
24: ; preds = %21
%25 = tail call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
ret void
}