#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 next_digits_factorial_num(int);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  int lowest_pow10 = 10;
  int max_representable = 362880;
  while (lowest_pow10 <= max_representable) {
    lowest_pow10 *= 10;
    max_representable += 362880;
  }
  int sum = 0;
  for (int i = 10; i <= max_representable; i++)
    if (i == next_digits_factorial_num(i))
      sum += i;
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movl   $0x58980,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1160 <main+0x40>
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x58980,%eax
mov    %eax,-0xc(%rbp)
jmp    113d <main+0x1d>
movl   $0x0,-0x10(%rbp)
movl   $0xa,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11b1 <main+0x91>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <next_digits_factorial_num@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jne    119e <main+0x7e>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11a3 <main+0x83>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116e <main+0x4e>
mov    -0x10(%rbp),%esi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0xa,%eax
mov    $0x58977,%ebx
xchg   %ax,%ax
mov    %ebx,%ecx
add    %eax,%eax
lea    (%rax,%rax,4),%eax
lea    0x58980(%rcx),%ebx
add    $0x58989,%ecx
cmp    %ecx,%eax
jbe    1130 <main+0x10>
xor    %r14d,%r14d
mov    $0xa,%ebp
jmp    116b <main+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ecx,%r14d
add    $0x1,%ebp
add    $0xffffffff,%ebx
je     117c <main+0x5c>
mov    %ebp,%edi
call   1040 <next_digits_factorial_num@plt>
mov    %ebp,%ecx
cmp    %eax,%ebp
je     1160 <main+0x40>
xor    %ecx,%ecx
jmp    1160 <main+0x40>
lea    0xe7d(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %2
store i32 362880, i32* %3
br label %6
6: ; preds = %10, %0
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = icmp sle i32 %7, %8
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* %2
%12 = mul nsw i32 %11, 10
store i32 %12, i32* %2
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 362880
store i32 %14, i32* %3
br label %6
15: ; preds = %6
store i32 0, i32* %4
store i32 10, i32* %5
br label %16
16: ; preds = %30, %15
%17 = load i32, i32* %5
%18 = load i32, i32* %3
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load i32, i32* %5
%22 = load i32, i32* %5
%23 = call i32 @next_digits_factorial_num(i32 %22)
%24 = icmp eq i32 %21, %23
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* %5
%27 = load i32, i32* %4
%28 = add nsw i32 %27, %26
store i32 %28, i32* %4
br label %29
29: ; preds = %25, %20
br label %30
30: ; preds = %29
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %16
33: ; preds = %16
%34 = load i32, i32* %4
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
br label %3
1: ; preds = %3
%2 = add nuw nsw i32 %4, 362880
br label %11
3: ; preds = %0, %3
%4 = phi i32 [ 362880, %0 ], [ %7, %3 ]
%5 = phi i32 [ 10, %0 ], [ %6, %3 ]
%6 = mul nsw i32 %5, 10
%7 = add nuw nsw i32 %4, 362880
%8 = icmp ugt i32 %6, %7
br i1 %8, label %1, label %3
9: ; preds = %11
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
ret i32 0
11: ; preds = %1, %11
%12 = phi i32 [ 10, %1 ], [ %18, %11 ]
%13 = phi i32 [ 0, %1 ], [ %17, %11 ]
%14 = tail call i32 @next_digits_factorial_num(i32 %12)
%15 = icmp eq i32 %12, %14
%16 = select i1 %15, i32 %12, i32 0
%17 = add nuw nsw i32 %16, %13
%18 = add nuw i32 %12, 1
%19 = icmp eq i32 %12, %2
br i1 %19, label %9, label %11
}