#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned long long *);
unsigned long long sumsq(unsigned long long);
int main() {
  int c = 0;
  unsigned long long int n;
  scanf("%llu", &n);
  while (n != 1 || n != 4) {
    if (n == 4) {
      printf("-1\n");
      break;
    }
    if (n == 1) {
      printf("%d", c);
      break;
    }
    n = sumsq(n);
    c++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x1,%al
cmpq   $0x1,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jne    1171 <main+0x41>
cmpq   $0x4,-0x10(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1181 <main+0x51>
jmp    11db <main+0xab>
cmpq   $0x4,-0x10(%rbp)
jne    119f <main+0x6f>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11db <main+0xab>
cmpq   $0x1,-0x10(%rbp)
jne    11c0 <main+0x90>
mov    -0x8(%rbp),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11db <main+0xab>
mov    -0x10(%rbp),%rdi
call   1030 <sumsq@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <main+0x26>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
xor    %ebx,%ebx
mov    0x8(%rsp),%rax
cmp    $0x1,%rax
je     118c <main+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x4,%rax
je     119e <main+0x5e>
mov    %rax,%rdi
call   1040 <sumsq@plt>
mov    %rax,0x8(%rsp)
add    $0x1,%ebx
cmp    $0x1,%rax
jne    1170 <main+0x30>
lea    0xe72(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11aa <main+0x6a>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%llu\00"
@.str.2 = [3 x i8] c"%d\00"
@str = [3 x i8] c"-1\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%4 = load i64, i64* %1
br label %5
5: ; preds = %12, %0
%6 = phi i64 [ %13, %12 ], [ %4, %0 ]
%7 = phi i32 [ %14, %12 ], [ 0, %0 ]
switch i64 %6, label %12 [
i64 4, label %8
i64 1, label %10
]
8: ; preds = %5
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %15
10: ; preds = %5
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %7)
br label %15
12: ; preds = %5
%13 = call i64 @sumsq(i64 %6)
store i64 %13, i64* %1
%14 = add nuw nsw i32 %7, 1
br label %5
15: ; preds = %10, %8
ret i32 0
}