#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(unsigned long);
int sqrt(int);
unsigned long biggest_palindrome(int top) {
  int c, d;
  unsigned long biggest = 0;
  unsigned long prod;
  for (d = top; d > (sqrt(top) * 2); d--) {
    for (c = top; c > (sqrt(top) * 2); c--) {
      prod = c * d;
      if (is_palindrome(prod))
        break;
    }
    if (prod > biggest) {
      biggest = prod;
    }
  }
  return biggest;
}


x86 assembly (clang, -O0):
<biggest_palindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
shl    $0x1,%ecx
cmp    %ecx,%eax
jle    11dc <biggest_palindrome+0xbc>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
shl    $0x1,%ecx
cmp    %ecx,%eax
jle    11b3 <biggest_palindrome+0x93>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <is_palindrome@plt>
cmp    $0x0,%rax
je     11a0 <biggest_palindrome+0x80>
jmp    11b3 <biggest_palindrome+0x93>
jmp    11a5 <biggest_palindrome+0x85>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    115d <biggest_palindrome+0x3d>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    11c9 <biggest_palindrome+0xa9>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11ce <biggest_palindrome+0xae>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <biggest_palindrome+0x19>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<biggest_palindrome>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
call   1040 <sqrt@plt>
add    %eax,%eax
cmp    %ebx,%eax
jge    11ee <biggest_palindrome+0xce>
movslq %ebx,%r14
mov    %ebx,%ecx
mov    %r14,%r15
imul   %r14,%r15
mov    %r14,%r12
neg    %r12
xor    %ebp,%ebp
mov    %r14,(%rsp)
mov    %r14,0x8(%rsp)
jmp    1198 <biggest_palindrome+0x78>
xchg   %ax,%ax
cmp    %rbp,%rbx
cmova  %rbx,%rbp
mov    (%rsp),%r13
add    $0xffffffffffffffff,%r13
mov    %r15d,%edi
call   1040 <sqrt@plt>
add    %eax,%eax
cltq
mov    0x8(%rsp),%r14
mov    %r15d,%ecx
mov    0x10(%rsp),%r15
sub    %r14,%r15
add    $0x1,%r12
mov    %r13,(%rsp)
cmp    %rax,%r13
jle    11f0 <biggest_palindrome+0xd0>
mov    %ecx,%r13d
mov    %ecx,%edi
call   1040 <sqrt@plt>
add    %eax,%eax
mov    %r15,0x10(%rsp)
mov    %r15,%rcx
cmp    %r13d,%eax
mov    %r13d,%r15d
jge    1160 <biggest_palindrome+0x40>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rcx,%rbx
mov    %rcx,%rdi
call   1030 <is_palindrome@plt>
test   %rax,%rax
jne    1160 <biggest_palindrome+0x40>
add    $0xffffffffffffffff,%r14
mov    %r15d,%edi
call   1040 <sqrt@plt>
add    %eax,%eax
cltq
lea    (%rbx,%r12,1),%rcx
cmp    %rax,%r14
jg     11c0 <biggest_palindrome+0xa0>
jmp    1160 <biggest_palindrome+0x40>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @biggest_palindrome(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %2
store i64 0, i64* %5
%7 = load i32, i32* %2
store i32 %7, i32* %4
br label %8
8: ; preds = %42, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = call i32 @sqrt(i32 %10)
%12 = mul nsw i32 %11, 2
%13 = icmp sgt i32 %9, %12
br i1 %13, label %14, label %45
14: ; preds = %8
%15 = load i32, i32* %2
store i32 %15, i32* %3
br label %16
16: ; preds = %32, %14
%17 = load i32, i32* %3
%18 = load i32, i32* %2
%19 = call i32 @sqrt(i32 %18)
%20 = mul nsw i32 %19, 2
%21 = icmp sgt i32 %17, %20
br i1 %21, label %22, label %35
22: ; preds = %16
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = mul nsw i32 %23, %24
%26 = sext i32 %25 to i64
store i64 %26, i64* %6
%27 = load i64, i64* %6
%28 = call i64 @is_palindrome(i64 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %22
br label %35
31: ; preds = %22
br label %32
32: ; preds = %31
%33 = load i32, i32* %3
%34 = add nsw i32 %33, -1
store i32 %34, i32* %3
br label %16
35: ; preds = %30, %16
%36 = load i64, i64* %6
%37 = load i64, i64* %5
%38 = icmp ugt i64 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = load i64, i64* %6
store i64 %40, i64* %5
br label %41
41: ; preds = %39, %35
br label %42
42: ; preds = %41
%43 = load i32, i32* %4
%44 = add nsw i32 %43, -1
store i32 %44, i32* %4
br label %8
45: ; preds = %8
%46 = load i64, i64* %5
ret i64 %46
}

LLVM IR (-O2):
define i64 @biggest_palindrome(i32 %0) {
%2 = tail call i32 @sqrt(i32 %0)
%3 = shl nsw i32 %2, 1
%4 = icmp slt i32 %3, %0
br i1 %4, label %5, label %34
5: ; preds = %1
%6 = sext i32 %0 to i64
br label %7
7: ; preds = %5, %25
%8 = phi i64 [ %6, %5 ], [ %29, %25 ]
%9 = phi i64 [ undef, %5 ], [ %26, %25 ]
%10 = phi i64 [ 0, %5 ], [ %28, %25 ]
%11 = tail call i32 @sqrt(i32 %0)
%12 = shl nsw i32 %11, 1
%13 = icmp slt i32 %12, %0
br i1 %13, label %19, label %25
14: ; preds = %19
%15 = tail call i32 @sqrt(i32 %0)
%16 = shl nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = icmp sgt i64 %24, %17
br i1 %18, label %19, label %25
19: ; preds = %7, %14
%20 = phi i64 [ %24, %14 ], [ %6, %7 ]
%21 = mul nsw i64 %20, %8
%22 = tail call i64 @is_palindrome(i64 %21)
%23 = icmp eq i64 %22, 0
%24 = add i64 %20, -1
br i1 %23, label %14, label %25
25: ; preds = %14, %19, %7
%26 = phi i64 [ %9, %7 ], [ %21, %19 ], [ %21, %14 ]
%27 = icmp ugt i64 %26, %10
%28 = select i1 %27, i64 %26, i64 %10
%29 = add i64 %8, -1
%30 = tail call i32 @sqrt(i32 %0)
%31 = shl nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = icmp sgt i64 %29, %32
br i1 %33, label %7, label %34
34: ; preds = %25, %1
%35 = phi i64 [ 0, %1 ], [ %28, %25 ]
ret i64 %35
}