#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 */
struct list_head {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sbuf_list_prepend(struct list_head *, char *);
char *strdup(char const *);
char *strrchr(char *, char);
void sbuf_split(struct list_head *sl, const char *data, char field_separator) {
  char *p, *str;
  if (!data)
    return;
  str = strdup(data);
  for (;;) {
    p = strrchr(str, field_separator);
    if (!p)
      break;
    sbuf_list_prepend(sl, p + 1);
    *p = '\0';
  }
  sbuf_list_prepend(sl, str);
  free(str);
}


x86 assembly (clang, -O0):
<sbuf_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1165 <sbuf_split+0x25>
jmp    11c6 <sbuf_split+0x86>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1193 <sbuf_split+0x53>
jmp    11b0 <sbuf_split+0x70>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1040 <sbuf_list_prepend@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    1172 <sbuf_split+0x32>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <sbuf_list_prepend@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sbuf_split>:
test   %rsi,%rsi
je     11be <sbuf_split+0x7e>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1060 <strdup@plt>
mov    %rax,%r15
movsbl %bl,%ebp
mov    %rax,%rdi
mov    %ebp,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11a1 <sbuf_split+0x61>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbx),%rsi
mov    %r14,%rdi
call   1040 <sbuf_list_prepend@plt>
movb   $0x0,(%rbx)
mov    %r15,%rdi
mov    %ebp,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1180 <sbuf_split+0x40>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <sbuf_list_prepend@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
ret

LLVM IR (-O0):
%struct.list_head = type { i32 }
define void @sbuf_split(%struct.list_head* %0, i8* %1, i8 signext %2) {
%4 = alloca %struct.list_head*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8*
store %struct.list_head* %0, %struct.list_head** %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %3
br label %34
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = call i8* @strdup(i8* %13)
store i8* %14, i8** %8
br label %15
15: ; preds = %22, %12
%16 = load i8*, i8** %8
%17 = load i8, i8* %6
%18 = call i8* @strrchr(i8* %16, i8 signext %17)
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %15
br label %28
22: ; preds = %15
%23 = load %struct.list_head*, %struct.list_head** %4
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = call i32 @sbuf_list_prepend(%struct.list_head* %23, i8* %25)
%27 = load i8*, i8** %7
store i8 0, i8* %27
br label %15
28: ; preds = %21
%29 = load %struct.list_head*, %struct.list_head** %4
%30 = load i8*, i8** %8
%31 = call i32 @sbuf_list_prepend(%struct.list_head* %29, i8* %30)
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %28, %11
ret void
}

LLVM IR (-O2):
%struct.list_head = type { i32 }
define void @sbuf_split(%struct.list_head* %0, i8* %1, i8 signext %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %18, label %5
5: ; preds = %3
%6 = tail call i8* @strdup(i8* %1)
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %6, i8 signext %2)
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %5, %9
%10 = phi i8* [ %13, %9 ], [ %7, %5 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = tail call i32 @sbuf_list_prepend(%struct.list_head* %0, i8* %11)
store i8 0, i8* %10
%13 = tail call i8* @strrchr(i8* dereferenceable(1) %6, i8 signext %2)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %9
15: ; preds = %9, %5
%16 = tail call i32 @sbuf_list_prepend(%struct.list_head* %0, i8* %6)
%17 = tail call i32 @free(i8* %6)
br label %18
18: ; preds = %3, %15
ret void
}