#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(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int euler_problem_4() {
  int i, j, k, max = 0;
  char *str = (char *)malloc(sizeof(char) * 20);
  for (i = 100; i < 1000; ++i) {
    for (j = 100; j < 1000; ++j) {
      k = i * j;
      sprintf(str, "%d", k);
      if (is_palindrome(str) && k > max) {
        max = k;
      }
    }
  }
  return max;
}


x86 assembly (clang, -O0):
<euler_problem_4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x10(%rbp)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x64,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jge    11dd <euler_problem_4+0xad>
movl   $0x64,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    11ca <euler_problem_4+0x9a>
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe73(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <is_palindrome@plt>
cmp    $0x0,%rax
je     11b7 <euler_problem_4+0x87>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11b7 <euler_problem_4+0x87>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11bc <euler_problem_4+0x8c>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1168 <euler_problem_4+0x38>
jmp    11cf <euler_problem_4+0x9f>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1154 <euler_problem_4+0x24>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euler_problem_4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
mov    $0x64,%r12d
mov    $0x2710,%ebp
lea    0xea4(%rip),%r15
jmp    1174 <euler_problem_4+0x44>
xchg   %ax,%ax
add    $0x1,%r12d
mov    0x4(%rsp),%ebp
add    $0x64,%ebp
cmp    $0x3e8,%r12d
je     11ae <euler_problem_4+0x7e>
mov    $0x384,%r13d
mov    %ebp,0x4(%rsp)
jmp    118f <euler_problem_4+0x5f>
test   %rax,%rax
cmovne %ecx,%ebx
add    %r12d,%ebp
add    $0xffffffff,%r13d
je     1160 <euler_problem_4+0x30>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1030 <is_palindrome@plt>
mov    %ebp,%ecx
cmp    %ebx,%ebp
jg     1180 <euler_problem_4+0x50>
mov    %ebx,%ecx
jmp    1180 <euler_problem_4+0x50>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @euler_problem_4() {
%1 = tail call i64 @malloc(i32 20)
%2 = inttoptr i64 %1 to i8*
br label %3
3: ; preds = %0, %18
%4 = phi i32 [ 100, %0 ], [ %19, %18 ]
%5 = phi i32 [ 0, %0 ], [ %15, %18 ]
br label %6
6: ; preds = %3, %6
%7 = phi i32 [ %5, %3 ], [ %15, %6 ]
%8 = phi i32 [ 100, %3 ], [ %16, %6 ]
%9 = mul nuw nsw i32 %8, %4
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i64 @is_palindrome(i8* %2)
%12 = icmp ne i64 %11, 0
%13 = icmp sgt i32 %9, %7
%14 = select i1 %12, i1 %13, i1 false
%15 = select i1 %14, i32 %9, i32 %7
%16 = add nuw nsw i32 %8, 1
%17 = icmp eq i32 %16, 1000
br i1 %17, label %18, label %6
18: ; preds = %6
%19 = add nuw nsw i32 %4, 1
%20 = icmp eq i32 %19, 1000
br i1 %20, label %21, label %3
21: ; preds = %18
ret i32 %15
}