#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 squaresumdigits(int);
bool isHappy(int n) {
  int fast = n;
  int slow = n;
  do {
    fast = squaresumdigits(squaresumdigits(fast));
    slow = squaresumdigits(slow);
    if (slow == 1 || fast == 1)
      return true;
  } while (fast != slow);
  return false;
}


x86 assembly (clang, -O0):
<isHappy>:
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)
mov    -0xc(%rbp),%edi
call   1030 <squaresumdigits@plt>
mov    %eax,%edi
call   1030 <squaresumdigits@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <squaresumdigits@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
je     1158 <isHappy+0x48>
cmpl   $0x1,-0xc(%rbp)
jne    1164 <isHappy+0x54>
movl   $0x1,-0x4(%rbp)
jmp    117c <isHappy+0x6c>
jmp    1169 <isHappy+0x59>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1127 <isHappy+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isHappy>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %edi,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <squaresumdigits@plt>
mov    %eax,%edi
call   1030 <squaresumdigits@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <squaresumdigits@plt>
mov    %eax,%ebx
mov    $0x1,%eax
cmp    $0x1,%ebx
je     114e <isHappy+0x3e>
cmp    $0x1,%ebp
je     114e <isHappy+0x3e>
cmp    %ebx,%ebp
jne    1120 <isHappy+0x10>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @isHappy(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 = %21, %1
%9 = load i32, i32* %4
%10 = call i32 @squaresumdigits(i32 %9)
%11 = call i32 @squaresumdigits(i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %5
%13 = call i32 @squaresumdigits(i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 1
br i1 %15, label %19, label %16
16: ; preds = %8
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %16, %8
store i32 1, i32* %2
br label %26
20: ; preds = %16
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = icmp ne i32 %22, %23
br i1 %24, label %8, label %25
25: ; preds = %21
store i32 0, i32* %2
br label %26
26: ; preds = %25, %19
%27 = load i32, i32* %2
ret i32 %27
}

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