#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 palindrome(int, int);
int /*<<< orphan*/ printf(char *, ...);
int reverse(int, int *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int number = 12345;
  int digits, res, reversed, sum;
  printf("Insert number: \n");
  scanf("%d", &number);
  reversed = reverse(number, &digits);
  printf("Digits %d\n", digits);
  sum = number + reversed;
  printf("%d + %d = %d\n", number, reversed, sum);
  res = palindrome(sum, digits);
  if (res == 1) {
    printf("Lychrel number: %d.\n", number);
  } else {
    printf("Not a Lychrel number.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3039,-0x8(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1030 <reverse@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <palindrome@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    11e2 <main+0xa2>
mov    -0x8(%rbp),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f0 <main+0xb0>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
movl   $0x3039,(%rsp)
lea    0xed0(%rip),%rdi
call   1040 <puts@plt>
lea    0xe93(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%edi
lea    0x4(%rsp),%rsi
call   1030 <reverse@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%esi
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%esi
lea    (%rsi,%rbx,1),%ebp
lea    0xe6b(%rip),%rdi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %ebp,%edi
call   1060 <palindrome@plt>
cmp    $0x1,%eax
jne    11d1 <main+0x81>
mov    (%rsp),%esi
lea    0xe54(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11dd <main+0x8d>
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Insert number: \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"Digits %d\0A\00"
@.str.3 = [14 x i8] c"%d + %d = %d\0A\00"
@.str.4 = [21 x i8] c"Lychrel number: %d.\0A\00"
@.str.5 = [23 x i8] c"Not a Lychrel number.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 12345, i32* %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = call i32 @reverse(i32 %9, i32* %3)
store i32 %10, i32* %5
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %2
%14 = load i32, i32* %5
%15 = add nsw i32 %13, %14
store i32 %15, i32* %6
%16 = load i32, i32* %2
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
%20 = load i32, i32* %6
%21 = load i32, i32* %3
%22 = call i32 @palindrome(i32 %20, i32 %21)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %0
%26 = load i32, i32* %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %30
28: ; preds = %0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"Digits %d\0A\00"
@.str.3 = [14 x i8] c"%d + %d = %d\0A\00"
@.str.4 = [21 x i8] c"Lychrel number: %d.\0A\00"
@str = [16 x i8] c"Insert number: \00"
@str.6 = [22 x i8] c"Not a Lychrel number.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 12345, i32* %1
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i32 @reverse(i32 %7, i32* %2)
%9 = load i32, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %1
%12 = add nsw i32 %11, %8
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32 %8, i32 %12)
%14 = load i32, i32* %2
%15 = call i32 @palindrome(i32 %12, i32 %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = load i32, i32* %1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %18)
br label %22
20: ; preds = %0
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
ret i32 0
}