#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 */
scalar_t__ get_factorial(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int);
bool is_curious(unsigned num) {
  unsigned tmp = num;
  unsigned f_sum = 0;
  while (tmp) {
    f_sum += get_factorial(tmp % 10);
    tmp /= 10;
  }
  if (f_sum == num) {
    printf("Curious number: %u\n", num);
    return true;
  }
  return false;
}


x86 assembly (clang, -O0):
<is_curious>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1175 <is_curious+0x55>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%edi
call   1040 <get_factorial@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
jmp    1138 <is_curious+0x18>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    119c <is_curious+0x7c>
mov    -0x8(%rbp),%esi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a3 <is_curious+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_curious>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
xor    %r14d,%r14d
mov    $0x0,%r13d
test   %edi,%edi
je     1174 <is_curious+0x54>
xor    %r13d,%r13d
mov    $0xcccccccd,%r12d
mov    %r15d,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%ebp
imul   %r12,%rbp
shr    $0x23,%rbp
lea    0x0(%rbp,%rbp,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebx,%edi
sub    %eax,%edi
call   1040 <get_factorial@plt>
add    %eax,%r13d
cmp    $0x9,%ebx
mov    %ebp,%ebx
ja     1150 <is_curious+0x30>
cmp    %r15d,%r13d
jne    118e <is_curious+0x6e>
lea    0xe80(%rip),%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Curious number: %u\0A\00"
define i32 @is_curious(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
store i32 0, i32* %5
br label %7
7: ; preds = %10, %1
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32, i32* %4
%12 = urem i32 %11, 10
%13 = call i64 @get_factorial(i32 %12)
%14 = load i32, i32* %5
%15 = zext i32 %14 to i64
%16 = add nsw i64 %15, %13
%17 = trunc i64 %16 to i32
store i32 %17, i32* %5
%18 = load i32, i32* %4
%19 = udiv i32 %18, 10
store i32 %19, i32* %4
br label %7
20: ; preds = %7
%21 = load i32, i32* %5
%22 = load i32, i32* %3
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %3
%26 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 1, i32* %2
br label %28
27: ; preds = %20
store i32 0, i32* %2
br label %28
28: ; preds = %27, %24
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [20 x i8] c"Curious number: %u\0A\00"
define i32 @is_curious(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %12, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %9, %3 ], [ 0, %1 ]
%5 = phi i32 [ %10, %3 ], [ %0, %1 ]
%6 = urem i32 %5, 10
%7 = tail call i64 @get_factorial(i32 %6)
%8 = trunc i64 %7 to i32
%9 = add i32 %4, %8
%10 = udiv i32 %5, 10
%11 = icmp ult i32 %5, 10
br i1 %11, label %12, label %3
12: ; preds = %3, %1
%13 = phi i32 [ 0, %1 ], [ %9, %3 ]
%14 = icmp eq i32 %13, %0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %17
17: ; preds = %12, %15
%18 = phi i32 [ 1, %15 ], [ 0, %12 ]
ret i32 %18
}