#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*/ free(int *);
int *in_binary(int, int *);
scalar_t__ is_palindrome_bin(int *);
scalar_t__ is_palindrome_n(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ print_binary(int *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int n, sum = 0;
  bool *binary = (bool *)malloc(32 * sizeof(bool));
  for (n = 1; n < 1000000; n++) {
    if (is_palindrome_n(n)) {
      binary = in_binary(n, binary);
      if (is_palindrome_bin(binary)) {
        printf("%d: ", n);
        print_binary(binary);
        sum += n;
      }
    }
  }
  printf("\nsum: %d\n", sum);
  free(binary);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x80,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0xf4240,-0x8(%rbp)
jge    1216 <main+0xa6>
mov    -0x8(%rbp),%edi
call   1050 <is_palindrome_n@plt>
cmp    $0x0,%rax
je     1203 <main+0x93>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1080 <in_binary@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <is_palindrome_bin@plt>
cmp    $0x0,%rax
je     11fe <main+0x8e>
mov    -0x8(%rbp),%esi
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <print_binary@plt>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1203 <main+0x93>
jmp    1208 <main+0x98>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119b <main+0x2b>
mov    -0xc(%rbp),%esi
lea    0xde5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x80,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x1,%ebp
xor    %r14d,%r14d
lea    0xe6d(%rip),%r15
jmp    11ab <main+0x3b>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
cmp    $0xf4240,%ebp
je     11e8 <main+0x78>
mov    %ebp,%edi
call   1050 <is_palindrome_n@plt>
test   %rax,%rax
je     11a0 <main+0x30>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <in_binary@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <is_palindrome_bin@plt>
test   %rax,%rax
je     11a0 <main+0x30>
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <print_binary@plt>
add    %ebp,%r14d
jmp    11a0 <main+0x30>
lea    0xe16(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%d: \00"
@.str.1 = [10 x i8] c"\0Asum: %d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 128)
%2 = inttoptr i64 %1 to i32*
br label %3
3: ; preds = %0, %17
%4 = phi i32* [ %2, %0 ], [ %19, %17 ]
%5 = phi i32 [ 0, %0 ], [ %18, %17 ]
%6 = phi i32 [ 1, %0 ], [ %20, %17 ]
%7 = tail call i64 @is_palindrome_n(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %3
%10 = tail call i32* @in_binary(i32 %6, i32* %4)
%11 = tail call i64 @is_palindrome_bin(i32* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
%15 = tail call i32 @print_binary(i32* %10)
%16 = add nsw i32 %5, %6
br label %17
17: ; preds = %3, %13, %9
%18 = phi i32 [ %16, %13 ], [ %5, %9 ], [ %5, %3 ]
%19 = phi i32* [ %10, %13 ], [ %10, %9 ], [ %4, %3 ]
%20 = add nuw nsw i32 %6, 1
%21 = icmp eq i32 %20, 1000000
br i1 %21, label %22, label %3
22: ; preds = %17
%23 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%24 = tail call i32 @free(i32* %19)
ret i32 0
}