#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 *copy_nstring(char *, int);
char *drop_leading_whitespace(char *);
char *find_next(char *, scalar_t__ (*)(char *));
scalar_t__ isDelim(char *);
char *next_token(char **str) {
  if (str == NULL || *str == NULL)
    return NULL;
  char *start = drop_leading_whitespace(*str);
  if (*start == '\0')
    return NULL;
  if (isDelim(start)) {
    *str = start + 1;
    return copy_nstring(start, 1);
  } else {
    *str = find_next(start, isDelim);
    return copy_nstring(start, (*str - start));
  }
}


x86 assembly (clang, -O0):
<next_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1155 <next_token+0x25>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1162 <next_token+0x32>
movq   $0x0,-0x8(%rbp)
jmp    11ff <next_token+0xcf>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <drop_leading_whitespace@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    118f <next_token+0x5f>
movq   $0x0,-0x8(%rbp)
jmp    11ff <next_token+0xcf>
mov    -0x18(%rbp),%rdi
call   1060 <isDelim@plt>
cmp    $0x0,%rax
je     11c8 <next_token+0x98>
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1040 <copy_nstring@plt>
mov    %rax,-0x8(%rbp)
jmp    11ff <next_token+0xcf>
mov    -0x18(%rbp),%rdi
mov    0x2e15(%rip),%rsi
call   1050 <find_next@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1040 <copy_nstring@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_token>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     116f <next_token+0x3f>
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     116f <next_token+0x3f>
call   1030 <drop_leading_whitespace@plt>
cmpb   $0x0,(%rax)
je     116f <next_token+0x3f>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <isDelim@plt>
test   %rax,%rax
je     1179 <next_token+0x49>
mov    %r14,%rax
add    $0x1,%rax
mov    %rax,(%rbx)
mov    $0x1,%esi
jmp    1191 <next_token+0x61>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e68(%rip),%rsi
mov    %r14,%rdi
call   1050 <find_next@plt>
mov    %rax,%rsi
mov    %rax,(%rbx)
sub    %r14d,%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <copy_nstring@plt>

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

LLVM IR (-O2):
define i8* @next_token(i8** %0) {
%2 = icmp eq i8** %0, null
br i1 %2, label %24, label %3
3: ; preds = %1
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = tail call i8* @drop_leading_whitespace(i8* %4)
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %24, label %10
10: ; preds = %6
%11 = tail call i64 @isDelim(i8* %7)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %7, i64 1
store i8* %14, i8** %0
br label %21
15: ; preds = %10
%16 = tail call i8* @find_next(i8* %7, i64 (i8*)* @isDelim)
store i8* %16, i8** %0
%17 = ptrtoint i8* %16 to i64
%18 = ptrtoint i8* %7 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
br label %21
21: ; preds = %15, %13
%22 = phi i32 [ 1, %13 ], [ %20, %15 ]
%23 = tail call i8* @copy_nstring(i8* %7, i32 %22)
br label %24
24: ; preds = %21, %6, %1, %3
%25 = phi i8* [ null, %3 ], [ null, %1 ], [ null, %6 ], [ %23, %21 ]
ret i8* %25
}