#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 */
long atoi(int /*<<< orphan*/);
int /*<<< orphan*/ itoa(long, char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, long *);
int /*<<< orphan*/ strrev(char *);
int main() {
  int i;
  long k, rk;
  char str[100];
  scanf("%l", &k);
  for (i = 0; i < 1000; i++) {
    itoa(k, str, 10);
    rk = atoi(strrev(str));
    if (k == rk) {
      printf("%d", i);
      break;
    } else {
      k = k + rk;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    11ed <main+0x9d>
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0xa,%edx
call   1070 <itoa@plt>
lea    -0x80(%rbp),%rdi
call   1050 <strrev@plt>
mov    %eax,%edi
call   1060 <atoi@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11ce <main+0x7e>
mov    -0x8(%rbp),%esi
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
jmp    11ed <main+0x9d>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11df <main+0x8f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1179 <main+0x29>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
lea    0xea2(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
xor    %ebx,%ebx
mov    0x8(%rsp),%rdi
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rsi
mov    $0xa,%edx
call   1070 <itoa@plt>
mov    %r14,%rdi
call   1050 <strrev@plt>
mov    %eax,%edi
call   1060 <atoi@plt>
mov    0x8(%rsp),%rdi
cmp    %rax,%rdi
je     11bb <main+0x6b>
add    %rax,%rdi
mov    %rdi,0x8(%rsp)
add    $0x1,%ebx
cmp    $0x3e8,%ebx
jne    1180 <main+0x30>
jmp    11c9 <main+0x79>
lea    0xe41(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%l\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [100 x i8]
%3 = bitcast i64* %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64* %1)
%6 = load i64, i64* %1
br label %7
7: ; preds = %0, %17
%8 = phi i64 [ %6, %0 ], [ %18, %17 ]
%9 = phi i32 [ 0, %0 ], [ %19, %17 ]
%10 = call i32 @itoa(i64 %8, i8* %4, i32 10)
%11 = call i32 @strrev(i8* %4)
%12 = call i64 @atoi(i32 %11)
%13 = load i64, i64* %1
%14 = icmp eq i64 %13, %12
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %21
17: ; preds = %7
%18 = add nsw i64 %13, %12
store i64 %18, i64* %1
%19 = add nuw nsw i32 %9, 1
%20 = icmp eq i32 %19, 1000
br i1 %20, label %21, label %7
21: ; preds = %17, %15
ret i32 0
}