#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
double *malloc(size_t);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ *strtok(char *, char *);
void CountCols(char *str, size_t *s1, double **table, size_t buff_num_rows) {
  char str_cpy[100000];
  strcpy(str_cpy, str);
  if (strtok(str_cpy, " \n,") == NULL)
    return;
  (*s1)++;
  while (1) {
    if (strtok(NULL, " \n,") == NULL)
      break;
    (*s1)++;
  }
  *table = malloc(buff_num_rows * (*s1) * sizeof(double));
  if (*table == NULL) {
    printf("\n### ERROR: malloc failed to create a data table\n");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<CountCols>:
push   %rbp
mov    %rsp,%rbp
sub    $0x186c0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x186c0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x186c0(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1060 <strtok@plt>
cmp    $0x0,%rax
jne    119d <CountCols+0x4d>
jmp    1224 <CountCols+0xd4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe4a(%rip),%rsi
call   1060 <strtok@plt>
cmp    $0x0,%rax
jne    11ca <CountCols+0x7a>
jmp    11dd <CountCols+0x8d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11ab <CountCols+0x5b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
imul   (%rax),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1224 <CountCols+0xd4>
lea    0xdf3(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x186c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CountCols>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x186a8,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    %rsp,%r12
mov    %r12,%rdi
call   1030 <strcpy@plt>
lea    0xe84(%rip),%rsi
mov    %r12,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11bb <CountCols+0x6b>
lea    0xe70(%rip),%r12
addq   $0x1,(%rbx)
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
jne    1190 <CountCols+0x40>
imul   (%rbx),%r15
shl    $0x3,%r15
mov    %r15,%rdi
call   1050 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11ca <CountCols+0x7a>
add    $0x186a8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe33(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c" \0A,\00"
@.str.1 = [50 x i8] c"\0A### ERROR: malloc failed to create a data table\0A\00"
@EXIT_FAILURE = global i32 0
define void @CountCols(i8* %0, i64* %1, double** %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca double**
%8 = alloca i64
%9 = alloca [100000 x i8]
store i8* %0, i8** %5
store i64* %1, i64** %6
store double** %2, double*** %7
store i64 %3, i64* %8
%10 = getelementptr inbounds [100000 x i8], [100000 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = getelementptr inbounds [100000 x i8], [100000 x i8]* %9, i64 0, i64 0
%14 = call i32* @strtok(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %4
br label %44
17: ; preds = %4
%18 = load i64*, i64** %6
%19 = load i64, i64* %18
%20 = add i64 %19, 1
store i64 %20, i64* %18
br label %21
21: ; preds = %17, %25
%22 = call i32* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %21
br label %29
25: ; preds = %21
%26 = load i64*, i64** %6
%27 = load i64, i64* %26
%28 = add i64 %27, 1
store i64 %28, i64* %26
br label %21
29: ; preds = %24
%30 = load i64, i64* %8
%31 = load i64*, i64** %6
%32 = load i64, i64* %31
%33 = mul i64 %30, %32
%34 = mul i64 %33, 8
%35 = call double* @malloc(i64 %34)
%36 = load double**, double*** %7
store double* %35, double** %36
%37 = load double**, double*** %7
%38 = load double*, double** %37
%39 = icmp eq double* %38, null
br i1 %39, label %40, label %44
40: ; preds = %29
%41 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %16, %29
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c" \0A,\00"
@EXIT_FAILURE = global i32 0
@str = [49 x i8] c"\0A### ERROR: malloc failed to create a data table\00"
define void @CountCols(i8* %0, i64* nocapture %1, double** nocapture writeonly %2, i64 %3) {
%5 = alloca [100000 x i8]
%6 = getelementptr inbounds [100000 x i8], [100000 x i8]* %5, i64 0, i64 0
%7 = call i32 @strcpy(i8* %6, i8* %0)
%8 = call i32* @strtok(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %25, label %10
10: ; preds = %4, %10
%11 = load i64, i64* %1
%12 = add i64 %11, 1
store i64 %12, i64* %1
%13 = call i32* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = load i64, i64* %1
%17 = shl i64 %3, 3
%18 = mul i64 %17, %16
%19 = call double* @malloc(i64 %18)
store double* %19, double** %2
%20 = icmp eq double* %19, null
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %15, %4
ret void
}