#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 */
scalar_t__ get_amicable_sum(long);
int /*<<< orphan*/ initialize_prime_stack();
int /*<<< orphan*/ printf(char *, long);
int main(int argc, char *argv[]) {
  initialize_prime_stack();
  long sum = 0;
  long i;
  for (i = 1; i <= 10000; i++) {
    sum += get_amicable_sum(i);
  }
  printf("Sum of all amicable pairs upto 10000 is %ld\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <initialize_prime_stack@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
cmpq   $0x2710,-0x20(%rbp)
jg     118d <main+0x5d>
mov    -0x20(%rbp),%rdi
call   1050 <get_amicable_sum@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115d <main+0x2d>
mov    -0x18(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <initialize_prime_stack@plt>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <get_amicable_sum@plt>
add    %rax,%r14
add    $0x1,%rbx
cmp    $0x2711,%rbx
jne    1150 <main+0x20>
lea    0xe91(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [45 x i8] c"Sum of all amicable pairs upto 10000 is %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @initialize_prime_stack()
store i64 0, i64* %6
store i64 1, i64* %7
br label %9
9: ; preds = %17, %2
%10 = load i64, i64* %7
%11 = icmp sle i64 %10, 10000
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i64, i64* %7
%14 = call i64 @get_amicable_sum(i64 %13)
%15 = load i64, i64* %6
%16 = add nsw i64 %15, %14
store i64 %16, i64* %6
br label %17
17: ; preds = %12
%18 = load i64, i64* %7
%19 = add nsw i64 %18, 1
store i64 %19, i64* %7
br label %9
20: ; preds = %9
%21 = load i64, i64* %6
%22 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i64 %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [45 x i8] c"Sum of all amicable pairs upto 10000 is %ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @initialize_prime_stack()
br label %4
4: ; preds = %2, %4
%5 = phi i64 [ 1, %2 ], [ %9, %4 ]
%6 = phi i64 [ 0, %2 ], [ %8, %4 ]
%7 = tail call i64 @get_amicable_sum(i64 %5)
%8 = add nsw i64 %7, %6
%9 = add nuw nsw i64 %5, 1
%10 = icmp eq i64 %9, 10001
br i1 %10, label %11, label %4
11: ; preds = %4
%12 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i64 %8)
ret i32 0
}