#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(void) {
  char target[] = "ABC,DEF,GHI\nJKL MNO PQR";
  char *token = NULL;
  int i = 0;
  do {
    if (i == 0) {
      token = strtok(target, ",\n ");
    } else {
      token = strtok(NULL, ",\n ");
    }
    if (token != NULL) {
      printf("token = %s\n", token);
    }
    i++;
  } while (token != NULL);
  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)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1182 <main+0x62>
lea    -0x20(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1196 <main+0x76>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe8b(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b1 <main+0x91>
mov    -0x28(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    115f <main+0x3f>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movaps 0xece(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x525150204f4e4d,%rax
mov    %rax,0x10(%rsp)
xor    %ebx,%ebx
lea    0xeca(%rip),%r15
mov    %rsp,%r14
lea    0xec4(%rip),%r12
sub    $0x1,%ebx
jae    1170 <main+0x50>
nopl   (%rax)
mov    %r14,%rdi
jmp    1172 <main+0x52>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     1191 <main+0x71>
mov    %r12,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
sub    $0x1,%ebx
jae    1170 <main+0x50>
jmp    1160 <main+0x40>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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"
define i32 @main() {
%1 = alloca i32
%2 = alloca [24 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [24 x i8]* %2 to i8*
store i8* null, i8** %3
store i32 0, i32* %4
br label %6
6: ; preds = %23, %0
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%11 = call i8* @strtok(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %3
br label %14
12: ; preds = %6
%13 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %3
br label %14
14: ; preds = %12, %9
%15 = load i8*, i8** %3
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i8*, i8** %3
%19 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %23
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = icmp ne i8* %24, null
br i1 %25, label %6, label %26
26: ; preds = %23
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"
define i32 @main() {
%1 = alloca [24 x i8]
%2 = getelementptr inbounds [24 x i8], [24 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %13, %0
%4 = phi i32 [ 0, %0 ], [ %15, %13 ]
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = call i8* @strtok(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %10
8: ; preds = %3
%9 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
%11 = phi i8* [ %7, %6 ], [ %9, %8 ]
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%15 = add nuw nsw i32 %4, 1
br label %3
16: ; preds = %10
ret i32 0
}