#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 *);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strpbrk(char *, char *);
int main(void) {
  char target[] = "ABC,DEF,GHI\nJKL MNO PQR";
  char *s = target;
  char *p = NULL;
  int d = 0;
  char token[256] = {0};
  char *e = &target[strlen(target)];
  do {
    p = strpbrk(s, ",\n ");
    if (p != NULL) {
      d = p - s;
      strncpy(token, s, d);
      printf("token = %s\n", token);
      s = p + 1;
    } else {
      d = e - s;
      strncpy(token, s, d);
      printf("token = %s\n", token);
    }
  } while (p != NULL);
  printf("target = %s\n", target);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe97(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe94(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
lea    -0x20(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x148(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1070 <strpbrk@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     122b <main+0xdb>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x34(%rbp)
lea    -0x140(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x140(%rbp),%rsi
lea    0xe07(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1262 <main+0x112>
mov    -0x148(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x34(%rbp)
lea    -0x140(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x140(%rbp),%rsi
lea    0xdbf(%rip),%rdi
call   1050 <printf@plt>
jmp    1267 <main+0x117>
cmpq   $0x0,-0x30(%rbp)
jne    11c7 <main+0x77>
lea    -0x20(%rbp),%rsi
lea    0xdab(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsp,%rbx
movaps 0xea5(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x525150204f4e4d,%rax
mov    %rax,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r14
lea    0xe27(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strpbrk@plt>
test   %rax,%rax
je     1255 <main+0x115>
mov    %rax,%r15
mov    %rsp,%rbx
lea    0x20(%rsp),%r12
lea    0xe0c(%rip),%r13
lea    0xe01(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edx
sub    %ebx,%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
mov    %r15,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <strpbrk@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1220 <main+0xe0>
mov    %rsp,%r15
add    %r15d,%r14d
sub    %ebx,%r14d
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
lea    0xda4(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
lea    0xda1(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.target = [24 x i8] c"ABC,DEF,GHI\0AJKL MNO PQR\00"
@.str = [4 x i8] c",\0A \00"
@.str.1 = [12 x i8] c"token = %s\0A\00"
@.str.2 = [13 x i8] c"target = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [24 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i8*
store i32 0, i32* %1
%8 = bitcast [24 x i8]* %2 to i8*
%9 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
store i8* %9, i8** %3
store i8* null, i8** %4
store i32 0, i32* %5
%10 = bitcast [256 x i8]* %6 to i8*
%11 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%12 = call i64 @strlen(i8* %11)
%13 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 %12
store i8* %13, i8** %7
br label %14
14: ; preds = %48, %0
%15 = load i8*, i8** %3
%16 = call i8* @strpbrk(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %34
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = load i8*, i8** %3
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = trunc i64 %24 to i32
store i32 %25, i32* %5
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%27 = load i8*, i8** %3
%28 = load i32, i32* %5
%29 = call i32 @strncpy(i8* %26, i8* %27, i32 %28)
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8* %33, i8** %3
br label %47
34: ; preds = %14
%35 = load i8*, i8** %7
%36 = load i8*, i8** %3
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = trunc i64 %39 to i32
store i32 %40, i32* %5
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%42 = load i8*, i8** %3
%43 = load i32, i32* %5
%44 = call i32 @strncpy(i8* %41, i8* %42, i32 %43)
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%46 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %34, %19
br label %48
48: ; preds = %47
%49 = load i8*, i8** %4
%50 = icmp ne i8* %49, null
br i1 %50, label %14, label %51
51: ; preds = %48
%52 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%53 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %52)
ret i32 0
}

LLVM IR (-O2):
@__const.main.target = [24 x i8] c"ABC,DEF,GHI\0AJKL MNO PQR\00"
@.str = [4 x i8] c",\0A \00"
@.str.1 = [12 x i8] c"token = %s\0A\00"
@.str.2 = [13 x i8] c"target = %s\0A\00"
define i32 @main() {
%1 = alloca [24 x i8]
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [24 x i8], [24 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = call i64 @strlen(i8* %3)
%6 = call i8* @strpbrk(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %20, label %8
8: ; preds = %0, %8
%9 = phi i8* [ %18, %8 ], [ %6, %0 ]
%10 = phi i8* [ %17, %8 ], [ %3, %0 ]
%11 = ptrtoint i8* %9 to i64
%12 = ptrtoint i8* %10 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
%15 = call i32 @strncpy(i8* %4, i8* %10, i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%17 = getelementptr inbounds i8, i8* %9, i64 1
%18 = call i8* @strpbrk(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %8
20: ; preds = %8, %0
%21 = phi i8* [ %3, %0 ], [ %17, %8 ]
%22 = getelementptr inbounds [24 x i8], [24 x i8]* %1, i64 0, i64 %5
%23 = ptrtoint i8* %22 to i64
%24 = ptrtoint i8* %21 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = call i32 @strncpy(i8* %4, i8* %21, i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%29 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %3)
ret i32 0
}