#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 *extract_token(char const *, size_t);
size_t find_token_end(char const *);
char *move_to_next_token(char const *);
const char *read_token(const char *s, char **token) {
  size_t l;
  *token = NULL;
  s = move_to_next_token(s);
  if ((s == NULL) || (*s == '\0'))
    return NULL;
  l = find_token_end(s);
  *token = extract_token(s, l);
  return (s + l);
}


x86 assembly (clang, -O0):
<read_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <move_to_next_token@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1173 <read_token+0x43>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1180 <read_token+0x50>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <read_token+0x80>
mov    -0x10(%rbp),%rdi
call   1040 <find_token_end@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <extract_token@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_token>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
movq   $0x0,(%rsi)
call   1050 <move_to_next_token@plt>
test   %rax,%rax
je     116f <read_token+0x3f>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     116f <read_token+0x3f>
mov    %rbx,%rdi
call   1040 <find_token_end@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <extract_token@plt>
mov    %rax,(%r14)
add    %r15,%rbx
jmp    1171 <read_token+0x41>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @read_token(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
store i8* null, i8** %7
%8 = load i8*, i8** %4
%9 = call i8* @move_to_next_token(i8* %8)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i8*, i8** %4
%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 = %12, %2
store i8* null, i8** %3
br label %28
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = call i64 @find_token_end(i8* %19)
store i64 %20, i64* %6
%21 = load i8*, i8** %4
%22 = load i64, i64* %6
%23 = call i8* @extract_token(i8* %21, i64 %22)
%24 = load i8**, i8*** %5
store i8* %23, i8** %24
%25 = load i8*, i8** %4
%26 = load i64, i64* %6
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8* %27, i8** %3
br label %28
28: ; preds = %18, %17
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
define i8* @read_token(i8* %0, i8** nocapture writeonly %1) {
store i8* null, i8** %1
%3 = tail call i8* @move_to_next_token(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call i64 @find_token_end(i8* %3)
%10 = tail call i8* @extract_token(i8* %3, i64 %9)
store i8* %10, i8** %1
%11 = getelementptr inbounds i8, i8* %3, i64 %9
br label %12
12: ; preds = %2, %5, %8
%13 = phi i8* [ %11, %8 ], [ null, %5 ], [ null, %2 ]
ret i8* %13
}