#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 */
struct timeval {
  int tv_usec;
};

/* Variables and functions */
int getSumDivisors(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  struct timeval stop, start;
  gettimeofday(&start, NULL);
  int i, sum, total = 0;
  for (i = 2; i <= 10000; i++) {
    sum = getSumDivisors(i);
    if (sum > i && getSumDivisors(sum) == i) {
      total += sum + i;
    }
  }
  printf("%d", total);
  gettimeofday(&stop, NULL);
  printf("\ntook %lu usec\n", stop.tv_usec - start.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x2,-0x14(%rbp)
cmpl   $0x2710,-0x14(%rbp)
jg     11ae <main+0x7e>
mov    -0x14(%rbp),%edi
call   1030 <getSumDivisors@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    119b <main+0x6b>
mov    -0x18(%rbp),%edi
call   1030 <getSumDivisors@plt>
cmp    -0x14(%rbp),%eax
jne    119b <main+0x6b>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11a0 <main+0x70>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115a <main+0x2a>
mov    -0x1c(%rbp),%esi
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x8(%rbp),%esi
sub    -0x10(%rbp),%esi
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %r14d,%r14d
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    $0x2,%ebp
jmp    115b <main+0x2b>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x2711,%ebp
je     117d <main+0x4d>
mov    %ebp,%edi
call   1030 <getSumDivisors@plt>
cmp    %ebp,%eax
jle    1150 <main+0x20>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <getSumDivisors@plt>
cmp    %eax,%ebp
jne    1150 <main+0x20>
add    %r14d,%ebx
add    %ebp,%ebx
mov    %ebx,%r14d
jmp    1150 <main+0x20>
lea    0xe7c(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x8(%rsp),%esi
sub    (%rsp),%esi
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [3 x i8] c"%d\00"
@.str.1 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %6
6: ; preds = %0, %17
%7 = phi i32 [ 0, %0 ], [ %18, %17 ]
%8 = phi i32 [ 2, %0 ], [ %19, %17 ]
%9 = tail call i32 @getSumDivisors(i32 %8)
%10 = icmp sgt i32 %9, %8
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = tail call i32 @getSumDivisors(i32 %9)
%13 = icmp eq i32 %12, %8
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = add i32 %7, %8
%16 = add i32 %15, %9
br label %17
17: ; preds = %6, %11, %14
%18 = phi i32 [ %16, %14 ], [ %7, %11 ], [ %7, %6 ]
%19 = add nuw nsw i32 %8, 1
%20 = icmp eq i32 %19, 10001
br i1 %20, label %21, label %6
21: ; preds = %17
%22 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %18)
%23 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%27 = load i32, i32* %26
%28 = sub nsw i32 %25, %27
%29 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %28)
ret i32 0
}