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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    0xebf(%rip),%ax
mov    %ax,-0x22(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x22(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11a2 <main+0x82>
mov    -0x30(%rbp),%rsi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x22(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    116f <main+0x4f>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x3b,0xe(%rsp)
lea    0x10(%rsp),%rdi
lea    0xe(%rsp),%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     119c <main+0x6c>
lea    0xe9f(%rip),%r14
lea    0xe(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1180 <main+0x50>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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