#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 */
struct stream {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ next_char(struct stream *);
int peek_char(struct stream *);
int /*<<< orphan*/ skip_whitespace(struct stream *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, int);
int next_word(struct stream *s, char *buffer, size_t size) {
  skip_whitespace(s);
  int ch = peek_char(s);
  switch (ch) {
  case '(':
  case ')':
  case '{':
  case '}':
  case ';':
  case ',':
    next_char(s);
    snprintf(buffer, size, "%c", ch);
    return 1;
  case 0:
    return 0;
  }
  next_char(s);
  *(buffer++) = ch;
  size--;
  while ((size > 1) && (ch = peek_char(s))) {
    int num = ch >= '0' && ch <= '9';
    int lowal = ch >= 'a' && ch <= 'z';
    int upal = ch >= 'A' && ch <= 'Z';
    int under = ch == '_';
    if (!num && !lowal && !upal && !under)
      break;
    *(buffer++) = next_char(s);
    size--;
  }
  *(buffer++) = '\0';
  size--;
  return 1;
}


x86 assembly (clang, -O0):
<next_word>:
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   1050 <skip_whitespace@plt>
mov    -0x10(%rbp),%rdi
call   1060 <peek_char@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
test   %eax,%eax
je     1200 <next_word+0xc0>
jmp    117c <next_word+0x3c>
mov    -0x38(%rbp),%eax
add    $0xffffffd8,%eax
sub    $0x2,%eax
jb     11d4 <next_word+0x94>
jmp    1190 <next_word+0x50>
mov    -0x38(%rbp),%eax
sub    $0x2c,%eax
je     11d4 <next_word+0x94>
jmp    11a1 <next_word+0x61>
mov    -0x38(%rbp),%eax
sub    $0x3b,%eax
je     11d4 <next_word+0x94>
jmp    11b2 <next_word+0x72>
mov    -0x38(%rbp),%eax
sub    $0x7b,%eax
je     11d4 <next_word+0x94>
jmp    11c3 <next_word+0x83>
mov    -0x38(%rbp),%eax
sub    $0x7d,%eax
jne    120c <next_word+0xcc>
jmp    11d4 <next_word+0x94>
mov    -0x10(%rbp),%rdi
call   1030 <next_char@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%ecx
lea    0xe11(%rip),%rdx
call   1040 <snprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1366 <next_word+0x226>
movl   $0x0,-0x4(%rbp)
jmp    1366 <next_word+0x226>
mov    -0x10(%rbp),%rdi
call   1030 <next_char@plt>
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x1,-0x20(%rbp)
mov    %al,-0x39(%rbp)
jbe    125c <next_word+0x11c>
mov    -0x10(%rbp),%rdi
call   1060 <peek_char@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    126c <next_word+0x12c>
jmp    1341 <next_word+0x201>
xor    %eax,%eax
cmpl   $0x30,-0x24(%rbp)
mov    %al,-0x3a(%rbp)
jl     1285 <next_word+0x145>
cmpl   $0x39,-0x24(%rbp)
setle  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
xor    %eax,%eax
cmpl   $0x61,-0x24(%rbp)
mov    %al,-0x3b(%rbp)
jl     12a9 <next_word+0x169>
cmpl   $0x7a,-0x24(%rbp)
setle  %al
mov    %al,-0x3b(%rbp)
mov    -0x3b(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmpl   $0x41,-0x24(%rbp)
mov    %al,-0x3c(%rbp)
jl     12cd <next_word+0x18d>
cmpl   $0x5a,-0x24(%rbp)
setle  %al
mov    %al,-0x3c(%rbp)
mov    -0x3c(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x5f,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1314 <next_word+0x1d4>
cmpl   $0x0,-0x2c(%rbp)
jne    1314 <next_word+0x1d4>
cmpl   $0x0,-0x30(%rbp)
jne    1314 <next_word+0x1d4>
cmpl   $0x0,-0x34(%rbp)
jne    1314 <next_word+0x1d4>
jmp    1341 <next_word+0x201>
mov    -0x10(%rbp),%rdi
call   1030 <next_char@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1237 <next_word+0xf7>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_word>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <skip_whitespace@plt>
mov    %r15,%rdi
call   1060 <peek_char@plt>
mov    %eax,%ebp
cmp    $0x3b,%eax
ja     117b <next_word+0x3b>
mov    %ebp,%eax
movabs $0x800130000000000,%rcx
bt     %rax,%rcx
jb     1185 <next_word+0x45>
test   %rax,%rax
je     11a6 <next_word+0x66>
cmp    $0x7d,%ebp
je     1185 <next_word+0x45>
cmp    $0x7b,%ebp
jne    11b3 <next_word+0x73>
mov    %r15,%rdi
call   1030 <next_char@plt>
lea    0xe6c(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1030 <next_char@plt>
mov    %bpl,(%r14)
add    $0x1,%r14
add    $0xffffffffffffffff,%rbx
cmp    $0x2,%rbx
jae    11e9 <next_word+0xa9>
jmp    1212 <next_word+0xd2>
xchg   %ax,%ax
mov    %r15,%rdi
call   1030 <next_char@plt>
mov    %al,(%r14)
add    $0x1,%r14
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    1212 <next_word+0xd2>
mov    %r15,%rdi
call   1060 <peek_char@plt>
test   %eax,%eax
je     1212 <next_word+0xd2>
lea    -0x30(%rax),%ecx
cmp    $0xa,%ecx
jb     11d0 <next_word+0x90>
lea    -0x61(%rax),%ecx
cmp    $0x1a,%ecx
jb     11d0 <next_word+0x90>
lea    -0x41(%rax),%ecx
cmp    $0x1a,%ecx
jb     11d0 <next_word+0x90>
cmp    $0x5f,%eax
je     11d0 <next_word+0x90>
movb   $0x0,(%r14)
jmp    11a1 <next_word+0x61>

LLVM IR (-O0):
%struct.stream = type { i32 }
@.str = [3 x i8] c"%c\00"
define i32 @next_word(%struct.stream* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.stream*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store %struct.stream* %0, %struct.stream** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%13 = load %struct.stream*, %struct.stream** %5
%14 = call i32 @skip_whitespace(%struct.stream* %13)
%15 = load %struct.stream*, %struct.stream** %5
%16 = call i32 @peek_char(%struct.stream* %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
switch i32 %17, label %26 [
i32 40, label %18
i32 41, label %18
i32 123, label %18
i32 125, label %18
i32 59, label %18
i32 44, label %18
i32 0, label %25
]
18: ; preds = %3, %3, %3, %3, %3, %3
%19 = load %struct.stream*, %struct.stream** %5
%20 = call i32 @next_char(%struct.stream* %19)
%21 = load i8*, i8** %6
%22 = load i64, i64* %7
%23 = load i32, i32* %8
%24 = call i32 @snprintf(i8* %21, i64 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %23)
store i32 1, i32* %4
br label %97
25: ; preds = %3
store i32 0, i32* %4
br label %97
26: ; preds = %3
%27 = load %struct.stream*, %struct.stream** %5
%28 = call i32 @next_char(%struct.stream* %27)
%29 = load i32, i32* %8
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %6
store i8 %30, i8* %31
%33 = load i64, i64* %7
%34 = add i64 %33, -1
store i64 %34, i64* %7
br label %35
35: ; preds = %84, %26
%36 = load i64, i64* %7
%37 = icmp ugt i64 %36, 1
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load %struct.stream*, %struct.stream** %5
%40 = call i32 @peek_char(%struct.stream* %39)
store i32 %40, i32* %8
%41 = icmp ne i32 %40, 0
br label %42
42: ; preds = %38, %35
%43 = phi i1 [ false, %35 ], [ %41, %38 ]
br i1 %43, label %44, label %92
44: ; preds = %42
%45 = load i32, i32* %8
%46 = icmp sge i32 %45, 48
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* %8
%49 = icmp sle i32 %48, 57
br label %50
50: ; preds = %47, %44
%51 = phi i1 [ false, %44 ], [ %49, %47 ]
%52 = zext i1 %51 to i32
store i32 %52, i32* %9
%53 = load i32, i32* %8
%54 = icmp sge i32 %53, 97
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = load i32, i32* %8
%57 = icmp sle i32 %56, 122
br label %58
58: ; preds = %55, %50
%59 = phi i1 [ false, %50 ], [ %57, %55 ]
%60 = zext i1 %59 to i32
store i32 %60, i32* %10
%61 = load i32, i32* %8
%62 = icmp sge i32 %61, 65
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = load i32, i32* %8
%65 = icmp sle i32 %64, 90
br label %66
66: ; preds = %63, %58
%67 = phi i1 [ false, %58 ], [ %65, %63 ]
%68 = zext i1 %67 to i32
store i32 %68, i32* %11
%69 = load i32, i32* %8
%70 = icmp eq i32 %69, 95
%71 = zext i1 %70 to i32
store i32 %71, i32* %12
%72 = load i32, i32* %9
%73 = icmp ne i32 %72, 0
br i1 %73, label %84, label %74
74: ; preds = %66
%75 = load i32, i32* %10
%76 = icmp ne i32 %75, 0
br i1 %76, label %84, label %77
77: ; preds = %74
%78 = load i32, i32* %11
%79 = icmp ne i32 %78, 0
br i1 %79, label %84, label %80
80: ; preds = %77
%81 = load i32, i32* %12
%82 = icmp ne i32 %81, 0
br i1 %82, label %84, label %83
83: ; preds = %80
br label %92
84: ; preds = %80, %77, %74, %66
%85 = load %struct.stream*, %struct.stream** %5
%86 = call i32 @next_char(%struct.stream* %85)
%87 = trunc i32 %86 to i8
%88 = load i8*, i8** %6
%89 = getelementptr inbounds i8, i8* %88, i32 1
store i8* %89, i8** %6
store i8 %87, i8* %88
%90 = load i64, i64* %7
%91 = add i64 %90, -1
store i64 %91, i64* %7
br label %35
92: ; preds = %83, %42
%93 = load i8*, i8** %6
%94 = getelementptr inbounds i8, i8* %93, i32 1
store i8* %94, i8** %6
store i8 0, i8* %93
%95 = load i64, i64* %7
%96 = add i64 %95, -1
store i64 %96, i64* %7
store i32 1, i32* %4
br label %97
97: ; preds = %92, %25, %18
%98 = load i32, i32* %4
ret i32 %98
}

LLVM IR (-O2):
%struct.stream = type { i32 }
@.str = [3 x i8] c"%c\00"
define i32 @next_word(%struct.stream* %0, i8* %1, i64 %2) {
%4 = tail call i32 @skip_whitespace(%struct.stream* %0)
%5 = tail call i32 @peek_char(%struct.stream* %0)
switch i32 %5, label %9 [
i32 40, label %6
i32 41, label %6
i32 123, label %6
i32 125, label %6
i32 59, label %6
i32 44, label %6
i32 0, label %39
]
6: ; preds = %3, %3, %3, %3, %3, %3
%7 = tail call i32 @next_char(%struct.stream* %0)
%8 = tail call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %39
9: ; preds = %3
%10 = tail call i32 @next_char(%struct.stream* %0)
%11 = trunc i32 %5 to i8
store i8 %11, i8* %1
%12 = getelementptr inbounds i8, i8* %1, i64 1
%13 = add i64 %2, -1
%14 = icmp ugt i64 %13, 1
br i1 %14, label %15, label %37
15: ; preds = %9, %31
%16 = phi i64 [ %35, %31 ], [ %13, %9 ]
%17 = phi i8* [ %34, %31 ], [ %12, %9 ]
%18 = tail call i32 @peek_char(%struct.stream* %0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %37, label %20
20: ; preds = %15
%21 = add i32 %18, -48
%22 = icmp ult i32 %21, 10
%23 = add i32 %18, -97
%24 = icmp ult i32 %23, 26
%25 = add i32 %18, -65
%26 = icmp ult i32 %25, 26
%27 = icmp eq i32 %18, 95
%28 = or i1 %22, %24
%29 = select i1 %28, i1 true, i1 %26
%30 = select i1 %29, i1 true, i1 %27
br i1 %30, label %31, label %37
31: ; preds = %20
%32 = tail call i32 @next_char(%struct.stream* %0)
%33 = trunc i32 %32 to i8
store i8 %33, i8* %17
%34 = getelementptr inbounds i8, i8* %17, i64 1
%35 = add i64 %16, -1
%36 = icmp ugt i64 %35, 1
br i1 %36, label %15, label %37
37: ; preds = %15, %31, %20, %9
%38 = phi i8* [ %12, %9 ], [ %17, %20 ], [ %34, %31 ], [ %17, %15 ]
store i8 0, i8* %38
br label %39
39: ; preds = %3, %37, %6
%40 = phi i32 [ 1, %37 ], [ 1, %6 ], [ %5, %3 ]
ret i32 %40
}