#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*/ printf(char *, ...);
char *strsep(char **, char const *);
int main() {
  printf("Seperating using strsep\n");
  char csv[] = "Name;Title;Misc";
  const char *delimiter = ";";
  char *aux = csv;
  char *word = strsep(&aux, delimiter);
  while (word) {
    printf("Word (%s)\n", word);
    word = strsep(&aux, delimiter);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0xeec(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xee9(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xebf(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdi
call   1040 <strsep@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11aa <main+0x8a>
mov    -0x38(%rbp),%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdi
call   1040 <strsep@plt>
mov    %rax,-0x38(%rbp)
jmp    1177 <main+0x57>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0xeae(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1050 <strsep@plt>
test   %rax,%rax
je     11ad <main+0x7d>
lea    0xe9a(%rip),%r14
lea    0xe91(%rip),%r15
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strsep@plt>
test   %rax,%rax
jne    1190 <main+0x60>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Seperating using strsep\0A\00"
@__const.main.csv = [16 x i8] c"Name;Title;Misc\00"
@.str.1 = [2 x i8] c";\00"
@.str.2 = [11 x i8] c"Word (%s)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = bitcast [16 x i8]* %2 to i8*
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %3
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
store i8* %8, i8** %4
%9 = load i8*, i8** %3
%10 = call i8* @strsep(i8** %4, i8* %9)
store i8* %10, i8** %5
br label %11
11: ; preds = %14, %0
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %3
%18 = call i8* @strsep(i8** %4, i8* %17)
store i8* %18, i8** %5
br label %11
19: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@__const.main.csv = [16 x i8] c"Name;Title;Misc\00"
@.str.1 = [2 x i8] c";\00"
@.str.2 = [11 x i8] c"Word (%s)\0A\00"
@str = [24 x i8] c"Seperating using strsep\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = alloca i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%5 = bitcast i8** %2 to i8*
store i8* %4, i8** %2
%6 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %0, %8
%9 = phi i8* [ %11, %8 ], [ %6, %0 ]
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %8
13: ; preds = %8, %0
ret i32 0
}