#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*/ assert_log(int, int, char *, int *);
char **split_str(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int test_split_str(int verbose) {
  int ok = 1;
  char **sp = split_str("one two  !", " ");
  assert_log(!strcmp(sp[0], "one"), verbose, "chunk should be: one", &ok);
  assert_log(!strcmp(sp[1], "two"), verbose, "chunk should be: two", &ok);
  assert_log(!strcmp(sp[2], "!"), verbose, "chunk should be: !", &ok);
  assert_log(sp[3] == NULL, verbose, "chunk should be: NULL", &ok);
  return ok;
}


x86 assembly (clang, -O0):
<test_split_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xeb7(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1050 <split_str@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xeb7(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    -0x4(%rbp),%esi
lea    0xe8a(%rip),%rdx
lea    -0x8(%rbp),%rcx
call   1040 <assert_log@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe98(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    -0x4(%rbp),%esi
lea    0xe6b(%rip),%rdx
lea    -0x8(%rbp),%rcx
call   1040 <assert_log@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3a(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    -0x4(%rbp),%esi
lea    0xe4c(%rip),%rdx
lea    -0x8(%rbp),%rcx
call   1040 <assert_log@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x18(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x4(%rbp),%esi
lea    0xe3b(%rip),%rdx
lea    -0x8(%rbp),%rcx
call   1040 <assert_log@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_split_str>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
movl   $0x1,0xc(%rsp)
lea    0xeb7(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1050 <split_str@plt>
mov    %rax,%rbx
mov    (%rax),%rdi
lea    0xebc(%rip),%rsi
call   1030 <strcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
lea    0xe97(%rip),%rdx
lea    0xc(%rsp),%r14
mov    %ebp,%esi
mov    %r14,%rcx
call   1040 <assert_log@plt>
mov    0x8(%rbx),%rdi
lea    0xea3(%rip),%rsi
call   1030 <strcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
lea    0xe7e(%rip),%rdx
mov    %ebp,%esi
mov    %r14,%rcx
call   1040 <assert_log@plt>
mov    0x10(%rbx),%rdi
lea    0xe50(%rip),%rsi
call   1030 <strcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
lea    0xe6a(%rip),%rdx
mov    %ebp,%esi
mov    %r14,%rcx
call   1040 <assert_log@plt>
xor    %edi,%edi
cmpq   $0x0,0x18(%rbx)
sete   %dil
lea    0xe61(%rip),%rdx
mov    %ebp,%esi
mov    %r14,%rcx
call   1040 <assert_log@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"one two !\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"one\00"
@.str.3 = [21 x i8] c"chunk should be: one\00"
@.str.4 = [4 x i8] c"two\00"
@.str.5 = [21 x i8] c"chunk should be: two\00"
@.str.6 = [2 x i8] c"!\00"
@.str.7 = [19 x i8] c"chunk should be: !\00"
@.str.8 = [22 x i8] c"chunk should be: NULL\00"
define i32 @test_split_str(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8**
store i32 %0, i32* %2
store i32 1, i32* %3
%5 = call i8** @split_str(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8** %5, i8*** %4
%6 = load i8**, i8*** %4
%7 = getelementptr inbounds i8*, i8** %6, i64 0
%8 = load i8*, i8** %7
%9 = call i32 @strcmp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
%12 = zext i1 %11 to i32
%13 = load i32, i32* %2
%14 = call i32 @assert_log(i32 %12, i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
%21 = zext i1 %20 to i32
%22 = load i32, i32* %2
%23 = call i32 @assert_log(i32 %21, i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%24 = load i8**, i8*** %4
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
%30 = zext i1 %29 to i32
%31 = load i32, i32* %2
%32 = call i32 @assert_log(i32 %30, i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32* %3)
%33 = load i8**, i8*** %4
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = icmp eq i8* %35, null
%37 = zext i1 %36 to i32
%38 = load i32, i32* %2
%39 = call i32 @assert_log(i32 %37, i32 %38, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i32* %3)
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [11 x i8] c"one two !\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"one\00"
@.str.3 = [21 x i8] c"chunk should be: one\00"
@.str.4 = [4 x i8] c"two\00"
@.str.5 = [21 x i8] c"chunk should be: two\00"
@.str.6 = [2 x i8] c"!\00"
@.str.7 = [19 x i8] c"chunk should be: !\00"
@.str.8 = [22 x i8] c"chunk should be: NULL\00"
define i32 @test_split_str(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%4 = tail call i8** @split_str(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = load i8*, i8** %4
%6 = tail call i32 @strcmp(i8* dereferenceable(1) %5, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert_log(i32 %8, i32 %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%10 = getelementptr inbounds i8*, i8** %4, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert_log(i32 %14, i32 %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%16 = getelementptr inbounds i8*, i8** %4, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @strcmp(i8* dereferenceable(1) %17, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert_log(i32 %20, i32 %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32* %2)
%22 = getelementptr inbounds i8*, i8** %4, i64 3
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
%25 = zext i1 %24 to i32
%26 = call i32 @assert_log(i32 %25, i32 %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i32* %2)
%27 = load i32, i32* %2
ret i32 %27
}