#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 */
char *intToString(int, int);
int isPalindromic(int);
int /*<<< orphan*/ printf(char *, ...);
void problem36() {
  int i, sum = 0;
  for (i = 1; i < 1000000; i++) {
    if (i == 3)
      printf("%d\t \n", isPalindromic(3));
    if (isPalindromic(i)) {
      if (i == 3)
        printf("adding\n");
      printf("Decimal: %d\tBinary: %s\n", i, intToString(i, 2));
      sum += i;
      if (i == 3)
        printf("added\n");
    }
  }
  printf("\nSum of all numbers, less than one million, which are palindromic "
         "in base 10 and base 2 == %d\n",
         sum);
  printf("\nisPalindromic: %d\n", isPalindromic(3));
}


x86 assembly (clang, -O0):
<problem36>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0x4(%rbp)
cmpl   $0xf4240,-0x4(%rbp)
jge    1200 <problem36+0xd0>
cmpl   $0x3,-0x4(%rbp)
jne    1177 <problem36+0x47>
mov    $0x3,%edi
call   1050 <isPalindromic@plt>
mov    %eax,%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <isPalindromic@plt>
cmp    $0x0,%eax
je     11ed <problem36+0xbd>
cmpl   $0x3,-0x4(%rbp)
jne    11a0 <problem36+0x70>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x2,%esi
call   1040 <intToString@plt>
mov    -0xc(%rbp),%esi
mov    %rax,%rdx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x3,-0x4(%rbp)
jne    11e8 <problem36+0xb8>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ed <problem36+0xbd>
jmp    11f2 <problem36+0xc2>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1146 <problem36+0x16>
mov    -0x8(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3,%edi
call   1050 <isPalindromic@plt>
mov    %eax,%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<problem36>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%ebx
mov    $0x1,%edi
call   1060 <isPalindromic@plt>
test   %eax,%eax
je     117e <problem36+0x3e>
mov    $0x1,%edi
mov    $0x2,%esi
call   1050 <intToString@plt>
lea    0xe99(%rip),%rdi
mov    $0x1,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1180 <problem36+0x40>
xor    %ebx,%ebx
mov    $0x2,%edi
call   1060 <isPalindromic@plt>
test   %eax,%eax
je     11b6 <problem36+0x76>
mov    $0x2,%edi
mov    $0x2,%esi
call   1050 <intToString@plt>
lea    0xe62(%rip),%rdi
mov    $0x2,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
or     $0x2,%ebx
mov    $0x3,%edi
call   1060 <isPalindromic@plt>
lea    0xe39(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3,%edi
call   1060 <isPalindromic@plt>
test   %eax,%eax
je     121e <problem36+0xde>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
mov    $0x2,%esi
call   1050 <intToString@plt>
lea    0xe06(%rip),%rdi
mov    $0x3,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x3,%ebx
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
mov    $0x4,%ebp
lea    0xddc(%rip),%r14
jmp    123b <problem36+0xfb>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0xf4240,%ebp
je     1265 <problem36+0x125>
mov    %ebp,%edi
call   1060 <isPalindromic@plt>
test   %eax,%eax
je     1230 <problem36+0xf0>
mov    %ebp,%edi
mov    $0x2,%esi
call   1050 <intToString@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    %ebp,%ebx
jmp    1230 <problem36+0xf0>
lea    0xdb2(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3,%edi
call   1060 <isPalindromic@plt>
lea    0xdf7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%d\09 \0A\00"
@.str.1 = [8 x i8] c"adding\0A\00"
@.str.2 = [24 x i8] c"Decimal: %d\09Binary: %s\0A\00"
@.str.3 = [7 x i8] c"added\0A\00"
@.str.4 = [95 x i8] c"\0ASum of all numbers, less than one million, which are palindromic in base 10 and base 2 == %d\0A\00"
@.str.5 = [20 x i8] c"\0AisPalindromic: %d\0A\00"
define void @problem36() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
store i32 1, i32* %1
br label %3
3: ; preds = %35, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 1000000
br i1 %5, label %6, label %38
6: ; preds = %3
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 3
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = call i32 @isPalindromic(i32 3)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %9, %6
%13 = load i32, i32* %1
%14 = call i32 @isPalindromic(i32 %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, 3
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = load i32, i32* %1
%23 = load i32, i32* %1
%24 = call i8* @intToString(i32 %23, i32 2)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %22, i8* %24)
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = add nsw i32 %27, %26
store i32 %28, i32* %2
%29 = load i32, i32* %1
%30 = icmp eq i32 %29, 3
br i1 %30, label %31, label %33
31: ; preds = %21
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %21
br label %34
34: ; preds = %33, %12
br label %35
35: ; preds = %34
%36 = load i32, i32* %1
%37 = add nsw i32 %36, 1
store i32 %37, i32* %1
br label %3
38: ; preds = %3
%39 = load i32, i32* %2
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.4, i64 0, i64 0), i32 %39)
%41 = call i32 @isPalindromic(i32 3)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %41)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d\09 \0A\00"
@.str.2 = [24 x i8] c"Decimal: %d\09Binary: %s\0A\00"
@.str.4 = [95 x i8] c"\0ASum of all numbers, less than one million, which are palindromic in base 10 and base 2 == %d\0A\00"
@.str.5 = [20 x i8] c"\0AisPalindromic: %d\0A\00"
@str = [6 x i8] c"added\00"
@str.6 = [7 x i8] c"adding\00"
define void @problem36() {
%1 = tail call i32 @isPalindromic(i32 1)
%2 = icmp eq i32 %1, 0
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i8* @intToString(i32 1, i32 2)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 1, i8* %4)
br label %6
6: ; preds = %3, %0
%7 = phi i32 [ 1, %3 ], [ 0, %0 ]
%8 = tail call i32 @isPalindromic(i32 2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = tail call i8* @intToString(i32 2, i32 2)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 2, i8* %11)
%13 = or i32 %7, 2
br label %14
14: ; preds = %10, %6
%15 = phi i32 [ %13, %10 ], [ %7, %6 ]
%16 = tail call i32 @isPalindromic(i32 3)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = tail call i32 @isPalindromic(i32 3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %14
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.6, i64 0, i64 0))
%22 = tail call i8* @intToString(i32 3, i32 2)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 3, i8* %22)
%24 = add nuw nsw i32 %15, 3
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %14, %20
%27 = phi i32 [ %15, %14 ], [ %24, %20 ]
br label %28
28: ; preds = %26, %37
%29 = phi i32 [ %38, %37 ], [ %27, %26 ]
%30 = phi i32 [ %39, %37 ], [ 4, %26 ]
%31 = tail call i32 @isPalindromic(i32 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %28
%34 = tail call i8* @intToString(i32 %30, i32 2)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %30, i8* %34)
%36 = add nsw i32 %29, %30
br label %37
37: ; preds = %33, %28
%38 = phi i32 [ %36, %33 ], [ %29, %28 ]
%39 = add nuw nsw i32 %30, 1
%40 = icmp eq i32 %39, 1000000
br i1 %40, label %41, label %28
41: ; preds = %37
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([95 x i8], [95 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%43 = tail call i32 @isPalindromic(i32 3)
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %43)
ret void
}