#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 *end_of_token(char const *);
char *next_token(char const *);
char *find_next_token(const char **ptr, unsigned int *lengthptr) {
  const char *p = next_token(*ptr);
  if (*p == '\0')
    return 0;
  *ptr = end_of_token(p);
  if (lengthptr != 0)
    *lengthptr = *ptr - p;
  return (char *)p;
}


x86 assembly (clang, -O0):
<find_next_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <next_token@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    115d <find_next_token+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    1199 <find_next_token+0x79>
mov    -0x20(%rbp),%rdi
call   1040 <end_of_token@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     1191 <find_next_token+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%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    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_next_token>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
call   1030 <next_token@plt>
cmpb   $0x0,(%rax)
je     1152 <find_next_token+0x32>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <end_of_token@plt>
mov    %rax,(%r15)
test   %r14,%r14
je     1154 <find_next_token+0x34>
sub    %ebx,%eax
mov    %eax,(%r14)
jmp    1154 <find_next_token+0x34>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
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*
store i8** %0, i8*** %4
store i32* %1, i32** %5
%7 = load i8**, i8*** %4
%8 = load i8*, i8** %7
%9 = call i8* @next_token(i8* %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i8* null, i8** %3
br label %32
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = call i8* @end_of_token(i8* %16)
%18 = load i8**, i8*** %4
store i8* %17, i8** %18
%19 = load i32*, i32** %5
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %30
21: ; preds = %15
%22 = load i8**, i8*** %4
%23 = load i8*, i8** %22
%24 = load i8*, i8** %6
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = load i32*, i32** %5
store i32 %28, i32* %29
br label %30
30: ; preds = %21, %15
%31 = load i8*, i8** %6
store i8* %31, i8** %3
br label %32
32: ; preds = %30, %14
%33 = load i8*, i8** %3
ret i8* %33
}

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