#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*/ free(char *);
int /*<<< orphan*/ mpz_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
char *mpz_get_str(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_str(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ strcmp(char *, char *);
char *strrev(char *);
int main(int argc, char **argv) {
  mpz_t nn, x;
  char *s1, *s2;
  int n, i, m = 10000;
  mpz_init(x);
  mpz_init(nn);
  for (n = 0; n < 10000; n++) {
    mpz_set_ui(nn, n);
    s1 = mpz_get_str(NULL, 10, nn);
    s2 = strrev(s1);
    for (i = 0; i < 50; i++) {
      mpz_set_str(x, s2, 10);
      mpz_add(nn, nn, x);
      free(s1);
      free(s2);
      s1 = mpz_get_str(NULL, 10, nn);
      s2 = strrev(s1);
      if (strcmp(s1, s2) == 0) {
        free(s1);
        free(s2);
        m--;
        break;
      }
    }
  }
  printf("%d\n", m);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2710,-0x34(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x14(%rbp),%edi
call   1050 <mpz_init@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2710,-0x2c(%rbp)
jge    12bf <main+0x12f>
mov    -0x14(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   10a0 <mpz_set_ui@plt>
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa,%esi
call   1060 <mpz_get_str@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   10b0 <strrev@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x32,-0x30(%rbp)
jge    12ac <main+0x11c>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1090 <mpz_set_str@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1080 <mpz_add@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa,%esi
call   1060 <mpz_get_str@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   10b0 <strrev@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1299 <main+0x109>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    12ac <main+0x11c>
jmp    129e <main+0x10e>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1205 <main+0x75>
jmp    12b1 <main+0x121>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c4 <main+0x34>
mov    -0x34(%rbp),%esi
lea    0xd37(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
call   1050 <mpz_init@plt>
call   1050 <mpz_init@plt>
xor    %r15d,%r15d
mov    $0x2710,%r14d
jmp    11d5 <main+0x45>
nopl   (%rax)
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0xffffffff,%r14d
add    $0x1,%r15d
cmp    $0x2710,%r15d
je     125b <main+0xcb>
mov    %r15d,%esi
call   10a0 <mpz_set_ui@plt>
xor    %edi,%edi
mov    $0xa,%esi
call   1060 <mpz_get_str@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   10b0 <strrev@plt>
mov    %rax,%rbx
mov    $0x32,%r12d
nopl   (%rax)
mov    %rbx,%rsi
mov    $0xa,%edx
call   1090 <mpz_set_str@plt>
call   1080 <mpz_add@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    $0xa,%esi
call   1060 <mpz_get_str@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   10b0 <strrev@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11b0 <main+0x20>
add    $0xffffffff,%r12d
jne    1200 <main+0x70>
jmp    11c4 <main+0x34>
lea    0xd9e(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10000, i32* %12
%13 = load i32, i32* %7
%14 = call i32 @mpz_init(i32 %13)
%15 = load i32, i32* %6
%16 = call i32 @mpz_init(i32 %15)
store i32 0, i32* %10
br label %17
17: ; preds = %63, %2
%18 = load i32, i32* %10
%19 = icmp slt i32 %18, 10000
br i1 %19, label %20, label %66
20: ; preds = %17
%21 = load i32, i32* %6
%22 = load i32, i32* %10
%23 = call i32 @mpz_set_ui(i32 %21, i32 %22)
%24 = load i32, i32* %6
%25 = call i8* @mpz_get_str(i32* null, i32 10, i32 %24)
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = call i8* @strrev(i8* %26)
store i8* %27, i8** %9
store i32 0, i32* %11
br label %28
28: ; preds = %59, %20
%29 = load i32, i32* %11
%30 = icmp slt i32 %29, 50
br i1 %30, label %31, label %62
31: ; preds = %28
%32 = load i32, i32* %7
%33 = load i8*, i8** %9
%34 = call i32 @mpz_set_str(i32 %32, i8* %33, i32 10)
%35 = load i32, i32* %6
%36 = load i32, i32* %6
%37 = load i32, i32* %7
%38 = call i32 @mpz_add(i32 %35, i32 %36, i32 %37)
%39 = load i8*, i8** %8
%40 = call i32 @free(i8* %39)
%41 = load i8*, i8** %9
%42 = call i32 @free(i8* %41)
%43 = load i32, i32* %6
%44 = call i8* @mpz_get_str(i32* null, i32 10, i32 %43)
store i8* %44, i8** %8
%45 = load i8*, i8** %8
%46 = call i8* @strrev(i8* %45)
store i8* %46, i8** %9
%47 = load i8*, i8** %8
%48 = load i8*, i8** %9
%49 = call i64 @strcmp(i8* %47, i8* %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %58
51: ; preds = %31
%52 = load i8*, i8** %8
%53 = call i32 @free(i8* %52)
%54 = load i8*, i8** %9
%55 = call i32 @free(i8* %54)
%56 = load i32, i32* %12
%57 = add nsw i32 %56, -1
store i32 %57, i32* %12
br label %62
58: ; preds = %31
br label %59
59: ; preds = %58
%60 = load i32, i32* %11
%61 = add nsw i32 %60, 1
store i32 %61, i32* %11
br label %28
62: ; preds = %51, %28
br label %63
63: ; preds = %62
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
br label %17
66: ; preds = %17
%67 = load i32, i32* %12
%68 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %67)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32 @mpz_init(i32 undef)
br label %5
5: ; preds = %2, %30
%6 = phi i32 [ 10000, %2 ], [ %31, %30 ]
%7 = phi i32 [ 0, %2 ], [ %32, %30 ]
%8 = tail call i32 @mpz_set_ui(i32 undef, i32 %7)
%9 = tail call i8* @mpz_get_str(i32* null, i32 10, i32 undef)
%10 = tail call i8* @strrev(i8* %9)
br label %14
11: ; preds = %14
%12 = add nuw nsw i32 %15, 1
%13 = icmp eq i32 %12, 50
br i1 %13, label %30, label %14
14: ; preds = %5, %11
%15 = phi i32 [ 0, %5 ], [ %12, %11 ]
%16 = phi i8* [ %10, %5 ], [ %23, %11 ]
%17 = phi i8* [ %9, %5 ], [ %22, %11 ]
%18 = tail call i32 @mpz_set_str(i32 undef, i8* %16, i32 10)
%19 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%20 = tail call i32 @free(i8* %17)
%21 = tail call i32 @free(i8* %16)
%22 = tail call i8* @mpz_get_str(i32* null, i32 10, i32 undef)
%23 = tail call i8* @strrev(i8* %22)
%24 = tail call i64 @strcmp(i8* %22, i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %11
26: ; preds = %14
%27 = tail call i32 @free(i8* %22)
%28 = tail call i32 @free(i8* %23)
%29 = add nsw i32 %6, -1
br label %30
30: ; preds = %11, %26
%31 = phi i32 [ %29, %26 ], [ %6, %11 ]
%32 = add nuw nsw i32 %7, 1
%33 = icmp eq i32 %32, 10000
br i1 %33, label %34, label %5
34: ; preds = %30
%35 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %31)
ret i32 0
}