#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*/ memcpy(char *, char const *, size_t const);
char *next_separator(char const *);
char *next_token(char const *);
const char *get_next_token(const char *str, char *token, size_t size) {
  const char *start = next_token(str);
  const char *end = next_separator(start);
  if (start != end) {
    const size_t to_copy =
        ((((size_t)(end - start)) < ((size - 1))) ? (size_t)(end - start)
                                                  : (size - 1));
    memcpy(token, start, to_copy);
    token[to_copy] = '\0';
    return start;
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<get_next_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <next_token@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <next_separator@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     11da <get_next_token+0xaa>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    119c <get_next_token+0x6c>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
jmp    11a8 <get_next_token+0x78>
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e2 <get_next_token+0xb2>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_token>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
call   1050 <next_token@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <next_separator@plt>
cmp    %rax,%rbx
je     1173 <get_next_token+0x43>
sub    %rbx,%rax
add    $0xffffffffffffffff,%r14
cmp    %r14,%rax
cmovb  %rax,%r14
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%r15,%r14,1)
jmp    1175 <get_next_token+0x45>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @get_next_token(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%11 = load i8*, i8** %5
%12 = call i8* @next_token(i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = call i8* @next_separator(i8* %13)
store i8* %14, i8** %9
%15 = load i8*, i8** %8
%16 = load i8*, i8** %9
%17 = icmp ne i8* %15, %16
br i1 %17, label %18, label %46
18: ; preds = %3
%19 = load i8*, i8** %9
%20 = load i8*, i8** %8
%21 = ptrtoint i8* %19 to i64
%22 = ptrtoint i8* %20 to i64
%23 = sub i64 %21, %22
%24 = load i64, i64* %7
%25 = sub i64 %24, 1
%26 = icmp ult i64 %23, %25
br i1 %26, label %27, label %33
27: ; preds = %18
%28 = load i8*, i8** %9
%29 = load i8*, i8** %8
%30 = ptrtoint i8* %28 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
br label %36
33: ; preds = %18
%34 = load i64, i64* %7
%35 = sub i64 %34, 1
br label %36
36: ; preds = %33, %27
%37 = phi i64 [ %32, %27 ], [ %35, %33 ]
store i64 %37, i64* %10
%38 = load i8*, i8** %6
%39 = load i8*, i8** %8
%40 = load i64, i64* %10
%41 = call i32 @memcpy(i8* %38, i8* %39, i64 %40)
%42 = load i8*, i8** %6
%43 = load i64, i64* %10
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8 0, i8* %44
%45 = load i8*, i8** %8
store i8* %45, i8** %4
br label %47
46: ; preds = %3
store i8* null, i8** %4
br label %47
47: ; preds = %46, %36
%48 = load i8*, i8** %4
ret i8* %48
}

LLVM IR (-O2):
define i8* @get_next_token(i8* %0, i8* %1, i64 %2) {
%4 = tail call i8* @next_token(i8* %0)
%5 = tail call i8* @next_separator(i8* %4)
%6 = icmp eq i8* %4, %5
br i1 %6, label %16, label %7
7: ; preds = %3
%8 = ptrtoint i8* %5 to i64
%9 = ptrtoint i8* %4 to i64
%10 = sub i64 %8, %9
%11 = add i64 %2, -1
%12 = icmp ult i64 %10, %11
%13 = select i1 %12, i64 %10, i64 %11
%14 = tail call i32 @memcpy(i8* %1, i8* %4, i64 %13)
%15 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 0, i8* %15
br label %16
16: ; preds = %3, %7
%17 = phi i8* [ %4, %7 ], [ null, %3 ]
ret i8* %17
}