#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 /*<<< orphan*/ scanf(char *, int *);
int vsotaDeljiteljev(int);
int main() {
  int meja;
  printf("Please insert upper bound:\n");
  scanf("%d", &meja);
  int tabela[meja];
  int n;
  for (n = 0; n < meja; n++) {
    tabela[n] = 0;
  }
  int i;
  int vsota = 0;
  for (i = 1; i < meja; i++) {
    int delitelji = vsotaDeljiteljev(i);
    if (i != delitelji && i == vsotaDeljiteljev(delitelji) && tabela[i] != 1) {
      vsota += i + delitelji;
      tabela[i] = 1;
      tabela[delitelji] = 1;
    }
  }
  if (vsota == 0) {
    printf("There are no amicable numbers below %d\n", meja);
    return 0;
  }
  printf("Sum of the amicable numbers below %d is:\n", meja);
  printf("%d\n", vsota);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b4 <main+0x84>
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118b <main+0x5b>
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    124b <main+0x11b>
mov    -0x20(%rbp),%edi
call   1050 <vsotaDeljiteljev@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     1238 <main+0x108>
mov    -0x20(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%edi
call   1050 <vsotaDeljiteljev@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jne    1238 <main+0x108>
mov    -0x38(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
je     1238 <main+0x108>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    -0x28(%rbp),%ecx
add    -0x24(%rbp),%ecx
mov    %ecx,-0x24(%rbp)
movslq -0x20(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
movslq -0x28(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    123d <main+0x10d>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c2 <main+0x92>
cmpl   $0x0,-0x24(%rbp)
jne    1279 <main+0x149>
mov    -0x8(%rbp),%esi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    12a9 <main+0x179>
mov    -0x8(%rbp),%esi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xef0(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8f(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <scanf@plt>
mov    %rsp,%r13
mov    -0x2c(%rbp),%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%r12d
test   %r12d,%r12d
jle    1241 <main+0xf1>
lea    0x0(,%r12,4),%rdx
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
cmp    $0x1,%r12d
mov    $0x1,%r12d
je     1241 <main+0xf1>
mov    $0x1,%ebx
jmp    11dd <main+0x8d>
xchg   %ax,%ax
add    $0x1,%rbx
movslq -0x2c(%rbp),%r12
cmp    %r12,%rbx
jge    121f <main+0xcf>
mov    %ebx,%edi
call   1070 <vsotaDeljiteljev@plt>
mov    %eax,%r12d
mov    %eax,%eax
cmp    %rax,%rbx
je     11d0 <main+0x80>
mov    %r12d,%edi
call   1070 <vsotaDeljiteljev@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jne    11d0 <main+0x80>
cmpl   $0x1,(%r15,%rbx,4)
je     11d0 <main+0x80>
add    %r12d,%r14d
add    %ebx,%r14d
movl   $0x1,(%r15,%rbx,4)
movslq %r12d,%rax
movl   $0x1,(%r15,%rax,4)
jmp    11d0 <main+0x80>
test   %r14d,%r14d
je     1241 <main+0xf1>
lea    0xe00(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdeb(%rip),%rdi
mov    %r14d,%esi
jmp    124b <main+0xfb>
lea    0xdbb(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Please insert upper bound:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"There are no amicable numbers below %d\0A\00"
@.str.3 = [42 x i8] c"Sum of the amicable numbers below %d is:\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = alloca i32, i64 %13
store i64 %13, i64* %4
store i32 0, i32* %5
br label %16
16: ; preds = %24, %0
%17 = load i32, i32* %5
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %15, i64 %22
store i32 0, i32* %23
br label %24
24: ; preds = %20
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %16
27: ; preds = %16
store i32 0, i32* %7
store i32 1, i32* %6
br label %28
28: ; preds = %62, %27
%29 = load i32, i32* %6
%30 = load i32, i32* %2
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %65
32: ; preds = %28
%33 = load i32, i32* %6
%34 = call i32 @vsotaDeljiteljev(i32 %33)
store i32 %34, i32* %8
%35 = load i32, i32* %6
%36 = load i32, i32* %8
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %61
38: ; preds = %32
%39 = load i32, i32* %6
%40 = load i32, i32* %8
%41 = call i32 @vsotaDeljiteljev(i32 %40)
%42 = icmp eq i32 %39, %41
br i1 %42, label %43, label %61
43: ; preds = %38
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %15, i64 %45
%47 = load i32, i32* %46
%48 = icmp ne i32 %47, 1
br i1 %48, label %49, label %61
49: ; preds = %43
%50 = load i32, i32* %6
%51 = load i32, i32* %8
%52 = add nsw i32 %50, %51
%53 = load i32, i32* %7
%54 = add nsw i32 %53, %52
store i32 %54, i32* %7
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %15, i64 %56
store i32 1, i32* %57
%58 = load i32, i32* %8
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %15, i64 %59
store i32 1, i32* %60
br label %61
61: ; preds = %49, %43, %38, %32
br label %62
62: ; preds = %61
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %28
65: ; preds = %28
%66 = load i32, i32* %7
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32, i32* %2
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %69)
store i32 0, i32* %1
store i32 1, i32* %9
br label %76
71: ; preds = %65
%72 = load i32, i32* %2
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %72)
%74 = load i32, i32* %7
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %74)
store i32 0, i32* %1
store i32 1, i32* %9
br label %76
76: ; preds = %71, %68
%77 = load i8*, i8** %3
%78 = load i32, i32* %1
ret i32 %78
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"There are no amicable numbers below %d\0A\00"
@.str.3 = [42 x i8] c"Sum of the amicable numbers below %d is:\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@str = [27 x i8] c"Please insert upper bound:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
%8 = alloca i32, i64 %6
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %44
11: ; preds = %0
%12 = bitcast i32* %8 to i8*
%13 = zext i32 %9 to i64
%14 = shl nuw nsw i64 %13, 2
%15 = icmp eq i32 %9, 1
br i1 %15, label %44, label %16
16: ; preds = %11, %36
%17 = phi i64 [ %38, %36 ], [ 1, %11 ]
%18 = phi i32 [ %37, %36 ], [ 0, %11 ]
%19 = trunc i64 %17 to i32
%20 = call i32 @vsotaDeljiteljev(i32 %19)
%21 = zext i32 %20 to i64
%22 = icmp eq i64 %17, %21
br i1 %22, label %36, label %23
23: ; preds = %16
%24 = call i32 @vsotaDeljiteljev(i32 %20)
%25 = zext i32 %24 to i64
%26 = icmp eq i64 %17, %25
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = getelementptr inbounds i32, i32* %8, i64 %17
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 1
br i1 %30, label %36, label %31
31: ; preds = %27
%32 = add i32 %18, %19
%33 = add i32 %32, %20
store i32 1, i32* %28
%34 = sext i32 %20 to i64
%35 = getelementptr inbounds i32, i32* %8, i64 %34
store i32 1, i32* %35
br label %36
36: ; preds = %31, %27, %23, %16
%37 = phi i32 [ %33, %31 ], [ %18, %27 ], [ %18, %23 ], [ %18, %16 ]
%38 = add nuw nsw i64 %17, 1
%39 = load i32, i32* %1
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %38, %40
br i1 %41, label %16, label %42
42: ; preds = %36
%43 = icmp eq i32 %37, 0
br i1 %43, label %44, label %47
44: ; preds = %0, %11, %42
%45 = phi i32 [ %39, %42 ], [ 1, %11 ], [ %9, %0 ]
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %45)
br label %50
47: ; preds = %42
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %50
50: ; preds = %47, %44
ret i32 0
}