char *find_next_token(ptr, lengthptr)
char **ptr;
unsigned int *lengthptr;
{
  char *p = next_token(*ptr);
  char *end;
  if (*p == '\0')
    return 0;
  *ptr = end = end_of_token(p);
  if (lengthptr != 0)
    *lengthptr = end - p;
  return p;
}


x86 assembly (clang, -O0):
<find_next_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x0,%al
call   1030 <next_token@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1161 <find_next_token+0x41>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <find_next_token+0x80>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1040 <end_of_token@plt>
movslq %eax,%rcx
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     1198 <find_next_token+0x78>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_next_token>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1030 <next_token@plt>
movslq %eax,%rbx
cmpb   $0x0,(%rbx)
je     1160 <find_next_token+0x40>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <end_of_token@plt>
movslq %eax,%rcx
mov    %rcx,(%r15)
test   %r14,%r14
je     115d <find_next_token+0x3d>
sub    %ebx,%eax
mov    %eax,(%r14)
mov    %rbx,%r12
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @find_next_token(i8** %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
store i8** %0, i8*** %4
store i32* %1, i32** %5
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
%10 = call i32 (i8*, ...) bitcast (i32 (...)* @next_token to i32 (i8*, ...)*)(i8* %9)
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %2
store i8* null, i8** %3
br label %36
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @end_of_token to i32 (i8*, ...)*)(i8* %19)
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %7
%23 = load i8**, i8*** %4
store i8* %22, i8** %23
%24 = load i32*, i32** %5
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %34
26: ; preds = %18
%27 = load i8*, i8** %7
%28 = load i8*, i8** %6
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = trunc i64 %31 to i32
%33 = load i32*, i32** %5
store i32 %32, i32* %33
br label %34
34: ; preds = %26, %18
%35 = load i8*, i8** %6
store i8* %35, i8** %3
br label %36
36: ; preds = %34, %17
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
define i8* @find_next_token(i8** nocapture %0, i32* writeonly %1) {
%3 = load i8*, i8** %0
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @next_token to i32 (i8*, ...)*)(i8* %3)
%5 = sext i32 %4 to i64
%6 = inttoptr i64 %5 to i8*
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = tail call i32 (i8*, ...) bitcast (i32 (...)* @end_of_token to i32 (i8*, ...)*)(i8* %6)
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %0
%13 = icmp eq i32* %1, null
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = sub i32 %10, %4
store i32 %15, i32* %1
br label %16
16: ; preds = %9, %14, %2
%17 = phi i8* [ null, %2 ], [ %6, %14 ], [ %6, %9 ]
ret i8* %17
}