#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 *calloc(int const, int);
int divisor_sum(int);
bool *gen_ab_table(const int size, int *n_ab) {
  bool *ab_table = calloc(size, sizeof(bool));
  for (int i = 2; i < size; ++i) {
    ab_table[i] = divisor_sum(i) > i;
    if (ab_table[i]) {
      ++(*n_ab);
    }
  }
  return ab_table;
}


x86 assembly (clang, -O0):
<gen_ab_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a1 <gen_ab_table+0x81>
mov    -0x1c(%rbp),%edi
call   1040 <divisor_sum@plt>
cmp    -0x1c(%rbp),%eax
setg   %al
and    $0x1,%al
movzbl %al,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     118e <gen_ab_table+0x6e>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1193 <gen_ab_table+0x73>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1147 <gen_ab_table+0x27>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_ab_table>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
cmp    $0x3,%ebx
jl     1176 <gen_ab_table+0x56>
mov    %ebx,%r12d
mov    $0x2,%ebx
jmp    1159 <gen_ab_table+0x39>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1176 <gen_ab_table+0x56>
mov    %ebx,%edi
call   1040 <divisor_sum@plt>
cltq
xor    %ecx,%ecx
cmp    %rax,%rbx
setl   %cl
mov    %ecx,(%r15,%rbx,4)
jge    1150 <gen_ab_table+0x30>
addl   $0x1,(%r14)
jmp    1150 <gen_ab_table+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @gen_ab_table(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%7 = load i32, i32* %3
%8 = call i32* @calloc(i32 %7, i32 4)
store i32* %8, i32** %5
store i32 2, i32* %6
br label %9
9: ; preds = %34, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %37
13: ; preds = %9
%14 = load i32, i32* %6
%15 = call i32 @divisor_sum(i32 %14)
%16 = load i32, i32* %6
%17 = icmp sgt i32 %15, %16
%18 = zext i1 %17 to i32
%19 = load i32*, i32** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
store i32 %18, i32* %22
%23 = load i32*, i32** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %13
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 1
store i32 %32, i32* %30
br label %33
33: ; preds = %29, %13
br label %34
34: ; preds = %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %9
37: ; preds = %9
%38 = load i32*, i32** %5
ret i32* %38
}

LLVM IR (-O2):
define noalias i32* @gen_ab_table(i32 %0, i32* nocapture %1) {
%3 = tail call i32* @calloc(i32 %0, i32 4)
%4 = icmp sgt i32 %0, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = zext i32 %0 to i64
br label %8
7: ; preds = %19, %2
ret i32* %3
8: ; preds = %5, %19
%9 = phi i64 [ 2, %5 ], [ %20, %19 ]
%10 = trunc i64 %9 to i32
%11 = tail call i32 @divisor_sum(i32 %10)
%12 = sext i32 %11 to i64
%13 = icmp slt i64 %9, %12
%14 = zext i1 %13 to i32
%15 = getelementptr inbounds i32, i32* %3, i64 %9
store i32 %14, i32* %15
br i1 %13, label %16, label %19
16: ; preds = %8
%17 = load i32, i32* %1
%18 = add nsw i32 %17, 1
store i32 %18, i32* %1
br label %19
19: ; preds = %8, %16
%20 = add nuw nsw i64 %9, 1
%21 = icmp eq i64 %20, %6
br i1 %21, label %7, label %8
}