#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__ factorial(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int);
int main(int argc, char *argv[]) {
  unsigned int sum = 0;
  for (unsigned int i = 3; i < 99999; i++) {
    unsigned int fact_sum = 0;
    unsigned int j = i;
    while (j > 0) {
      fact_sum += factorial(j % 10);
      j /= 10;
    }
    if (i == fact_sum) {
      sum += i;
    }
  }
  printf("%u", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
cmpl   $0x1869f,-0x18(%rbp)
jae    11c3 <main+0xa3>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jbe    119b <main+0x7b>
mov    -0x20(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%edi
call   1030 <factorial@plt>
mov    %rax,%rcx
mov    -0x1c(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x20(%rbp)
jmp    115e <main+0x3e>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11b0 <main+0x90>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11b5 <main+0x95>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1144 <main+0x24>
mov    -0x14(%rbp),%esi
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
mov    $0x3,%r15d
mov    $0xcccccccd,%r12d
nopw   0x0(%rax,%rax,1)
mov    %r15d,%ebx
xor    %r13d,%r13d
cs 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   1030 <factorial@plt>
add    %eax,%r13d
cmp    $0x9,%ebx
mov    %ebp,%ebx
ja     1150 <main+0x30>
cmp    %r13d,%r15d
mov    $0x0,%eax
cmove  %r15d,%eax
add    %eax,%r14d
add    $0x1,%r15d
cmp    $0x1869f,%r15d
jne    1140 <main+0x20>
lea    0xe69(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 3, i32* %7
br label %10
10: ; preds = %37, %2
%11 = load i32, i32* %7
%12 = icmp ult i32 %11, 99999
br i1 %12, label %13, label %40
13: ; preds = %10
store i32 0, i32* %8
%14 = load i32, i32* %7
store i32 %14, i32* %9
br label %15
15: ; preds = %18, %13
%16 = load i32, i32* %9
%17 = icmp ugt i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i32, i32* %9
%20 = urem i32 %19, 10
%21 = call i64 @factorial(i32 %20)
%22 = load i32, i32* %8
%23 = zext i32 %22 to i64
%24 = add nsw i64 %23, %21
%25 = trunc i64 %24 to i32
store i32 %25, i32* %8
%26 = load i32, i32* %9
%27 = udiv i32 %26, 10
store i32 %27, i32* %9
br label %15
28: ; preds = %15
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = add i32 %34, %33
store i32 %35, i32* %6
br label %36
36: ; preds = %32, %28
br label %37
37: ; preds = %36
%38 = load i32, i32* %7
%39 = add i32 %38, 1
store i32 %39, i32* %7
br label %10
40: ; preds = %10
%41 = load i32, i32* %6
%42 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %41)
ret i32 0
}

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