#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 *);
char *strtok(char *, char *);
int main() {
  char str[] = "select \"foo\" from test;";
  char delim[] = " ";
  char *result = NULL;
  result = strtok(str, delim);
  while (result != NULL) {
    printf("result is \"%s\"\n", result);
    result = strtok(NULL, delim);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xec1(%rip),%ax
mov    %ax,-0x22(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x22(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11a5 <main+0x85>
mov    -0x30(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
lea    -0x22(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    1174 <main+0x54>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x3b74736574206d,%rax
mov    %rax,0x20(%rsp)
movw   $0x20,0xe(%rsp)
lea    0x10(%rsp),%rdi
lea    0xe(%rsp),%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     118a <main+0x6a>
lea    0xeb4(%rip),%r14
lea    0xe(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    1170 <main+0x50>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.str = [24 x i8] c"select \22foo\22 from test;\00"
@__const.main.delim = [2 x i8] c" \00"
@.str = [16 x i8] c"result is \22%s\22\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [24 x i8]
%3 = alloca [2 x i8]
%4 = alloca i8*
store i32 0, i32* %1
%5 = bitcast [24 x i8]* %2 to i8*
%6 = bitcast [2 x i8]* %3 to i8*
store i8* null, i8** %4
%7 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%9 = call i8* @strtok(i8* %7, i8* %8)
store i8* %9, i8** %4
br label %10
10: ; preds = %13, %0
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i8*, i8** %4
%15 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%17 = call i8* @strtok(i8* null, i8* %16)
store i8* %17, i8** %4
br label %10
18: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [24 x i8] c"select \22foo\22 from test;\00"
@.str = [16 x i8] c"result is \22%s\22\0A\00"
define i32 @main() {
%1 = alloca [24 x i8]
%2 = alloca i16
%3 = getelementptr inbounds [24 x i8], [24 x i8]* %1, i64 0, i64 0
%4 = bitcast i16* %2 to i8*
store i16 32, i16* %2
%5 = call i8* @strtok(i8* %3, i8* %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %0, %7
%8 = phi i8* [ %10, %7 ], [ %5, %0 ]
%9 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = call i8* @strtok(i8* null, i8* %4)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %7
12: ; preds = %7, %0
ret i32 0
}