#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(int argc, char **argv) {
  char buf[8192];
  char *p;
  char *p1;
  char *delim = "\r\n";
  char a[] = "aaaaa\r\nbbbbb\nccccc\rp\ndddddd\n";
  p1 = a;
  p = strtok(p1, delim);
  if (p) {
    printf("get:%s'\n", p);
  }
  while ((p = strtok(NULL, delim)) != NULL) {
    printf("get:%s'\n", p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec0(%rip),%rax
mov    %rax,-0x2028(%rbp)
mov    0xec2(%rip),%rax
mov    %rax,-0x2050(%rbp)
mov    0xebc(%rip),%rax
mov    %rax,-0x2048(%rbp)
mov    0xeb6(%rip),%rax
mov    %rax,-0x2040(%rbp)
mov    0xeb1(%rip),%eax
mov    %eax,-0x2038(%rbp)
mov    0xea9(%rip),%al
mov    %al,-0x2034(%rbp)
lea    -0x2050(%rbp),%rax
mov    %rax,-0x2020(%rbp)
mov    -0x2020(%rbp),%rdi
mov    -0x2028(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x2018(%rbp)
cmpq   $0x0,-0x2018(%rbp)
je     11d2 <main+0xb2>
mov    -0x2018(%rbp),%rsi
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
jmp    11d7 <main+0xb7>
mov    -0x2028(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x2018(%rbp)
cmp    $0x0,%rax
je     1210 <main+0xf0>
mov    -0x2018(%rbp),%rsi
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
jmp    11d7 <main+0xb7>
xor    %eax,%eax
add    $0x2050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movups 0xeef(%rip),%xmm0
movups %xmm0,0xd(%rsp)
movaps 0xed6(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xebb(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strtok@plt>
test   %rax,%rax
je     1161 <main+0x41>
lea    0xeaa(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
lea    0xe98(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
test   %rax,%rax
je     11aa <main+0x8a>
lea    0xe88(%rip),%r14
lea    0xe7e(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
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    1190 <main+0x70>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
@__const.main.a = [29 x i8] c"aaaaa\0D\0Abbbbb\0Accccc\0Dp\0Adddddd\0A\00"
@.str.1 = [9 x i8] c"get:%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8192 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [29 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %9
%11 = bitcast [29 x i8]* %10 to i8*
%12 = getelementptr inbounds [29 x i8], [29 x i8]* %10, i64 0, i64 0
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = load i8*, i8** %9
%15 = call i8* @strtok(i8* %13, i8* %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i8*, i8** %7
%20 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %2
br label %22
22: ; preds = %26, %21
%23 = load i8*, i8** %9
%24 = call i8* @strtok(i8* null, i8* %23)
store i8* %24, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i8*, i8** %7
%28 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %22
29: ; preds = %22
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
@__const.main.a = [29 x i8] c"aaaaa\0D\0Abbbbb\0Accccc\0Dp\0Adddddd\0A\00"
@.str.1 = [9 x i8] c"get:%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [29 x i8]
%4 = getelementptr inbounds [29 x i8], [29 x i8]* %3, i64 0, i64 0
%5 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %9
9: ; preds = %7, %2
%10 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %9, %12
%13 = phi i8* [ %15, %12 ], [ %10, %9 ]
%14 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %12
17: ; preds = %12, %9
ret i32 0
}