#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 */
double CLOCKS_PER_SEC;
double clock();
scalar_t__ factorial(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  double start, end;
  unsigned int temp = 0, position = 0, total = 0;
  printf("Algorithm starts, please wait...\n");
  start = clock();
  for (unsigned int i = 3; i < 50000; i++) {
    temp = i;
    position = 0;
    do {
      position += factorial(temp % 10);
      if (position > i) {
        break;
      }
      temp /= 10;
    } while (temp != 0);
    if (position == i) {
      total += i;
    }
  }
  end = clock();
  printf("Algorithm end.\n");
  printf("Total time: %f\n", (end - start) / CLOCKS_PER_SEC);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x3,-0x30(%rbp)
cmpl   $0xc350,-0x30(%rbp)
jae    1207 <main+0xd7>
mov    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%edi
call   1030 <factorial@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x30(%rbp),%eax
jbe    11c6 <main+0x96>
jmp    11df <main+0xaf>
mov    -0x24(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1196 <main+0x66>
mov    -0x28(%rbp),%eax
cmp    -0x30(%rbp),%eax
jne    11f4 <main+0xc4>
mov    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    11f9 <main+0xc9>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    117c <main+0x4c>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x20(%rbp)
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    0x2db6(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdf5(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x3,%r15d
mov    $0xcccccccd,%r14d
jmp    118d <main+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15d
cmp    $0xc350,%r15d
je     11d1 <main+0x91>
mov    %r15d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%ebp
imul   %r14,%rbp
shr    $0x23,%rbp
lea    0x0(%rbp,%rbp,1),%eax
lea    (%rax,%rax,4),%eax
mov    %r12d,%edi
sub    %eax,%edi
call   1040 <factorial@plt>
mov    %ebx,%ebx
add    %rax,%rbx
cmp    %ebx,%r15d
jb     1180 <main+0x40>
cmp    $0x9,%r12d
mov    %ebp,%r12d
ja     11a0 <main+0x60>
jmp    1180 <main+0x40>
xor    %eax,%eax
call   1050 <clock@plt>
movsd  %xmm0,(%rsp)
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
mov    0x2ded(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdfa(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Algorithm starts, please wait...\0A\00"
@.str.1 = [16 x i8] c"Algorithm end.\0A\00"
@.str.2 = [16 x i8] c"Total time: %f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%13 = call double (...) @clock()
store double %13, double* %6
store i32 3, i32* %11
br label %14
14: ; preds = %46, %2
%15 = load i32, i32* %11
%16 = icmp ult i32 %15, 50000
br i1 %16, label %17, label %49
17: ; preds = %14
%18 = load i32, i32* %11
store i32 %18, i32* %8
store i32 0, i32* %9
br label %19
19: ; preds = %34, %17
%20 = load i32, i32* %8
%21 = urem i32 %20, 10
%22 = call i64 @factorial(i32 %21)
%23 = load i32, i32* %9
%24 = zext i32 %23 to i64
%25 = add nsw i64 %24, %22
%26 = trunc i64 %25 to i32
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = load i32, i32* %11
%29 = icmp ugt i32 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %19
br label %37
31: ; preds = %19
%32 = load i32, i32* %8
%33 = udiv i32 %32, 10
store i32 %33, i32* %8
br label %34
34: ; preds = %31
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 0
br i1 %36, label %19, label %37
37: ; preds = %34, %30
%38 = load i32, i32* %9
%39 = load i32, i32* %11
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* %11
%43 = load i32, i32* %10
%44 = add i32 %43, %42
store i32 %44, i32* %10
br label %45
45: ; preds = %41, %37
br label %46
46: ; preds = %45
%47 = load i32, i32* %11
%48 = add i32 %47, 1
store i32 %48, i32* %11
br label %14
49: ; preds = %14
%50 = call double (...) @clock()
store double %50, double* %7
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%52 = load double, double* %7
%53 = load double, double* %6
%54 = fsub double %52, %53
%55 = load double, double* @CLOCKS_PER_SEC
%56 = fdiv double %54, %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %56)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [16 x i8] c"Total time: %f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@str = [33 x i8] c"Algorithm starts, please wait...\00"
@str.3 = [15 x i8] c"Algorithm end.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%4 = tail call double (...) @clock()
br label %5
5: ; preds = %2, %26
%6 = phi i32 [ 3, %2 ], [ %27, %26 ]
br label %14
7: ; preds = %26
%8 = tail call double (...) @clock()
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.3, i64 0, i64 0))
%10 = fsub double %8, %4
%11 = load double, double* @CLOCKS_PER_SEC
%12 = fdiv double %10, %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %12)
ret i32 0
14: ; preds = %5, %14
%15 = phi i32 [ %23, %14 ], [ %6, %5 ]
%16 = phi i64 [ %20, %14 ], [ 0, %5 ]
%17 = urem i32 %15, 10
%18 = tail call i64 @factorial(i32 %17)
%19 = and i64 %16, 4294967295
%20 = add nsw i64 %19, %18
%21 = trunc i64 %20 to i32
%22 = icmp ult i32 %6, %21
%23 = udiv i32 %15, 10
%24 = icmp ult i32 %15, 10
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %26, label %14
26: ; preds = %14
%27 = add nuw nsw i32 %6, 1
%28 = icmp eq i32 %27, 50000
br i1 %28, label %7, label %5
}