#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(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int PalindromeThreeDigitProduct() {
  int startingPt = 999;
  long int palindrome = 0;
  char tempstr[100];
  int i, j;
  for (i = startingPt; i >= 100; i--) {
    for (j = startingPt; j >= 100; j--) {
      sprintf(tempstr, "%ld", i * j);
      if (isPalindrome(tempstr)) {
        if (palindrome < i * j)
          palindrome = i * j;
      }
    }
  }
  return palindrome;
}


x86 assembly (clang, -O0):
<PalindromeThreeDigitProduct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x3e7,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x84(%rbp)
cmpl   $0x64,-0x84(%rbp)
jl     11fd <PalindromeThreeDigitProduct+0xdd>
mov    -0x4(%rbp),%eax
mov    %eax,-0x88(%rbp)
cmpl   $0x64,-0x88(%rbp)
jl     11e4 <PalindromeThreeDigitProduct+0xc4>
lea    -0x80(%rbp),%rdi
mov    -0x84(%rbp),%edx
imul   -0x88(%rbp),%edx
lea    0xe82(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x80(%rbp),%rdi
call   1030 <isPalindrome@plt>
cmp    $0x0,%rax
je     11cb <PalindromeThreeDigitProduct+0xab>
mov    -0x10(%rbp),%rax
mov    -0x84(%rbp),%ecx
imul   -0x88(%rbp),%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    11c6 <PalindromeThreeDigitProduct+0xa6>
mov    -0x84(%rbp),%eax
imul   -0x88(%rbp),%eax
cltq
mov    %rax,-0x10(%rbp)
jmp    11cb <PalindromeThreeDigitProduct+0xab>
jmp    11d0 <PalindromeThreeDigitProduct+0xb0>
mov    -0x88(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x88(%rbp)
jmp    1159 <PalindromeThreeDigitProduct+0x39>
jmp    11e9 <PalindromeThreeDigitProduct+0xc9>
mov    -0x84(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x84(%rbp)
jmp    1143 <PalindromeThreeDigitProduct+0x23>
mov    -0x10(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PalindromeThreeDigitProduct>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    $0x3e7,%eax
mov    $0xf3a71,%ebx
mov    $0xfffffffffffffc19,%rbp
xor    %r12d,%r12d
lea    0xeb7(%rip),%r14
lea    0x10(%rsp),%r15
jmp    116e <PalindromeThreeDigitProduct+0x4e>
mov    (%rsp),%rcx
lea    -0x1(%rcx),%rax
mov    0x8(%rsp),%rbx
add    $0xfffffffffffffc19,%rbx
add    $0x1,%rbp
cmp    $0x64,%rcx
jbe    11b6 <PalindromeThreeDigitProduct+0x96>
mov    %rax,(%rsp)
mov    $0x3e8,%r13d
mov    %rbx,0x8(%rsp)
jmp    1194 <PalindromeThreeDigitProduct+0x74>
nop
test   %rax,%rax
cmovne %rcx,%r12
add    $0xffffffffffffffff,%r13
add    %rbp,%rbx
cmp    $0x64,%r13
jbe    1150 <PalindromeThreeDigitProduct+0x30>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <sprintf@plt>
mov    %r15,%rdi
call   1030 <isPalindrome@plt>
mov    %rbx,%rcx
cmp    %rbx,%r12
jl     1180 <PalindromeThreeDigitProduct+0x60>
mov    %r12,%rcx
jmp    1180 <PalindromeThreeDigitProduct+0x60>
mov    %r12d,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
define i32 @PalindromeThreeDigitProduct() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 999, i32* %1
store i64 0, i64* %2
%6 = load i32, i32* %1
store i32 %6, i32* %4
br label %7
7: ; preds = %42, %0
%8 = load i32, i32* %4
%9 = icmp sge i32 %8, 100
br i1 %9, label %10, label %45
10: ; preds = %7
%11 = load i32, i32* %1
store i32 %11, i32* %5
br label %12
12: ; preds = %38, %10
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 100
br i1 %14, label %15, label %41
15: ; preds = %12
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = mul nsw i32 %17, %18
%20 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%22 = call i64 @isPalindrome(i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %37
24: ; preds = %15
%25 = load i64, i64* %2
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = mul nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %25, %29
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = mul nsw i32 %32, %33
%35 = sext i32 %34 to i64
store i64 %35, i64* %2
br label %36
36: ; preds = %31, %24
br label %37
37: ; preds = %36, %15
br label %38
38: ; preds = %37
%39 = load i32, i32* %5
%40 = add nsw i32 %39, -1
store i32 %40, i32* %5
br label %12
41: ; preds = %12
br label %42
42: ; preds = %41
%43 = load i32, i32* %4
%44 = add nsw i32 %43, -1
store i32 %44, i32* %4
br label %7
45: ; preds = %7
%46 = load i64, i64* %2
%47 = trunc i64 %46 to i32
ret i32 %47
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
define i32 @PalindromeThreeDigitProduct() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %19
%4 = phi i64 [ 999, %0 ], [ %20, %19 ]
%5 = phi i64 [ 0, %0 ], [ %16, %19 ]
br label %6
6: ; preds = %3, %6
%7 = phi i64 [ 999, %3 ], [ %17, %6 ]
%8 = phi i64 [ %5, %3 ], [ %16, %6 ]
%9 = mul nuw nsw i64 %7, %4
%10 = trunc i64 %9 to i32
%11 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i64 @isPalindrome(i8* %2)
%13 = icmp eq i64 %12, 0
%14 = icmp slt i64 %8, %9
%15 = select i1 %14, i64 %9, i64 %8
%16 = select i1 %13, i64 %8, i64 %15
%17 = add nsw i64 %7, -1
%18 = icmp ugt i64 %7, 100
br i1 %18, label %6, label %19
19: ; preds = %6
%20 = add nsw i64 %4, -1
%21 = icmp ugt i64 %4, 100
br i1 %21, label %3, label %22
22: ; preds = %19
%23 = trunc i64 %16 to i32
ret i32 %23
}