#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__ _mm_popcnt_u64(unsigned long long);
void computeCardinalities(unsigned long long int *differences,
                          int *cardIndvSets, int cardDiff, int setSize) {
  int i, j, offset;
#pragma omp parallel private(i, j, offset) if (cardDiff > CHUNKSIZE)           \
    num_threads(12)
  {
#pragma omp for schedule(dynamic, CHUNKSIZE) nowait
    for (i = 0; i < cardDiff; i++) {
      offset = i * setSize;
      cardIndvSets[i] = 0;
      for (j = offset; j < offset + setSize; j++) {
        cardIndvSets[i] += _mm_popcnt_u64(differences[j]);
      }
    }
  }
}


x86 assembly (clang, -O0):
<computeCardinalities>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b0 <computeCardinalities+0xa0>
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    119d <computeCardinalities+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <_mm_popcnt_u64@plt>
mov    %rax,%rsi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movslq (%rax,%rcx,4),%rdx
add    %rsi,%rdx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1158 <computeCardinalities+0x48>
jmp    11a2 <computeCardinalities+0x92>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <computeCardinalities+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computeCardinalities>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
jle    1199 <computeCardinalities+0x89>
mov    %rsi,%rbx
mov    %rdi,%r13
movslq %ecx,%rax
mov    %rax,0x8(%rsp)
mov    %edx,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
xor    %r12d,%r12d
mov    %ecx,0x4(%rsp)
jmp    1162 <computeCardinalities+0x52>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15
mov    0x4(%rsp),%ecx
add    %ecx,%r12d
cmp    0x10(%rsp),%r15
je     1199 <computeCardinalities+0x89>
movl   $0x0,(%rbx,%r15,4)
test   %ecx,%ecx
jle    1150 <computeCardinalities+0x40>
mov    %r15,%rbp
mov    0x8(%rsp),%rax
imul   %rax,%rbp
add    %rax,%rbp
movslq %r12d,%r14
mov    0x0(%r13,%r14,8),%rdi
call   1030 <_mm_popcnt_u64@plt>
add    %eax,(%rbx,%r15,4)
add    $0x1,%r14
cmp    %rbp,%r14
jl     1180 <computeCardinalities+0x70>
jmp    1150 <computeCardinalities+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @computeCardinalities(i64* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i64*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i64* %0, i64** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %12
12: ; preds = %50, %4
%13 = load i32, i32* %9
%14 = load i32, i32* %7
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %53
16: ; preds = %12
%17 = load i32, i32* %9
%18 = load i32, i32* %8
%19 = mul nsw i32 %17, %18
store i32 %19, i32* %11
%20 = load i32*, i32** %6
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 0, i32* %23
%24 = load i32, i32* %11
store i32 %24, i32* %10
br label %25
25: ; preds = %46, %16
%26 = load i32, i32* %10
%27 = load i32, i32* %11
%28 = load i32, i32* %8
%29 = add nsw i32 %27, %28
%30 = icmp slt i32 %26, %29
br i1 %30, label %31, label %49
31: ; preds = %25
%32 = load i64*, i64** %5
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i64, i64* %32, i64 %34
%36 = load i64, i64* %35
%37 = call i64 @_mm_popcnt_u64(i64 %36)
%38 = load i32*, i32** %6
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = sext i32 %42 to i64
%44 = add nsw i64 %43, %37
%45 = trunc i64 %44 to i32
store i32 %45, i32* %41
br label %46
46: ; preds = %31
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %25
49: ; preds = %25
br label %50
50: ; preds = %49
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %12
53: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @computeCardinalities(i64* nocapture %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %32
6: ; preds = %4
%7 = sext i32 %3 to i64
%8 = zext i32 %2 to i64
%9 = icmp sgt i32 %3, 0
br label %10
10: ; preds = %6, %28
%11 = phi i64 [ 0, %6 ], [ %29, %28 ]
%12 = phi i32 [ 0, %6 ], [ %30, %28 ]
%13 = mul nsw i64 %11, %7
%14 = getelementptr inbounds i32, i32* %1, i64 %11
store i32 0, i32* %14
%15 = add nsw i64 %13, %7
br i1 %9, label %16, label %28
16: ; preds = %10
%17 = sext i32 %12 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ %17, %16 ], [ %26, %18 ]
%20 = getelementptr inbounds i64, i64* %0, i64 %19
%21 = load i64, i64* %20
%22 = tail call i64 @_mm_popcnt_u64(i64 %21)
%23 = load i32, i32* %14
%24 = trunc i64 %22 to i32
%25 = add i32 %23, %24
store i32 %25, i32* %14
%26 = add nsw i64 %19, 1
%27 = icmp slt i64 %26, %15
br i1 %27, label %18, label %28
28: ; preds = %18, %10
%29 = add nuw nsw i64 %11, 1
%30 = add i32 %12, %3
%31 = icmp eq i64 %29, %8
br i1 %31, label %32, label %10
32: ; preds = %28, %4
ret void
}