#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 is_happy_cal(int);
unsigned char is_happy(int n) {
  if (n <= 0) {
    return 0;
  }
  int sum1, sum2, n1, n2;
  n1 = n2 = n;
  while (1) {
    sum1 = is_happy_cal(n1);
    sum2 = is_happy_cal(is_happy_cal(n2));
    if (sum1 == 1 || sum2 == 1) {
      break;
    }
    if (sum1 == sum2) {
      return 0;
    }
    n1 = sum1;
    n2 = sum2;
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_happy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     112e <is_happy+0x1e>
movb   $0x0,-0x1(%rbp)
jmp    1197 <is_happy+0x87>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <is_happy_cal@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <is_happy_cal@plt>
mov    %eax,%edi
call   1030 <is_happy_cal@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     1168 <is_happy+0x58>
cmpl   $0x1,-0x10(%rbp)
jne    116d <is_happy+0x5d>
jmp    1193 <is_happy+0x83>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1182 <is_happy+0x72>
movb   $0x0,-0x1(%rbp)
jmp    1197 <is_happy+0x87>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1137 <is_happy+0x27>
movb   $0x1,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_happy>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    1149 <is_happy+0x39>
mov    %edi,%ebx
mov    %edi,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <is_happy_cal@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <is_happy_cal@plt>
mov    %eax,%edi
call   1030 <is_happy_cal@plt>
mov    %eax,%ebp
mov    $0x1,%al
cmp    $0x1,%ebx
je     114b <is_happy+0x3b>
cmp    $0x1,%ebp
je     114b <is_happy+0x3b>
cmp    %ebp,%ebx
jne    1120 <is_happy+0x10>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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