#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(long);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ *strtok(char *, char *);
void CountCols(char *str, int *s1, double **table, long int 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    1221 <CountCols+0xd1>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe4d(%rip),%rsi
call   1060 <strtok@plt>
cmp    $0x0,%rax
jne    11c7 <CountCols+0x77>
jmp    11d7 <CountCols+0x87>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11a8 <CountCols+0x58>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%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    1221 <CountCols+0xd1>
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc6(%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     11bd <CountCols+0x6d>
lea    0xe70(%rip),%r12
addl   $0x1,(%rbx)
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
jne    1190 <CountCols+0x40>
movslq (%rbx),%rax
imul   %rax,%r15
shl    $0x3,%r15
mov    %r15,%rdi
call   1050 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11cc <CountCols+0x7c>
add    $0x186a8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe31(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e01(%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, i32* %1, double** %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca double**
%8 = alloca i64
%9 = alloca [100000 x i8]
store i8* %0, i8** %5
store i32* %1, i32** %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 %45
17: ; preds = %4
%18 = load i32*, i32** %6
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %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 i32*, i32** %6
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
br label %21
29: ; preds = %24
%30 = load i64, i64* %8
%31 = load i32*, i32** %6
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = mul nsw i64 %30, %33
%35 = mul i64 %34, 8
%36 = call double* @malloc(i64 %35)
%37 = load double**, double*** %7
store double* %36, double** %37
%38 = load double**, double*** %7
%39 = load double*, double** %38
%40 = icmp eq double* %39, null
br i1 %40, label %41, label %45
41: ; preds = %29
%42 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; 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, i32* 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 %26, label %10
10: ; preds = %4, %10
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 1
store i32 %12, i32* %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 i32, i32* %1
%17 = sext i32 %16 to i64
%18 = shl i64 %3, 3
%19 = mul i64 %18, %17
%20 = call double* @malloc(i64 %19)
store double* %20, double** %2
%21 = icmp eq double* %20, null
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %15, %4
ret void
}