#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 *kcm_skip_non_spaces(char const *);
char *kcm_skip_spaces(char const *);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
const char *kcm_get_token(const char *line, char *token, size_t max_token_len) {
  const char *token_starts = kcm_skip_spaces(line);
  const char *token_ends = kcm_skip_non_spaces(token_starts);
  size_t token_len = token_ends - token_starts;
  if ((0 == token_len) || (token_len >= max_token_len)) {
    return NULL;
  }
  memcpy(token, token_starts, token_len);
  token[token_len] = '\0';
  return token_ends;
}


x86 assembly (clang, -O0):
<kcm_get_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   1040 <kcm_skip_spaces@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <kcm_skip_non_spaces@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
je     1187 <kcm_get_token+0x57>
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     1194 <kcm_get_token+0x64>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <kcm_get_token+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kcm_get_token>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
call   1040 <kcm_skip_spaces@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1030 <kcm_skip_non_spaces@plt>
mov    %rax,%r15
xor    %eax,%eax
mov    %r15,%rbx
sub    %r13,%rbx
je     1177 <kcm_get_token+0x47>
cmp    %r12,%rbx
jae    1177 <kcm_get_token+0x47>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
movb   $0x0,(%r14,%rbx,1)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @kcm_get_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* @kcm_skip_spaces(i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = call i8* @kcm_skip_non_spaces(i8* %13)
store i8* %14, i8** %9
%15 = load i8*, i8** %9
%16 = load i8*, i8** %8
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
store i64 %19, i64* %10
%20 = load i64, i64* %10
%21 = icmp eq i64 0, %20
br i1 %21, label %26, label %22
22: ; preds = %3
%23 = load i64, i64* %10
%24 = load i64, i64* %7
%25 = icmp uge i64 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22, %3
store i8* null, i8** %4
br label %36
27: ; preds = %22
%28 = load i8*, i8** %6
%29 = load i8*, i8** %8
%30 = load i64, i64* %10
%31 = call i32 @memcpy(i8* %28, i8* %29, i64 %30)
%32 = load i8*, i8** %6
%33 = load i64, i64* %10
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %9
store i8* %35, i8** %4
br label %36
36: ; preds = %27, %26
%37 = load i8*, i8** %4
ret i8* %37
}

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