#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 **getMem(int);
int /*<<< orphan*/ getMemFree(char ***, int);
int /*<<< orphan*/ printf(char *, ...);
int spitString2(char *, char, char **, int *);
int /*<<< orphan*/ system(char *);
int main() {
  char *p = "abcdef,acccd,eeee,aaaa,e3eeee,ssss,";
  char **buf = getMem(10);
  int n = 0;
  int ret = 0;
  ret = spitString2(p, ',', buf, &n);
  if (ret != 0) {
    return ret;
  }
  int i = 0;
  for (i = 0; i < n; i++) {
    printf("%s\n", buf[i]);
  }
  getMemFree(&buf, n);
  printf("\n");
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0xa,%edi
call   1060 <getMem@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x2c,%esi
lea    -0x1c(%rbp),%rcx
call   1030 <spitString2@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11b4 <main+0x64>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <main+0xd3>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f6 <main+0xa6>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c2 <main+0x72>
mov    -0x1c(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1070 <getMemFree@plt>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe11(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0xa,%edi
call   1070 <getMem@plt>
mov    %rax,%r14
mov    %rax,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xe78(%rip),%rdi
lea    0xc(%rsp),%rcx
mov    $0x2c,%esi
mov    %rax,%rdx
call   1040 <spitString2@plt>
test   %eax,%eax
jne    11e9 <main+0x89>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    11c7 <main+0x67>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
call   1050 <puts@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rsi
cmp    %rsi,%rbx
jl     11b0 <main+0x50>
lea    0x10(%rsp),%rdi
call   1080 <getMemFree@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe42(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [36 x i8] c"abcdef,acccd,eeee,aaaa,e3eeee,ssss,\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = call i8** @getMem(i32 10)
store i8** %7, i8*** %3
store i32 0, i32* %4
store i32 0, i32* %5
%8 = load i8*, i8** %2
%9 = load i8**, i8*** %3
%10 = call i32 @spitString2(i8* %8, i8 signext 44, i8** %9, i32* %4)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = load i32, i32* %5
store i32 %14, i32* %1
br label %35
15: ; preds = %0
store i32 0, i32* %6
store i32 0, i32* %6
br label %16
16: ; preds = %27, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i8**, i8*** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %20
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %16
30: ; preds = %16
%31 = load i32, i32* %4
%32 = call i32 @getMemFree(i8*** %3, i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %35
35: ; preds = %30, %13
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [36 x i8] c"abcdef,acccd,eeee,aaaa,e3eeee,ssss,\00"
@.str.3 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i8**
%2 = alloca i32
%3 = bitcast i8*** %1 to i8*
%4 = tail call i8** @getMem(i32 10)
store i8** %4, i8*** %1
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = call i32 @spitString2(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8 signext 44, i8** %4, i32* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %0
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %8, %11
%12 = phi i64 [ %16, %11 ], [ 0, %8 ]
%13 = getelementptr inbounds i8*, i8** %4, i64 %12
%14 = load i8*, i8** %13
%15 = call i32 @puts(i8* dereferenceable(1) %14)
%16 = add nuw nsw i64 %12, 1
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %11, label %20
20: ; preds = %11, %8
%21 = phi i32 [ %9, %8 ], [ %17, %11 ]
%22 = call i32 @getMemFree(i8*** %1, i32 %21)
%23 = call i32 @putchar(i32 10)
%24 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %0, %20
%26 = phi i32 [ 0, %20 ], [ %6, %0 ]
ret i32 %26
}