#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();
unsigned int d(unsigned int);
int pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  double start, end;
  unsigned int summatory = 0, temp = 0;
  printf("Algorithm starts, please wait...\n");
  start = clock();
  for (unsigned int i = 1; i < (int)(1 * pow(10, 4)); i++) {
    temp = d(i);
    if (d(temp) == i && i != temp)
      summatory += 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)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    $0xa,%edi
mov    $0x4,%esi
call   1060 <pow@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
shl    $0x0,%ecx
cmp    %ecx,%eax
jae    11ee <main+0xae>
mov    -0x2c(%rbp),%edi
call   1030 <d@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1030 <d@plt>
cmp    -0x2c(%rbp),%eax
jne    11db <main+0x9b>
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     11db <main+0x9b>
mov    -0x2c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11e0 <main+0xa0>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1185 <main+0x45>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x20(%rbp)
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    0x2dcf(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe0e(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xa,%edi
mov    $0x4,%esi
call   1070 <pow@plt>
cmp    $0x2,%eax
jb     11b4 <main+0x64>
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <d@plt>
mov    %eax,%edi
call   1040 <d@plt>
add    $0x1,%ebx
mov    $0xa,%edi
mov    $0x4,%esi
call   1070 <pow@plt>
cmp    %eax,%ebx
jb     1190 <main+0x40>
xor    %eax,%eax
call   1050 <clock@plt>
movsd  %xmm0,(%rsp)
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
mov    0x2e0a(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe17(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
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
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
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%12 = call double (...) @clock()
store double %12, double* %6
store i32 1, i32* %10
br label %13
13: ; preds = %34, %2
%14 = load i32, i32* %10
%15 = call i32 @pow(i32 10, i32 4)
%16 = mul nsw i32 1, %15
%17 = icmp ult i32 %14, %16
br i1 %17, label %18, label %37
18: ; preds = %13
%19 = load i32, i32* %10
%20 = call i32 @d(i32 %19)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = call i32 @d(i32 %21)
%23 = load i32, i32* %10
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %18
%26 = load i32, i32* %10
%27 = load i32, i32* %9
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* %10
%31 = load i32, i32* %8
%32 = add i32 %31, %30
store i32 %32, i32* %8
br label %33
33: ; preds = %29, %25, %18
br label %34
34: ; preds = %33
%35 = load i32, i32* %10
%36 = add i32 %35, 1
store i32 %36, i32* %10
br label %13
37: ; preds = %13
%38 = call double (...) @clock()
store double %38, double* %7
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%40 = load double, double* %7
%41 = load double, double* %6
%42 = fsub double %40, %41
%43 = load double, double* @CLOCKS_PER_SEC
%44 = fdiv double %42, %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %44)
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()
%5 = tail call i32 @pow(i32 10, i32 4)
%6 = icmp ugt i32 %5, 1
br i1 %6, label %14, label %7
7: ; preds = %14, %2
%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 = %2, %14
%15 = phi i32 [ %18, %14 ], [ 1, %2 ]
%16 = tail call i32 @d(i32 %15)
%17 = tail call i32 @d(i32 %16)
%18 = add nuw i32 %15, 1
%19 = tail call i32 @pow(i32 10, i32 4)
%20 = icmp ult i32 %18, %19
br i1 %20, label %14, label %7
}