#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 /*<<< orphan*/ printf(char *, int);
int sum_proper_divisors(int);
int Problem021(void) {
  int sum = 0, a, b;
  for (a = 2; a < 10000; a++) {
    b = sum_proper_divisors(a);
    if (sum_proper_divisors(b) == a && a < b) {
      sum += a + b;
    }
  }
  printf("%30d", sum);
  return 0;
}


x86 assembly (clang, -O0):
<Problem021>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jge    118a <Problem021+0x6a>
mov    -0x8(%rbp),%edi
call   1040 <sum_proper_divisors@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <sum_proper_divisors@plt>
cmp    -0x8(%rbp),%eax
jne    1177 <Problem021+0x57>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1177 <Problem021+0x57>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117c <Problem021+0x5c>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <Problem021+0x16>
mov    -0x4(%rbp),%esi
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Problem021>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x2,%ebx
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    1156 <Problem021+0x36>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
cmp    %r14d,%ebx
cmovge %r15d,%eax
add    %eax,%ebp
add    $0x1,%ebx
cmp    $0x2710,%ebx
je     1171 <Problem021+0x51>
mov    %ebx,%edi
call   1040 <sum_proper_divisors@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1040 <sum_proper_divisors@plt>
cmp    %eax,%ebx
jne    1140 <Problem021+0x20>
lea    (%r14,%rbx,1),%eax
jmp    1142 <Problem021+0x22>
lea    0xe88(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%30d\00"
define i32 @Problem021() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %11, %1 ]
%3 = phi i32 [ 2, %0 ], [ %12, %1 ]
%4 = tail call i32 @sum_proper_divisors(i32 %3)
%5 = tail call i32 @sum_proper_divisors(i32 %4)
%6 = icmp eq i32 %5, %3
%7 = icmp slt i32 %3, %4
%8 = and i1 %7, %6
%9 = add nsw i32 %4, %3
%10 = select i1 %8, i32 %9, i32 0
%11 = add nsw i32 %10, %2
%12 = add nuw nsw i32 %3, 1
%13 = icmp eq i32 %12, 10000
br i1 %13, label %14, label %1
14: ; preds = %1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i32 0
}