#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*/ exit(int);
long get_sum_of_proper_divisors(long);
int /*<<< orphan*/ printf(char *, long, long);
long get_amicable_sum(long n) {
  long amicable_pair;
  amicable_pair = get_sum_of_proper_divisors(n);
  if (amicable_pair < 0) {
    printf("Error occured while calculating sum of divisors of %ld (%ld)\n", n,
           amicable_pair);
    exit(1);
  }
  if (n != amicable_pair && get_sum_of_proper_divisors(amicable_pair) == n) {
    printf("%ld,%ld are amicable\n", n, amicable_pair);
    return (n + amicable_pair);
  } else
    return 0;
}


x86 assembly (clang, -O0):
<get_amicable_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <get_sum_of_proper_divisors@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1172 <get_amicable_sum+0x42>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11b8 <get_amicable_sum+0x88>
mov    -0x18(%rbp),%rdi
call   1030 <get_sum_of_proper_divisors@plt>
cmp    -0x10(%rbp),%rax
jne    11b8 <get_amicable_sum+0x88>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c0 <get_amicable_sum+0x90>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_amicable_sum>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <get_sum_of_proper_divisors@plt>
mov    %rax,%rbx
test   %rax,%rax
js     117a <get_amicable_sum+0x4a>
cmp    %r14,%rbx
je     116d <get_amicable_sum+0x3d>
mov    %rbx,%rdi
call   1030 <get_sum_of_proper_divisors@plt>
cmp    %r14,%rax
jne    116d <get_amicable_sum+0x3d>
lea    0xee1(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <printf@plt>
add    %r14,%rbx
jmp    116f <get_amicable_sum+0x3f>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe7f(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [62 x i8] c"Error occured while calculating sum of divisors of %ld (%ld)\0A\00"
@.str.1 = [22 x i8] c"%ld,%ld are amicable\0A\00"
define i64 @get_amicable_sum(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = call i64 @get_sum_of_proper_divisors(i64 %5)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i64, i64* %3
%11 = load i64, i64* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i64 %10, i64 %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = load i64, i64* %3
%16 = load i64, i64* %4
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %30
18: ; preds = %14
%19 = load i64, i64* %4
%20 = call i64 @get_sum_of_proper_divisors(i64 %19)
%21 = load i64, i64* %3
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = load i64, i64* %3
%25 = load i64, i64* %4
%26 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %24, i64 %25)
%27 = load i64, i64* %3
%28 = load i64, i64* %4
%29 = add nsw i64 %27, %28
store i64 %29, i64* %2
br label %31
30: ; preds = %18, %14
store i64 0, i64* %2
br label %31
31: ; preds = %30, %23
%32 = load i64, i64* %2
ret i64 %32
}

LLVM IR (-O2):
@.str = [62 x i8] c"Error occured while calculating sum of divisors of %ld (%ld)\0A\00"
@.str.1 = [22 x i8] c"%ld,%ld are amicable\0A\00"
define i64 @get_amicable_sum(i64 %0) {
%2 = tail call i64 @get_sum_of_proper_divisors(i64 %0)
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i64 %0, i64 %2)
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = icmp eq i64 %2, %0
br i1 %8, label %15, label %9
9: ; preds = %7
%10 = tail call i64 @get_sum_of_proper_divisors(i64 %2)
%11 = icmp eq i64 %10, %0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %0, i64 %2)
%14 = add nsw i64 %2, %0
br label %15
15: ; preds = %7, %9, %12
%16 = phi i64 [ %14, %12 ], [ 0, %9 ], [ 0, %7 ]
ret i64 %16
}