int calculate_sswc(int argc, char **argv) {
  int n_objects, n_attributes;
  float *dataset =
      read_dataset("../datasets/iris.csv", &n_objects, &n_attributes);
  int *medoids = randint(n_objects, 0, 1);
  medoids[49] = 1;
  medoids[99] = 1;
  medoids[149] = 1;
  float val = sswc(medoids, dataset, n_objects, n_attributes);
  printf("sswc: %f\n", val);
  free(medoids);
  free(dataset);
  return 0;
}


x86 assembly (clang, -O0):
<calculate_sswc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1060 <read_dataset@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x0,%al
call   1070 <randint@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x1,0xc4(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0x18c(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0x254(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    $0x0,%al
call   1030 <sswc@plt>
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe2b(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_sswc>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1060 <read_dataset@plt>
movslq %eax,%r14
mov    (%rsp),%edi
xor    %esi,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1070 <randint@plt>
movslq %eax,%rbx
movl   $0x1,0xc4(%rbx)
movl   $0x1,0x18c(%rbx)
movl   $0x1,0x254(%rbx)
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <sswc@plt>
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe53(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c"../datasets/iris.csv\00"
@.str.1 = [10 x i8] c"sswc: %f\0A\00"
define i32 @calculate_sswc(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca float*
%8 = alloca i32*
%9 = alloca float
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = call i32 (i8*, i32*, i32*, ...) bitcast (i32 (...)* @read_dataset to i32 (i8*, i32*, i32*, ...)*)(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6)
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to float*
store float* %12, float** %7
%13 = load i32, i32* %5
%14 = call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @randint to i32 (i32, i32, i32, ...)*)(i32 %13, i32 0, i32 1)
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %8
%17 = load i32*, i32** %8
%18 = getelementptr inbounds i32, i32* %17, i64 49
store i32 1, i32* %18
%19 = load i32*, i32** %8
%20 = getelementptr inbounds i32, i32* %19, i64 99
store i32 1, i32* %20
%21 = load i32*, i32** %8
%22 = getelementptr inbounds i32, i32* %21, i64 149
store i32 1, i32* %22
%23 = load i32*, i32** %8
%24 = load float*, float** %7
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = call i32 (i32*, float*, i32, i32, ...) bitcast (i32 (...)* @sswc to i32 (i32*, float*, i32, i32, ...)*)(i32* %23, float* %24, i32 %25, i32 %26)
%28 = sitofp i32 %27 to float
store float %28, float* %9
%29 = load float, float* %9
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %30)
%32 = load i32*, i32** %8
%33 = bitcast i32* %32 to i8*
%34 = load float*, float** %7
%35 = bitcast float* %34 to i8*
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"../datasets/iris.csv\00"
@.str.1 = [10 x i8] c"sswc: %f\0A\00"
define i32 @calculate_sswc(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 (i8*, i32*, i32*, ...) bitcast (i32 (...)* @read_dataset to i32 (i8*, i32*, i32*, ...)*)(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to float*
%10 = load i32, i32* %3
%11 = call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @randint to i32 (i32, i32, i32, ...)*)(i32 %10, i32 0, i32 1)
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = getelementptr inbounds i32, i32* %13, i64 49
store i32 1, i32* %14
%15 = getelementptr inbounds i32, i32* %13, i64 99
store i32 1, i32* %15
%16 = getelementptr inbounds i32, i32* %13, i64 149
store i32 1, i32* %16
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = call i32 (i32*, float*, i32, i32, ...) bitcast (i32 (...)* @sswc to i32 (i32*, float*, i32, i32, ...)*)(i32* %13, float* %9, i32 %17, i32 %18)
%20 = sitofp i32 %19 to float
%21 = fpext float %20 to double
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %21)
%23 = inttoptr i64 %12 to i8*
%24 = inttoptr i64 %8 to i8*
ret i32 0
}