#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 */
int /*<<< orphan*/ itoa(int, char *, int);
int palindrome(char *, int);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
int main() {
  char string[20] = "";
  int i, j, len, product, maxProduct = 0;
  for (i = 100; i <= 999; i++) {
    for (j = 100; j <= 999; j++) {
      product = i * j;
      itoa(product, string, 10);
      len = strlen(string);
      if (palindrome(string, len) == 1) {
        if (product > maxProduct) {
          maxProduct = product;
        }
      }
    }
  }
  printf("The max product is %d\n", maxProduct);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x64,-0x24(%rbp)
cmpl   $0x3e7,-0x24(%rbp)
jg     1217 <main+0xc7>
movl   $0x64,-0x28(%rbp)
cmpl   $0x3e7,-0x28(%rbp)
jg     1204 <main+0xb4>
mov    -0x24(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1070 <itoa@plt>
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <palindrome@plt>
cmp    $0x1,%eax
jne    11f1 <main+0xa1>
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jle    11ec <main+0x9c>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    11f1 <main+0xa1>
jmp    11f6 <main+0xa6>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1191 <main+0x41>
jmp    1209 <main+0xb9>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117d <main+0x2d>
mov    -0x34(%rbp),%esi
lea    0xddf(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
mov    $0x64,%r15d
xor    %r13d,%r13d
mov    $0x2710,%r12d
mov    %rsp,%r14
jmp    1191 <main+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15d
add    $0x64,%r12d
cmp    $0x3e8,%r15d
je     11dc <main+0x9c>
mov    $0x384,%ebx
mov    %r12d,%ebp
jmp    11af <main+0x6f>
nopl   0x0(%rax,%rax,1)
cmp    $0x1,%eax
cmove  %ecx,%r13d
add    %r15d,%ebp
add    $0xffffffff,%ebx
je     1180 <main+0x40>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1060 <itoa@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <palindrome@plt>
mov    %ebp,%ecx
cmp    %r13d,%ebp
jg     11a0 <main+0x60>
mov    %r13d,%ecx
jmp    11a0 <main+0x60>
lea    0xe1d(%rip),%rdi
mov    %r13d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"The max product is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [20 x i8]* %2 to i8*
store i32 0, i32* %7
store i32 100, i32* %3
br label %9
9: ; preds = %41, %0
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 999
br i1 %11, label %12, label %44
12: ; preds = %9
store i32 100, i32* %4
br label %13
13: ; preds = %37, %12
%14 = load i32, i32* %4
%15 = icmp sle i32 %14, 999
br i1 %15, label %16, label %40
16: ; preds = %13
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = mul nsw i32 %17, %18
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%22 = call i32 @itoa(i32 %20, i8* %21, i32 10)
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %5
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%26 = load i32, i32* %5
%27 = call i32 @palindrome(i8* %25, i32 %26)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %36
29: ; preds = %16
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = load i32, i32* %6
store i32 %34, i32* %7
br label %35
35: ; preds = %33, %29
br label %36
36: ; preds = %35, %16
br label %37
37: ; preds = %36
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %13
40: ; preds = %13
br label %41
41: ; preds = %40
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
br label %9
44: ; preds = %9
%45 = load i32, i32* %7
%46 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %45)
ret i32 0
}

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