#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
scalar_t__ mpz_palindrome(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_rotate_sum(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  mpz_t a;
  mpz_init(a);
  int lychrel_sum = 0;
  unsigned int i;
  for (i = 1; i < 10000; ++i) {
    mpz_set_ui(a, i);
    int j;
    for (j = 0; j < 50; ++j) {
      mpz_rotate_sum(a);
      if (mpz_palindrome(a))
        break;
    }
    if (j == 50)
      ++lychrel_sum;
  }
  printf("%d\n", lychrel_sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <mpz_init@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x2710,-0x10(%rbp)
jae    11f6 <main+0xa6>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1070 <mpz_set_ui@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x32,-0x14(%rbp)
jge    11d0 <main+0x80>
mov    -0x8(%rbp),%edi
call   1030 <mpz_rotate_sum@plt>
mov    -0x8(%rbp),%edi
call   1060 <mpz_palindrome@plt>
cmp    $0x0,%rax
je     11bd <main+0x6d>
jmp    11d0 <main+0x80>
jmp    11c2 <main+0x72>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1194 <main+0x44>
cmpl   $0x32,-0x14(%rbp)
jne    11e3 <main+0x93>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e8 <main+0x98>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1175 <main+0x25>
mov    -0xc(%rbp),%esi
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
call   1050 <mpz_init@plt>
xor    %r14d,%r14d
mov    $0x1,%ebp
jmp    1186 <main+0x36>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
cmp    $0x32,%ebx
sete   %al
add    %eax,%r14d
add    $0x1,%ebp
cmp    $0x2710,%ebp
je     11ae <main+0x5e>
mov    %ebp,%esi
call   1070 <mpz_set_ui@plt>
xor    %ebx,%ebx
nop
call   1030 <mpz_rotate_sum@plt>
call   1060 <mpz_palindrome@plt>
test   %rax,%rax
jne    1170 <main+0x20>
add    $0x1,%ebx
cmp    $0x32,%ebx
jne    1190 <main+0x40>
mov    $0x32,%ebx
jmp    1170 <main+0x20>
lea    0xe4b(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* %2
%7 = call i32 @mpz_init(i32 %6)
store i32 0, i32* %3
store i32 1, i32* %4
br label %8
8: ; preds = %36, %0
%9 = load i32, i32* %4
%10 = icmp ult i32 %9, 10000
br i1 %10, label %11, label %39
11: ; preds = %8
%12 = load i32, i32* %2
%13 = load i32, i32* %4
%14 = call i32 @mpz_set_ui(i32 %12, i32 %13)
store i32 0, i32* %5
br label %15
15: ; preds = %26, %11
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 50
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i32, i32* %2
%20 = call i32 @mpz_rotate_sum(i32 %19)
%21 = load i32, i32* %2
%22 = call i64 @mpz_palindrome(i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
br label %29
25: ; preds = %18
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %15
29: ; preds = %24, %15
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 50
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %35
35: ; preds = %32, %29
br label %36
36: ; preds = %35
%37 = load i32, i32* %4
%38 = add i32 %37, 1
store i32 %38, i32* %4
br label %8
39: ; preds = %8
%40 = load i32, i32* %3
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i32 @mpz_init(i32 undef)
br label %2
2: ; preds = %0, %14
%3 = phi i32 [ 1, %0 ], [ %19, %14 ]
%4 = phi i32 [ 0, %0 ], [ %18, %14 ]
%5 = tail call i32 @mpz_set_ui(i32 undef, i32 %3)
br label %6
6: ; preds = %2, %11
%7 = phi i32 [ 0, %2 ], [ %12, %11 ]
%8 = tail call i32 @mpz_rotate_sum(i32 undef)
%9 = tail call i64 @mpz_palindrome(i32 undef)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = add nuw nsw i32 %7, 1
%13 = icmp eq i32 %12, 50
br i1 %13, label %14, label %6
14: ; preds = %6, %11
%15 = phi i32 [ %7, %6 ], [ 50, %11 ]
%16 = icmp eq i32 %15, 50
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %4, %17
%19 = add nuw nsw i32 %3, 1
%20 = icmp eq i32 %19, 10000
br i1 %20, label %21, label %2
21: ; preds = %14
%22 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %18)
ret i32 0
}