#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 *cc_skip_chars(char const *, char const *);
char *cc_stop_at_chars(char const *, char const *);
char *malloc(size_t);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *cc_next_token_new(char const *const restrict str_s,
                        char const *const restrict seps_s) {
  static char const *start = NULL;
  static char const *end = NULL;
  static char const *sps = NULL;
  if (str_s)
    start = str_s;
  else {
    if (!end)
      return NULL;
    start = end + 1;
  }
  if (seps_s)
    sps = seps_s;
  start = cc_skip_chars(start, sps);
  end = cc_stop_at_chars(start, sps);
  if (end == start)
    return NULL;
  size_t len = end - start;
  char *pos = malloc(len + 1);
  if (!pos)
    return NULL;
  strncpy(pos, start, len);
  pos[len] = '\0';
  return pos;
}


x86 assembly (clang, -O0):
<cc_next_token_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116b <cc_next_token_new+0x2b>
mov    -0x10(%rbp),%rax
mov    %rax,0x2ee2(%rip)
jmp    1198 <cc_next_token_new+0x58>
cmpq   $0x0,0x2edd(%rip)
jne    1186 <cc_next_token_new+0x46>
movq   $0x0,-0x8(%rbp)
jmp    1269 <cc_next_token_new+0x129>
mov    0x2ec3(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2eb0(%rip)
cmpq   $0x0,-0x18(%rbp)
je     11ae <cc_next_token_new+0x6e>
mov    -0x18(%rbp),%rax
mov    %rax,0x2eaa(%rip)
mov    0x2e93(%rip),%rdi
mov    0x2e9c(%rip),%rsi
call   1040 <cc_skip_chars@plt>
mov    %rax,0x2e80(%rip)
mov    0x2e79(%rip),%rdi
mov    0x2e82(%rip),%rsi
call   1050 <cc_stop_at_chars@plt>
mov    %rax,0x2e6e(%rip)
mov    0x2e67(%rip),%rax
cmp    0x2e58(%rip),%rax
jne    1203 <cc_next_token_new+0xc3>
movq   $0x0,-0x8(%rbp)
jmp    1269 <cc_next_token_new+0x129>
mov    0x2e46(%rip),%rax
mov    0x2e37(%rip),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1241 <cc_next_token_new+0x101>
movq   $0x0,-0x8(%rbp)
jmp    1269 <cc_next_token_new+0x129>
mov    -0x28(%rbp),%rdi
mov    0x2dfc(%rip),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cc_next_token_new>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
jne    115a <cc_next_token_new+0x1a>
mov    0x2eff(%rip),%rdi
test   %rdi,%rdi
je     11cd <cc_next_token_new+0x8d>
add    $0x1,%rdi
mov    %rdi,0x2ee7(%rip)
test   %rsi,%rsi
je     116f <cc_next_token_new+0x2f>
mov    %rsi,0x2eeb(%rip)
jmp    1176 <cc_next_token_new+0x36>
mov    0x2ee2(%rip),%rsi
call   1040 <cc_skip_chars@plt>
mov    %rax,0x2ec6(%rip)
mov    0x2ecf(%rip),%rsi
mov    %rax,%rdi
call   1050 <cc_stop_at_chars@plt>
mov    %rax,%rbx
mov    %rax,0x2eb5(%rip)
mov    0x2ea6(%rip),%r15
sub    %r15,%rbx
je     11cd <cc_next_token_new+0x8d>
lea    0x1(%rbx),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11cd <cc_next_token_new+0x8d>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
jmp    11d0 <cc_next_token_new+0x90>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@cc_next_token_new.start = internal global i8* null
@cc_next_token_new.end = internal global i8* null
@cc_next_token_new.sps = internal global i8* null
define i8* @cc_next_token_new(i8* noalias %0, i8* noalias %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i8*, i8** %4
store i8* %11, i8** @cc_next_token_new.start
br label %19
12: ; preds = %2
%13 = load i8*, i8** @cc_next_token_new.end
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12
store i8* null, i8** %3
br label %56
16: ; preds = %12
%17 = load i8*, i8** @cc_next_token_new.end
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** @cc_next_token_new.start
br label %19
19: ; preds = %16, %10
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i8*, i8** %5
store i8* %23, i8** @cc_next_token_new.sps
br label %24
24: ; preds = %22, %19
%25 = load i8*, i8** @cc_next_token_new.start
%26 = load i8*, i8** @cc_next_token_new.sps
%27 = call i8* @cc_skip_chars(i8* %25, i8* %26)
store i8* %27, i8** @cc_next_token_new.start
%28 = load i8*, i8** @cc_next_token_new.start
%29 = load i8*, i8** @cc_next_token_new.sps
%30 = call i8* @cc_stop_at_chars(i8* %28, i8* %29)
store i8* %30, i8** @cc_next_token_new.end
%31 = load i8*, i8** @cc_next_token_new.end
%32 = load i8*, i8** @cc_next_token_new.start
%33 = icmp eq i8* %31, %32
br i1 %33, label %34, label %35
34: ; preds = %24
store i8* null, i8** %3
br label %56
35: ; preds = %24
%36 = load i8*, i8** @cc_next_token_new.end
%37 = load i8*, i8** @cc_next_token_new.start
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
store i64 %40, i64* %6
%41 = load i64, i64* %6
%42 = add i64 %41, 1
%43 = call i8* @malloc(i64 %42)
store i8* %43, i8** %7
%44 = load i8*, i8** %7
%45 = icmp ne i8* %44, null
br i1 %45, label %47, label %46
46: ; preds = %35
store i8* null, i8** %3
br label %56
47: ; preds = %35
%48 = load i8*, i8** %7
%49 = load i8*, i8** @cc_next_token_new.start
%50 = load i64, i64* %6
%51 = call i32 @strncpy(i8* %48, i8* %49, i64 %50)
%52 = load i8*, i8** %7
%53 = load i64, i64* %6
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8 0, i8* %54
%55 = load i8*, i8** %7
store i8* %55, i8** %3
br label %56
56: ; preds = %47, %46, %34, %15
%57 = load i8*, i8** %3
ret i8* %57
}

LLVM IR (-O2):
@cc_next_token_new.start = internal unnamed_addr global i8* null
@cc_next_token_new.end = internal unnamed_addr global i8* null
@cc_next_token_new.sps = internal unnamed_addr global i8* null
define i8* @cc_next_token_new(i8* noalias %0, i8* noalias %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i8*, i8** @cc_next_token_new.end
%6 = icmp eq i8* %5, null
br i1 %6, label %32, label %7
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 1
br label %9
9: ; preds = %2, %7
%10 = phi i8* [ %8, %7 ], [ %0, %2 ]
store i8* %10, i8** @cc_next_token_new.start
%11 = icmp eq i8* %1, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = load i8*, i8** @cc_next_token_new.sps
br label %15
14: ; preds = %9
store i8* %1, i8** @cc_next_token_new.sps
br label %15
15: ; preds = %12, %14
%16 = phi i8* [ %13, %12 ], [ %1, %14 ]
%17 = tail call i8* @cc_skip_chars(i8* %10, i8* %16)
store i8* %17, i8** @cc_next_token_new.start
%18 = load i8*, i8** @cc_next_token_new.sps
%19 = tail call i8* @cc_stop_at_chars(i8* %17, i8* %18)
store i8* %19, i8** @cc_next_token_new.end
%20 = load i8*, i8** @cc_next_token_new.start
%21 = icmp eq i8* %19, %20
br i1 %21, label %32, label %22
22: ; preds = %15
%23 = ptrtoint i8* %19 to i64
%24 = ptrtoint i8* %20 to i64
%25 = sub i64 %23, %24
%26 = add i64 %25, 1
%27 = tail call i8* @malloc(i64 %26)
%28 = icmp eq i8* %27, null
br i1 %28, label %32, label %29
29: ; preds = %22
%30 = tail call i32 @strncpy(i8* %27, i8* %20, i64 %25)
%31 = getelementptr inbounds i8, i8* %27, i64 %25
store i8 0, i8* %31
br label %32
32: ; preds = %29, %22, %15, %4
%33 = phi i8* [ null, %4 ], [ null, %15 ], [ %27, %29 ], [ null, %22 ]
ret i8* %33
}