#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*/ free(double *);
int /*<<< orphan*/ getclustermeans(int, int, int, double **, int **, int *,
                                   double **, int **, int);
int /*<<< orphan*/ getclustermedians(int, int, int, double **, int **, int *,
                                     double **, int **, int, double *);
double *malloc(int const);
int getclustercentroids(int nclusters, int nrows, int ncolumns, double **data,
                        int **mask, int clusterid[], double **cdata,
                        int **cmask, int transpose, char method) {
  switch (method) {
  case 'm': {
    const int nelements = (transpose == 0) ? nrows : ncolumns;
    double *cache = malloc(nelements * sizeof(double));
    if (!cache)
      return 0;
    getclustermedians(nclusters, nrows, ncolumns, data, mask, clusterid, cdata,
                      cmask, transpose, cache);
    free(cache);
    return 1;
  }
  case 'a': {
    getclustermeans(nclusters, nrows, ncolumns, data, mask, clusterid, cdata,
                    cmask, transpose);
    return 1;
  }
  }
  return 0;
}


x86 assembly (clang, -O0):
<getclustercentroids>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
mov    0x28(%rbp),%al
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movsbl 0x28(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x61,%eax
je     122f <getclustercentroids+0xef>
jmp    1181 <getclustercentroids+0x41>
mov    -0x44(%rbp),%eax
sub    $0x6d,%eax
jne    126d <getclustercentroids+0x12d>
jmp    1192 <getclustercentroids+0x52>
cmpl   $0x0,0x20(%rbp)
jne    11a7 <getclustercentroids+0x67>
mov    -0x14(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    11ad <getclustercentroids+0x6d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11dd <getclustercentroids+0x9d>
movl   $0x0,-0xc(%rbp)
jmp    1274 <getclustercentroids+0x134>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    0x10(%rbp),%rbx
mov    0x18(%rbp),%r11
mov    0x20(%rbp),%r10d
mov    -0x40(%rbp),%rax
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1060 <getclustermedians@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0xc(%rbp)
jmp    1274 <getclustercentroids+0x134>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    0x10(%rbp),%r11
mov    0x18(%rbp),%r10
mov    0x20(%rbp),%eax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <getclustermeans@plt>
movl   $0x1,-0xc(%rbp)
jmp    1274 <getclustercentroids+0x134>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<getclustercentroids>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r15
mov    %rcx,%r12
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r13d
mov    0x50(%rsp),%r10d
movsbl 0x58(%rsp),%eax
cmp    $0x61,%eax
je     11bd <getclustercentroids+0x7d>
xor    %r14d,%r14d
cmp    $0x6d,%eax
jne    11e7 <getclustercentroids+0xa7>
mov    %r9,(%rsp)
test   %r10d,%r10d
mov    %ebp,%edi
cmove  %ebx,%edi
shl    $0x3,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11e7 <getclustercentroids+0xa7>
mov    %r13d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r12,%rcx
mov    %r15,%r8
mov    (%rsp),%r9
push   %rax
mov    0x58(%rsp),%ebp
push   %rbp
push   0x58(%rsp)
push   0x58(%rsp)
mov    %rax,%rbx
call   1060 <getclustermedians@plt>
add    $0x20,%rsp
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11e1 <getclustercentroids+0xa1>
sub    $0x8,%rsp
mov    %r13d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r12,%rcx
mov    %r15,%r8
push   %r10
push   0x58(%rsp)
push   0x58(%rsp)
call   1040 <getclustermeans@plt>
add    $0x20,%rsp
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getclustercentroids(i32 %0, i32 %1, i32 %2, double** %3, i32** %4, i32* %5, double** %6, i32** %7, i32 %8, i8 signext %9) {
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double**
%16 = alloca i32**
%17 = alloca i32*
%18 = alloca double**
%19 = alloca i32**
%20 = alloca i32
%21 = alloca i8
%22 = alloca i32
%23 = alloca double*
store i32 %0, i32* %12
store i32 %1, i32* %13
store i32 %2, i32* %14
store double** %3, double*** %15
store i32** %4, i32*** %16
store i32* %5, i32** %17
store double** %6, double*** %18
store i32** %7, i32*** %19
store i32 %8, i32* %20
store i8 %9, i8* %21
%24 = load i8, i8* %21
%25 = sext i8 %24 to i32
switch i32 %25, label %68 [
i32 109, label %26
i32 97, label %57
]
26: ; preds = %10
%27 = load i32, i32* %20
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i32, i32* %13
br label %33
31: ; preds = %26
%32 = load i32, i32* %14
br label %33
33: ; preds = %31, %29
%34 = phi i32 [ %30, %29 ], [ %32, %31 ]
store i32 %34, i32* %22
%35 = load i32, i32* %22
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 8
%38 = trunc i64 %37 to i32
%39 = call double* @malloc(i32 %38)
store double* %39, double** %23
%40 = load double*, double** %23
%41 = icmp ne double* %40, null
br i1 %41, label %43, label %42
42: ; preds = %33
store i32 0, i32* %11
br label %69
43: ; preds = %33
%44 = load i32, i32* %12
%45 = load i32, i32* %13
%46 = load i32, i32* %14
%47 = load double**, double*** %15
%48 = load i32**, i32*** %16
%49 = load i32*, i32** %17
%50 = load double**, double*** %18
%51 = load i32**, i32*** %19
%52 = load i32, i32* %20
%53 = load double*, double** %23
%54 = call i32 @getclustermedians(i32 %44, i32 %45, i32 %46, double** %47, i32** %48, i32* %49, double** %50, i32** %51, i32 %52, double* %53)
%55 = load double*, double** %23
%56 = call i32 @free(double* %55)
store i32 1, i32* %11
br label %69
57: ; preds = %10
%58 = load i32, i32* %12
%59 = load i32, i32* %13
%60 = load i32, i32* %14
%61 = load double**, double*** %15
%62 = load i32**, i32*** %16
%63 = load i32*, i32** %17
%64 = load double**, double*** %18
%65 = load i32**, i32*** %19
%66 = load i32, i32* %20
%67 = call i32 @getclustermeans(i32 %58, i32 %59, i32 %60, double** %61, i32** %62, i32* %63, double** %64, i32** %65, i32 %66)
store i32 1, i32* %11
br label %69
68: ; preds = %10
store i32 0, i32* %11
br label %69
69: ; preds = %68, %57, %43, %42
%70 = load i32, i32* %11
ret i32 %70
}

LLVM IR (-O2):
define i32 @getclustercentroids(i32 %0, i32 %1, i32 %2, double** %3, i32** %4, i32* %5, double** %6, i32** %7, i32 %8, i8 signext %9) {
%11 = sext i8 %9 to i32
switch i32 %11, label %23 [
i32 109, label %12
i32 97, label %21
]
12: ; preds = %10
%13 = icmp eq i32 %8, 0
%14 = select i1 %13, i32 %1, i32 %2
%15 = shl i32 %14, 3
%16 = tail call double* @malloc(i32 %15)
%17 = icmp eq double* %16, null
br i1 %17, label %23, label %18
18: ; preds = %12
%19 = tail call i32 @getclustermedians(i32 %0, i32 %1, i32 %2, double** %3, i32** %4, i32* %5, double** %6, i32** %7, i32 %8, double* %16)
%20 = tail call i32 @free(double* %16)
br label %23
21: ; preds = %10
%22 = tail call i32 @getclustermeans(i32 %0, i32 %1, i32 %2, double** %3, i32** %4, i32* %5, double** %6, i32** %7, i32 %8)
br label %23
23: ; preds = %10, %18, %12, %21
%24 = phi i32 [ 1, %21 ], [ 1, %18 ], [ 0, %12 ], [ 0, %10 ]
ret i32 %24
}