#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 */
char **malloc(int);
int snoopy_string_countChars(char *, char);
char *strchr(char *, char);
int strlen(char *);
int snoopy_parser_argList_csv(char *argListRaw, char ***argListParsed) {
  int commaCount;
  int argCount;
  char **argListParsedPtr;
  int argListRaw_charCount;
  char *argListRaw_pos;
  char *nextCommaPtr;
  int i;
  argListRaw_charCount = strlen(argListRaw);
  commaCount = snoopy_string_countChars(argListRaw, ',');
  argCount = commaCount + 1;
  argListParsedPtr = malloc(sizeof(char *) * (argCount + 1));
  if (0 == argListRaw_charCount) {
    argCount = 0;
    i = 0;
  } else {
    argListParsedPtr[0] = argListRaw;
    i = 1;
  }
  if (commaCount > 0) {
    argListRaw_pos = argListRaw;
    while (NULL != (nextCommaPtr = strchr(argListRaw_pos, ','))) {
      *nextCommaPtr = '\0';
      argListRaw_pos = nextCommaPtr + 1;
      argListParsedPtr[i] = argListRaw_pos;
      i++;
    }
  }
  argListParsedPtr[i] = argListRaw + argListRaw_charCount + 1;
  *argListParsed = argListParsedPtr;
  return argCount;
}


x86 assembly (clang, -O0):
<snoopy_parser_argList_csv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2c,%esi
call   1050 <snoopy_string_countChars@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
jne    11ab <snoopy_parser_argList_csv+0x6b>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x3c(%rbp)
jmp    11bd <snoopy_parser_argList_csv+0x7d>
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x3c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1225 <snoopy_parser_argList_csv+0xe5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x38(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     1220 <snoopy_parser_argList_csv+0xe0>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11cf <snoopy_parser_argList_csv+0x8f>
jmp    1225 <snoopy_parser_argList_csv+0xe5>
mov    -0x8(%rbp),%rdx
movslq -0x24(%rbp),%rax
add    %rax,%rdx
add    $0x1,%rdx
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snoopy_parser_argList_csv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    $0x2c,%esi
call   1050 <snoopy_string_countChars@plt>
mov    %eax,%ebx
lea    0x10(,%rbx,8),%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
test   %r15d,%r15d
je     118f <snoopy_parser_argList_csv+0x4f>
lea    0x1(%rbx),%eax
mov    %r13,0x0(%rbp)
mov    $0x1,%r14d
test   %ebx,%ebx
jg     1198 <snoopy_parser_argList_csv+0x58>
jmp    11d4 <snoopy_parser_argList_csv+0x94>
xor    %eax,%eax
xor    %r14d,%r14d
test   %ebx,%ebx
jle    11d4 <snoopy_parser_argList_csv+0x94>
mov    %eax,%ebx
mov    %r13,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d2 <snoopy_parser_argList_csv+0x92>
mov    %r14d,%r14d
nop
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,0x0(%rbp,%r14,8)
add    $0x1,%r14
mov    %rax,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11b0 <snoopy_parser_argList_csv+0x70>
mov    %ebx,%eax
movslq %r15d,%rcx
lea    (%rcx,%r13,1),%rdx
add    $0x1,%rdx
movslq %r14d,%rcx
mov    %rdx,0x0(%rbp,%rcx,8)
mov    %rbp,(%r12)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @snoopy_parser_argList_csv(i8* %0, i8*** %1) {
%3 = alloca i8*
%4 = alloca i8***
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %3
store i8*** %1, i8**** %4
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %8
%14 = load i8*, i8** %3
%15 = call i32 @snoopy_string_countChars(i8* %14, i8 signext 44)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = mul i64 8, %20
%22 = trunc i64 %21 to i32
%23 = call i8** @malloc(i32 %22)
store i8** %23, i8*** %7
%24 = load i32, i32* %8
%25 = icmp eq i32 0, %24
br i1 %25, label %26, label %27
26: ; preds = %2
store i32 0, i32* %6
store i32 0, i32* %11
br label %31
27: ; preds = %2
%28 = load i8*, i8** %3
%29 = load i8**, i8*** %7
%30 = getelementptr inbounds i8*, i8** %29, i64 0
store i8* %28, i8** %30
store i32 1, i32* %11
br label %31
31: ; preds = %27, %26
%32 = load i32, i32* %5
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %52
34: ; preds = %31
%35 = load i8*, i8** %3
store i8* %35, i8** %9
br label %36
36: ; preds = %40, %34
%37 = load i8*, i8** %9
%38 = call i8* @strchr(i8* %37, i8 signext 44)
store i8* %38, i8** %10
%39 = icmp ne i8* null, %38
br i1 %39, label %40, label %51
40: ; preds = %36
%41 = load i8*, i8** %10
store i8 0, i8* %41
%42 = load i8*, i8** %10
%43 = getelementptr inbounds i8, i8* %42, i64 1
store i8* %43, i8** %9
%44 = load i8*, i8** %9
%45 = load i8**, i8*** %7
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
store i8* %44, i8** %48
%49 = load i32, i32* %11
%50 = add nsw i32 %49, 1
store i32 %50, i32* %11
br label %36
51: ; preds = %36
br label %52
52: ; preds = %51, %31
%53 = load i8*, i8** %3
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = load i8**, i8*** %7
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
store i8* %57, i8** %61
%62 = load i8**, i8*** %7
%63 = load i8***, i8**** %4
store i8** %62, i8*** %63
%64 = load i32, i32* %6
ret i32 %64
}

LLVM IR (-O2):
define i32 @snoopy_parser_argList_csv(i8* %0, i8*** nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @snoopy_string_countChars(i8* %0, i8 signext 44)
%5 = shl i32 %4, 3
%6 = add i32 %5, 16
%7 = tail call i8** @malloc(i32 %6)
%8 = icmp eq i32 %3, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = add nsw i32 %4, 1
store i8* %0, i8** %7
br label %11
11: ; preds = %2, %9
%12 = phi i32 [ %10, %9 ], [ 0, %2 ]
%13 = phi i32 [ 1, %9 ], [ 0, %2 ]
%14 = icmp sgt i32 %4, 0
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 44)
%17 = icmp eq i8* %16, null
br i1 %17, label %30, label %18
18: ; preds = %15
%19 = zext i32 %13 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ %19, %18 ], [ %25, %20 ]
%22 = phi i8* [ %16, %18 ], [ %26, %20 ]
store i8 0, i8* %22
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = getelementptr inbounds i8*, i8** %7, i64 %21
store i8* %23, i8** %24
%25 = add nuw i64 %21, 1
%26 = tail call i8* @strchr(i8* dereferenceable(1) %23, i8 signext 44)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %20
28: ; preds = %20
%29 = trunc i64 %25 to i32
br label %30
30: ; preds = %28, %15, %11
%31 = phi i32 [ %13, %11 ], [ %13, %15 ], [ %29, %28 ]
%32 = sext i32 %3 to i64
%33 = getelementptr inbounds i8, i8* %0, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = sext i32 %31 to i64
%36 = getelementptr inbounds i8*, i8** %7, i64 %35
store i8* %34, i8** %36
store i8** %7, i8*** %1
ret i32 %12
}