#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 */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strip_whitespace(char *);
int /*<<< orphan*/ valid_word_char(char);
int /*<<< orphan*/ valid_word_first_char(char);
char *tokenizer_next_word(char *input_p) {
  char *word, *input;
  assert(input_p != NULL);
  word = input = input_p;
  if (*input == 0)
    return NULL;
  if (!valid_word_first_char(*input)) {
    fprintf(stderr, "Letter expected\n");
    return NULL;
  }
  while (*++input != 0) {
    if (isspace(*input)) {
      *input = 0;
      strip_whitespace(++input);
      break;
    }
    if (!valid_word_char(*input)) {
      input_p = input;
      fprintf(stderr, "Invalid word character\n");
      return NULL;
    }
  }
  input_p = input;
  return word;
}


x86 assembly (clang, -O0):
<tokenizer_next_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a7 <tokenizer_next_word+0x47>
movq   $0x0,-0x8(%rbp)
jmp    1286 <tokenizer_next_word+0x126>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <valid_word_first_char@plt>
cmp    $0x0,%eax
jne    11de <tokenizer_next_word+0x7e>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1286 <tokenizer_next_word+0x126>
jmp    11e3 <tokenizer_next_word+0x83>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1276 <tokenizer_next_word+0x116>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     1232 <tokenizer_next_word+0xd2>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x20(%rbp)
call   1040 <strip_whitespace@plt>
jmp    1276 <tokenizer_next_word+0x116>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1060 <valid_word_char@plt>
cmp    $0x0,%eax
jne    1271 <tokenizer_next_word+0x111>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1286 <tokenizer_next_word+0x126>
jmp    11e3 <tokenizer_next_word+0x83>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenizer_next_word>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1070 <assert@plt>
mov    (%r14),%al
test   %al,%al
je     11dd <tokenizer_next_word+0x7d>
movsbl %al,%edi
call   1030 <valid_word_first_char@plt>
test   %eax,%eax
je     11c8 <tokenizer_next_word+0x68>
lea    0x2(%r14),%rbx
nopl   0x0(%rax)
movzbl -0x1(%rbx),%eax
test   %al,%al
je     11e0 <tokenizer_next_word+0x80>
movsbl %al,%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    11eb <tokenizer_next_word+0x8b>
movsbl -0x1(%rbx),%edi
call   1060 <valid_word_char@plt>
add    $0x1,%rbx
test   %eax,%eax
jne    1190 <tokenizer_next_word+0x30>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
jmp    11d8 <tokenizer_next_word+0x78>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
call   1080 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movb   $0x0,-0x1(%rbx)
mov    %rbx,%rdi
call   1040 <strip_whitespace@plt>
jmp    11e0 <tokenizer_next_word+0x80>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"Letter expected\0A\00"
@.str.1 = [24 x i8] c"Invalid word character\0A\00"
define i8* @tokenizer_next_word(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %3
store i8* %10, i8** %5
store i8* %10, i8** %4
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
store i8* null, i8** %2
br label %54
16: ; preds = %1
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = call i32 @valid_word_first_char(i8 signext %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %54
24: ; preds = %16
br label %25
25: ; preds = %50, %24
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %51
31: ; preds = %25
%32 = load i8*, i8** %5
%33 = load i8, i8* %32
%34 = call i64 @isspace(i8 signext %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %31
%37 = load i8*, i8** %5
store i8 0, i8* %37
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %5
%40 = call i32 @strip_whitespace(i8* %39)
br label %51
41: ; preds = %31
%42 = load i8*, i8** %5
%43 = load i8, i8* %42
%44 = call i32 @valid_word_char(i8 signext %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %41
%47 = load i8*, i8** %5
store i8* %47, i8** %3
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %54
50: ; preds = %41
br label %25
51: ; preds = %36, %25
%52 = load i8*, i8** %5
store i8* %52, i8** %3
%53 = load i8*, i8** %4
store i8* %53, i8** %2
br label %54
54: ; preds = %51, %46, %21, %15
%55 = load i8*, i8** %2
ret i8* %55
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"Letter expected\0A\00"
@.str.1 = [24 x i8] c"Invalid word character\0A\00"
define i8* @tokenizer_next_word(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %31, label %7
7: ; preds = %1
%8 = tail call i32 @valid_word_first_char(i8 signext %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %31
13: ; preds = %7, %24
%14 = phi i8* [ %15, %24 ], [ %0, %7 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %31, label %18
18: ; preds = %13
%19 = tail call i64 @isspace(i8 signext %16)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
store i8 0, i8* %15
%22 = getelementptr inbounds i8, i8* %14, i64 2
%23 = tail call i32 @strip_whitespace(i8* %22)
br label %31
24: ; preds = %18
%25 = load i8, i8* %15
%26 = tail call i32 @valid_word_char(i8 signext %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %13
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %13, %21, %1, %28, %10
%32 = phi i8* [ null, %28 ], [ null, %10 ], [ null, %1 ], [ %0, %21 ], [ %0, %13 ]
ret i8* %32
}