#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(char **);
int /*<<< orphan*/ mu_assert(char *, int);
char **split_string(char *, char *, size_t *);
scalar_t__ strcmp(char *, char *);
char *test_split_string() {
  char str[] = "41,27";
  char delim[] = ",";
  size_t len = 0;
  char **result = split_string(str, delim, &len);
  mu_assert("len is not 2", len == 2);
  mu_assert("1: _1_,2 => [_1_, 2]", strcmp("41", result[0]) == 0);
  mu_assert("2: 1,_2_ => [1, _2_]", strcmp("27", result[1]) == 0);
  free(result);
  return 0;
}


x86 assembly (clang, -O0):
<test_split_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xeb2(%rip),%eax
mov    %eax,-0x6(%rbp)
mov    0xeac(%rip),%ax
mov    %ax,-0x2(%rbp)
mov    0xea3(%rip),%ax
mov    %ax,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x6(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <split_string@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x2,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe70(%rip),%rdi
call   1060 <mu_assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7f(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe52(%rip),%rdi
call   1060 <mu_assert@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2c(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe3e(%rip),%rdi
call   1060 <mu_assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_split_string>:
push   %rbx
sub    $0x20,%rsp
movw   $0x37,0x14(%rsp)
movl   $0x322c3134,0x10(%rsp)
32
movw   $0x2c,0xe(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rdi
lea    0xe(%rsp),%rsi
lea    0x18(%rsp),%rdx
call   1040 <split_string@plt>
mov    %rax,%rbx
xor    %esi,%esi
cmpq   $0x2,0x18(%rsp)
sete   %sil
lea    0xe78(%rip),%rdi
call   1060 <mu_assert@plt>
mov    (%rbx),%rsi
lea    0xe8b(%rip),%rdi
call   1050 <strcmp@plt>
xor    %esi,%esi
test   %rax,%rax
sete   %sil
lea    0xe61(%rip),%rdi
call   1060 <mu_assert@plt>
mov    0x8(%rbx),%rsi
lea    0xe41(%rip),%rdi
call   1050 <strcmp@plt>
xor    %esi,%esi
test   %rax,%rax
sete   %sil
lea    0xe54(%rip),%rdi
call   1060 <mu_assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_split_string.str = [6 x i8] c"41,27\00"
@__const.test_split_string.delim = [2 x i8] c",\00"
@.str = [13 x i8] c"len is not 2\00"
@.str.1 = [21 x i8] c"1: _1_,2 => [_1_, 2]\00"
@.str.2 = [3 x i8] c"41\00"
@.str.3 = [21 x i8] c"2: 1,_2_ => [1, _2_]\00"
@.str.4 = [3 x i8] c"27\00"
define i8* @test_split_string() {
%1 = alloca [6 x i8]
%2 = alloca [2 x i8]
%3 = alloca i64
%4 = alloca i8**
%5 = bitcast [6 x i8]* %1 to i8*
%6 = bitcast [2 x i8]* %2 to i8*
store i64 0, i64* %3
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%9 = call i8** @split_string(i8* %7, i8* %8, i64* %3)
store i8** %9, i8*** %4
%10 = load i64, i64* %3
%11 = icmp eq i64 %10, 2
%12 = zext i1 %11 to i32
%13 = call i32 @mu_assert(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @mu_assert(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @mu_assert(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load i8**, i8*** %4
%29 = call i32 @free(i8** %28)
ret i8* null
}

LLVM IR (-O2):
@__const.test_split_string.str = [6 x i8] c"41,27\00"
@.str = [13 x i8] c"len is not 2\00"
@.str.1 = [21 x i8] c"1: _1_,2 => [_1_, 2]\00"
@.str.2 = [3 x i8] c"41\00"
@.str.3 = [21 x i8] c"2: 1,_2_ => [1, _2_]\00"
@.str.4 = [3 x i8] c"27\00"
define noalias i8* @test_split_string() {
%1 = alloca [6 x i8]
%2 = alloca i16
%3 = alloca i64
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%5 = bitcast i16* %2 to i8*
store i16 44, i16* %2
%6 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%7 = call i8** @split_string(i8* %4, i8* %5, i64* %3)
%8 = load i64, i64* %3
%9 = icmp eq i64 %8, 2
%10 = zext i1 %9 to i32
%11 = call i32 @mu_assert(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i8*, i8** %7
%13 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @mu_assert(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds i8*, i8** %7, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = icmp eq i64 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @mu_assert(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = call i32 @free(i8** %7)
ret i8* null
}