#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__ checkForPalindrome(int);
char *malloc(int);
int /*<<< orphan*/ printf(char *, int, int);
int strtol(char *, char **, int);
int findPalindrome(int digits) {
  char *largestDigitStr = malloc(sizeof(char) * digits);
  for (int i = 0; i < digits; ++i)
    largestDigitStr[i] = '9';
  int originalMultiplicand = strtol(largestDigitStr, (char **)NULL, 10);
  int multiplicand = originalMultiplicand;
  int multiplier = multiplicand;
  largestDigitStr = NULL;
  printf("Largest %d-Digit value is: %d\n", digits, multiplicand);
  int largestPalindrome = 0;
  for (int a = 0; multiplicand > a; --multiplicand) {
    for (int b = 0; multiplier > b; multiplier -= 1) {
      int possiblePalindrome = multiplicand * multiplier;
      int isPalindrome = checkForPalindrome(possiblePalindrome) ? !0 : 0;
      if (isPalindrome)
        largestPalindrome = possiblePalindrome > largestPalindrome
                                ? possiblePalindrome
                                : largestPalindrome;
    }
    multiplier = originalMultiplicand;
  }
  return largestPalindrome;
}


x86 assembly (clang, -O0):
<findPalindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118b <findPalindrome+0x4b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x39,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <findPalindrome+0x25>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    126d <findPalindrome+0x12d>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jle    1259 <findPalindrome+0x119>
mov    -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   1060 <checkForPalindrome@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1246 <findPalindrome+0x106>
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    123a <findPalindrome+0xfa>
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    1240 <findPalindrome+0x100>
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    124b <findPalindrome+0x10b>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e7 <findPalindrome+0xa7>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d4 <findPalindrome+0x94>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findPalindrome>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r15d
call   1060 <malloc@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    117e <findPalindrome+0x2e>
mov    %r15d,%edx
mov    %r14,%rdi
mov    $0x39,%esi
call   1040 <memset@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ebp
lea    0xe68(%rip),%rdi
mov    %r15d,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbp,0x8(%rsp)
test   %ebp,%ebp
jle    1219 <findPalindrome+0xc9>
mov    0x8(%rsp),%rax
lea    0x1(%rax),%ecx
mov    %ecx,0x4(%rsp)
mov    %eax,%r12d
imul   %eax,%r12d
mov    %eax,%r13d
neg    %r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %rax,0x10(%rsp)
mov    %r12d,%ebp
mov    0x4(%rsp),%r15d
nopl   (%rax)
mov    %ebx,%r14d
mov    %ebp,%edi
call   1070 <checkForPalindrome@plt>
cmp    %ebx,%ebp
cmovg  %ebp,%ebx
test   %rax,%rax
cmove  %r14d,%ebx
add    $0xffffffff,%r15d
add    %r13d,%ebp
cmp    $0x1,%r15d
jg     11e0 <findPalindrome+0x90>
mov    0x10(%rsp),%rcx
lea    -0x1(%rcx),%eax
sub    0x8(%rsp),%r12d
add    $0x1,%r13d
cmp    $0x1,%ecx
jg     11d0 <findPalindrome+0x80>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Largest %d-Digit value is: %d\0A\00"
define i32 @findPalindrome(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %2
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = mul i64 1, %14
%16 = trunc i64 %15 to i32
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %3
store i32 0, i32* %4
br label %18
18: ; preds = %27, %1
%19 = load i32, i32* %4
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 57, i8* %26
br label %27
27: ; preds = %22
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %18
30: ; preds = %18
%31 = load i8*, i8** %3
%32 = call i32 @strtol(i8* %31, i8** null, i32 10)
store i32 %32, i32* %5
%33 = load i32, i32* %5
store i32 %33, i32* %6
%34 = load i32, i32* %6
store i32 %34, i32* %7
store i8* null, i8** %3
%35 = load i32, i32* %2
%36 = load i32, i32* %6
%37 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %36)
store i32 0, i32* %8
store i32 0, i32* %9
br label %38
38: ; preds = %74, %30
%39 = load i32, i32* %6
%40 = load i32, i32* %9
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %77
42: ; preds = %38
store i32 0, i32* %10
br label %43
43: ; preds = %69, %42
%44 = load i32, i32* %7
%45 = load i32, i32* %10
%46 = icmp sgt i32 %44, %45
br i1 %46, label %47, label %72
47: ; preds = %43
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = mul nsw i32 %48, %49
store i32 %50, i32* %11
%51 = load i32, i32* %11
%52 = call i64 @checkForPalindrome(i32 %51)
%53 = icmp ne i64 %52, 0
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 1, i32 0
store i32 %55, i32* %12
%56 = load i32, i32* %12
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %68
58: ; preds = %47
%59 = load i32, i32* %11
%60 = load i32, i32* %8
%61 = icmp sgt i32 %59, %60
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = load i32, i32* %11
br label %66
64: ; preds = %58
%65 = load i32, i32* %8
br label %66
66: ; preds = %64, %62
%67 = phi i32 [ %63, %62 ], [ %65, %64 ]
store i32 %67, i32* %8
br label %68
68: ; preds = %66, %47
br label %69
69: ; preds = %68
%70 = load i32, i32* %7
%71 = sub nsw i32 %70, 1
store i32 %71, i32* %7
br label %43
72: ; preds = %43
%73 = load i32, i32* %5
store i32 %73, i32* %7
br label %74
74: ; preds = %72
%75 = load i32, i32* %6
%76 = add nsw i32 %75, -1
store i32 %76, i32* %6
br label %38
77: ; preds = %38
%78 = load i32, i32* %8
ret i32 %78
}

LLVM IR (-O2):
@.str = [31 x i8] c"Largest %d-Digit value is: %d\0A\00"
define i32 @findPalindrome(i32 %0) {
%2 = tail call i8* @malloc(i32 %0)
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @strtol(i8* nocapture %2, i8** null, i32 10)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %7)
%9 = icmp sgt i32 %7, 0
br i1 %9, label %10, label %13
10: ; preds = %6, %15
%11 = phi i32 [ %16, %15 ], [ %7, %6 ]
%12 = phi i32 [ %26, %15 ], [ 0, %6 ]
br label %18
13: ; preds = %15, %6
%14 = phi i32 [ 0, %6 ], [ %26, %15 ]
ret i32 %14
15: ; preds = %18
%16 = add nsw i32 %11, -1
%17 = icmp sgt i32 %11, 1
br i1 %17, label %10, label %13
18: ; preds = %10, %18
%19 = phi i32 [ %27, %18 ], [ %7, %10 ]
%20 = phi i32 [ %26, %18 ], [ %12, %10 ]
%21 = mul nsw i32 %19, %11
%22 = tail call i64 @checkForPalindrome(i32 %21)
%23 = icmp eq i64 %22, 0
%24 = icmp sgt i32 %21, %20
%25 = select i1 %24, i32 %21, i32 %20
%26 = select i1 %23, i32 %20, i32 %25
%27 = add nsw i32 %19, -1
%28 = icmp sgt i32 %19, 1
br i1 %28, label %18, label %15
}