#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 */
char *strchr(char *, char);
char *strsep(char **, char const *);
char *_strtok(char *input, const char *delim) {
  static char *position = NULL;
  char *token;
  if (input != NULL)
    position = input;
  token = strsep(&position, delim);
  if (token) {
    char *pos = strchr(token, '\n');
    if (pos)
      *pos = '\0';
  }
  return token;
}


x86 assembly (clang, -O0):
<_strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1146 <_strtok+0x26>
mov    -0x8(%rbp),%rax
mov    %rax,0x2ef2(%rip)
mov    -0x10(%rbp),%rsi
lea    0x2ee7(%rip),%rdi
call   1040 <strsep@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118e <_strtok+0x6e>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1189 <_strtok+0x69>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    118e <_strtok+0x6e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_strtok>:
push   %rbx
test   %rdi,%rdi
je     112d <_strtok+0xd>
mov    %rdi,0x2f0b(%rip)
lea    0x2f04(%rip),%rdi
call   1040 <strsep@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1156 <_strtok+0x36>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1156 <_strtok+0x36>
movb   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@_strtok.position = internal global i8* null
define i8* @_strtok(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load i8*, i8** %3
store i8* %10, i8** @_strtok.position
br label %11
11: ; preds = %9, %2
%12 = load i8*, i8** %4
%13 = call i8* @strsep(i8** @_strtok.position, i8* %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = call i8* @strchr(i8* %17, i8 signext 10)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i8*, i8** %6
store i8 0, i8* %22
br label %23
23: ; preds = %21, %16
br label %24
24: ; preds = %23, %11
%25 = load i8*, i8** %5
ret i8* %25
}

LLVM IR (-O2):
@_strtok.position = internal global i8* null
define i8* @_strtok(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %5, label %4
4: ; preds = %2
store i8* %0, i8** @_strtok.position
br label %5
5: ; preds = %4, %2
%6 = tail call i8* @strsep(i8** @_strtok.position, i8* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call i8* @strchr(i8* %6, i8 signext 10)
%10 = icmp eq i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %8
store i8 0, i8* %9
br label %12
12: ; preds = %8, %11, %5
ret i8* %6
}