#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 squareSum(int);
int isHappy2(int n) {
  int slow = n, fast = n;
  while (slow > 1) {
    slow = squareSum(slow);
    if (slow == 1)
      return true;
    fast = squareSum(squareSum(fast));
    if (fast == 1)
      return true;
    if (slow == fast)
      return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<isHappy2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    1197 <isHappy2+0x87>
mov    -0xc(%rbp),%edi
call   1030 <squareSum@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1152 <isHappy2+0x42>
movl   $0x1,-0x4(%rbp)
jmp    119e <isHappy2+0x8e>
mov    -0x10(%rbp),%edi
call   1030 <squareSum@plt>
mov    %eax,%edi
call   1030 <squareSum@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    117a <isHappy2+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    119e <isHappy2+0x8e>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1192 <isHappy2+0x82>
movl   $0x0,-0x4(%rbp)
jmp    119e <isHappy2+0x8e>
jmp    1127 <isHappy2+0x17>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isHappy2>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    %edi,%ebp
mov    $0x1,%r14d
xchg   %ax,%ax
cmp    $0x2,%ebx
jl     114f <isHappy2+0x3f>
mov    %ebx,%edi
call   1030 <squareSum@plt>
cmp    $0x1,%eax
je     114f <isHappy2+0x3f>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <squareSum@plt>
mov    %eax,%edi
call   1030 <squareSum@plt>
cmp    $0x1,%eax
je     114f <isHappy2+0x3f>
mov    %eax,%ebp
cmp    %eax,%ebx
jne    1120 <isHappy2+0x10>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @isHappy2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
store i32 %6, i32* %4
%7 = load i32, i32* %3
store i32 %7, i32* %5
br label %8
8: ; preds = %29, %1
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %30
11: ; preds = %8
%12 = load i32, i32* %4
%13 = call i32 @squareSum(i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 1, i32* %2
br label %31
17: ; preds = %11
%18 = load i32, i32* %5
%19 = call i32 @squareSum(i32 %18)
%20 = call i32 @squareSum(i32 %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 1, i32* %2
br label %31
24: ; preds = %17
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 0, i32* %2
br label %31
29: ; preds = %24
br label %8
30: ; preds = %8
store i32 1, i32* %2
br label %31
31: ; preds = %30, %28, %23, %16
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
define i32 @isHappy2(i32 %0) {
br label %2
2: ; preds = %13, %1
%3 = phi i32 [ %0, %1 ], [ %7, %13 ]
%4 = phi i32 [ %0, %1 ], [ %11, %13 ]
%5 = icmp sgt i32 %3, 1
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = tail call i32 @squareSum(i32 %3)
%8 = icmp eq i32 %7, 1
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = tail call i32 @squareSum(i32 %4)
%11 = tail call i32 @squareSum(i32 %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = icmp eq i32 %7, %11
br i1 %14, label %15, label %2
15: ; preds = %2, %13, %9, %6
%16 = phi i32 [ 1, %6 ], [ 1, %9 ], [ 0, %13 ], [ 1, %2 ]
ret i32 %16
}