#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 *strtok_r(char *, char *, char **);
int main() {
  printf("Seperating using strtok_r\n");
  char csv[] = "Name;Title;Misc";
  char delimiter[] = ";";
  char *aux;
  char *word = strtok_r(csv, delimiter, &aux);
  while (word) {
    printf("Word (%s)\n", word);
    word = strtok_r(NULL, delimiter, &aux);
  }
  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)
mov    0xec1(%rip),%ax
mov    %ax,-0x22(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x22(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11aa <main+0x8a>
mov    -0x38(%rbp),%rsi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x22(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x30(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
jmp    1173 <main+0x53>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x3b,0x6(%rsp)
lea    0x10(%rsp),%rdi
lea    0x6(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
je     11af <main+0x7f>
lea    0xe98(%rip),%r14
lea    0x6(%rsp),%r15
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <strtok_r@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 = [27 x i8] c"Seperating using strtok_r\0A\00"
@__const.main.csv = [16 x i8] c"Name;Title;Misc\00"
@__const.main.delimiter = [2 x i8] c";\00"
@.str.1 = [11 x i8] c"Word (%s)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca [2 x i8]
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = bitcast [16 x i8]* %2 to i8*
%8 = bitcast [2 x i8]* %3 to i8*
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%11 = call i8* @strtok_r(i8* %9, i8* %10, i8** %4)
store i8* %11, i8** %5
br label %12
12: ; preds = %15, %0
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i8*, i8** %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%19 = call i8* @strtok_r(i8* null, i8* %18, i8** %4)
store i8* %19, i8** %5
br label %12
20: ; preds = %12
ret i32 0
}

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