#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*/ count_digits(long);
int /*<<< orphan*/ printf(char *, int, long);
long reverse(long, int /*<<< orphan*/);
void palindrome(long n, long rev_n) {
  static int no_iterations = 0;
  if (n != rev_n) {
    n += rev_n;
    rev_n = reverse(n, count_digits(n));
    no_iterations++;
    palindrome(n, rev_n);
  } else {
    printf("%d %ld\n", no_iterations, n);
  }
  no_iterations = 0;
}


x86 assembly (clang, -O0):
<palindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11ab <palindrome+0x6b>
mov    -0x10(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <count_digits@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
call   1030 <reverse@plt>
mov    %rax,-0x10(%rbp)
mov    0x2eb4(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2eab(%rip)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <palindrome@plt>
jmp    11c1 <palindrome+0x81>
mov    0x2e93(%rip),%esi
mov    -0x8(%rbp),%rdx
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,0x2e79(%rip)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<palindrome>:
push   %rbx
mov    %rdi,%rdx
cmp    %rsi,%rdi
jne    115d <palindrome+0x1d>
mov    0x2ef5(%rip),%esi
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
jmp    1187 <palindrome+0x47>
mov    %rsi,%rbx
add    %rdx,%rbx
mov    %rbx,%rdi
call   1050 <count_digits@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <reverse@plt>
addl   $0x1,0x2ec8(%rip)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <palindrome@plt>
movl   $0x0,0x2eb3(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@palindrome.no_iterations = internal global i32 0
@.str = [8 x i8] c"%d %ld\0A\00"
define void @palindrome(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%5 = load i64, i64* %3
%6 = load i64, i64* %4
%7 = icmp ne i64 %5, %6
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = load i64, i64* %4
%10 = load i64, i64* %3
%11 = add nsw i64 %10, %9
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = load i64, i64* %3
%14 = call i32 @count_digits(i64 %13)
%15 = call i64 @reverse(i64 %12, i32 %14)
store i64 %15, i64* %4
%16 = load i32, i32* @palindrome.no_iterations
%17 = add nsw i32 %16, 1
store i32 %17, i32* @palindrome.no_iterations
%18 = load i64, i64* %3
%19 = load i64, i64* %4
br label %24
20: ; preds = %2
%21 = load i32, i32* @palindrome.no_iterations
%22 = load i64, i64* %3
%23 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %21, i64 %22)
br label %24
24: ; preds = %20, %8
store i32 0, i32* @palindrome.no_iterations
ret void
}

LLVM IR (-O2):
@palindrome.no_iterations = internal unnamed_addr global i32 0
@.str = [8 x i8] c"%d %ld\0A\00"
define void @palindrome(i64 %0, i64 %1) {
%3 = icmp eq i64 %0, %1
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = add nsw i64 %1, %0
%6 = tail call i32 @count_digits(i64 %5)
%7 = tail call i64 @reverse(i64 %5, i32 %6)
%8 = load i32, i32* @palindrome.no_iterations
%9 = add nsw i32 %8, 1
store i32 %9, i32* @palindrome.no_iterations
tail call void @palindrome(i64 %5, i64 %7)
br label %13
10: ; preds = %2
%11 = load i32, i32* @palindrome.no_iterations
%12 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %11, i64 %0)
br label %13
13: ; preds = %10, %4
store i32 0, i32* @palindrome.no_iterations
ret void
}