#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*/ printf(char *, char *);
char *strsep(char **, char const *);
void test_strsep(char **text, const char *delim, bool dofree) {
  char *ptr, *str;
  ptr = *text;
  while ((str = strsep(text, delim)))
    printf("%s\n", str);
  if (dofree)
    free(ptr);
}


x86 assembly (clang, -O0):
<test_strsep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     117e <test_strsep+0x4e>
mov    -0x28(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
jmp    114e <test_strsep+0x1e>
cmpl   $0x0,-0x14(%rbp)
je     1191 <test_strsep+0x61>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strsep>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    (%rdi),%r14
call   1050 <strsep@plt>
test   %rax,%rax
je     117b <test_strsep+0x4b>
lea    0xeab(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <strsep@plt>
test   %rax,%rax
jne    1160 <test_strsep+0x30>
test   %r15d,%r15d
je     1190 <test_strsep+0x60>
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define void @test_strsep(i8** %0, i8* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
store i8* %10, i8** %7
br label %11
11: ; preds = %16, %3
%12 = load i8**, i8*** %4
%13 = load i8*, i8** %5
%14 = call i8* @strsep(i8** %12, i8* %13)
store i8* %14, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %8
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %11
19: ; preds = %11
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %7
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @test_strsep(i8** %0, i8* %1, i32 %2) {
%4 = load i8*, i8** %0
%5 = tail call i8* @strsep(i8** %0, i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %3, %7
%8 = phi i8* [ %10, %7 ], [ %5, %3 ]
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i8* @strsep(i8** %0, i8* %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %7
12: ; preds = %7, %3
%13 = icmp eq i32 %2, 0
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 @free(i8* %4)
br label %16
16: ; preds = %14, %12
ret void
}