#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 *op_xstrndup(char const *, size_t);
int /*<<< orphan*/ parse_error(char *);
char *skip_nonws(char const *);
char *skip_ws(char const *);
char *strchr(char const *, char);
int /*<<< orphan*/ strlen(char const *);
char *xstrdup(char const *);
int next_token(char const **cp, char **name, char **value) {
  size_t tag_len;
  size_t val_len;
  char const *c = *cp;
  char const *end;
  char const *colon;
  c = skip_ws(c);
  end = colon = c;
  end = skip_nonws(end);
  colon = strchr(colon, ':');
  if (!colon) {
    if (*c)
      parse_error("next_token(): garbage at end of line");
    return 0;
  }
  if (colon >= end)
    parse_error("next_token() expected ':'");
  tag_len = colon - c;
  val_len = end - (colon + 1);
  if (!tag_len) {
    end = skip_ws(end);
    *name = xstrdup("desc");
    *value = xstrdup(end);
    end += strlen(end);
  } else {
    *name = op_xstrndup(c, tag_len);
    *value = op_xstrndup(colon + 1, val_len);
    end = skip_ws(end);
  }
  *cp = end;
  return 1;
}


x86 assembly (clang, -O0):
<next_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <skip_ws@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1090 <skip_nonws@plt>
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11f7 <next_token+0x87>
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     11eb <next_token+0x7b>
lea    0xe1a(%rip),%rdi
call   1080 <parse_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e3 <next_token+0x173>
mov    -0x48(%rbp),%rax
cmp    -0x40(%rbp),%rax
jb     1211 <next_token+0xa1>
lea    0xe19(%rip),%rdi
call   1080 <parse_error@plt>
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x48(%rbp),%rcx
add    $0x1,%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1292 <next_token+0x122>
mov    -0x40(%rbp),%rdi
call   1060 <skip_ws@plt>
mov    %rax,-0x40(%rbp)
lea    0xded(%rip),%rdi
call   1050 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
jmp    12d1 <next_token+0x161>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <op_xstrndup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
mov    -0x30(%rbp),%rsi
call   1070 <op_xstrndup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rdi
call   1060 <skip_ws@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_token>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
mov    (%rdi),%rdi
call   1060 <skip_ws@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <skip_nonws@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11fd <next_token+0x8d>
mov    %rax,%rbp
cmp    %r14,%rax
jb     11c0 <next_token+0x50>
lea    0xe6a(%rip),%rdi
call   1080 <parse_error@plt>
mov    %rbp,%rsi
sub    %rbx,%rsi
je     1212 <next_token+0xa2>
add    $0x1,%rbp
mov    %r13,(%rsp)
mov    %r14,%r13
sub    %rbp,%r13
mov    %rbx,%rdi
call   1070 <op_xstrndup@plt>
mov    %rax,(%r15)
mov    %rbp,%rdi
mov    %r13,%rsi
call   1070 <op_xstrndup@plt>
mov    (%rsp),%rcx
mov    %rax,(%rcx)
mov    %r14,%rdi
call   1060 <skip_ws@plt>
jmp    1245 <next_token+0xd5>
xor    %ebp,%ebp
cmpb   $0x0,(%rbx)
je     124e <next_token+0xde>
lea    0xdf5(%rip),%rdi
call   1080 <parse_error@plt>
jmp    124e <next_token+0xde>
mov    %r14,%rdi
call   1060 <skip_ws@plt>
mov    %rax,%rbx
lea    0xe1b(%rip),%rdi
call   1050 <xstrdup@plt>
mov    %rax,(%r15)
mov    %rbx,%rdi
call   1050 <xstrdup@plt>
mov    %rax,0x0(%r13)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
mov    %rax,(%r12)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"next_token(): garbage at end of line\00"
@.str.1 = [26 x i8] c"next_token() expected ':'\00"
@.str.2 = [5 x i8] c"desc\00"
define i32 @next_token(i8** %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i8** %0, i8*** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%13 = load i8**, i8*** %5
%14 = load i8*, i8** %13
store i8* %14, i8** %10
%15 = load i8*, i8** %10
%16 = call i8* @skip_ws(i8* %15)
store i8* %16, i8** %10
%17 = load i8*, i8** %10
store i8* %17, i8** %12
store i8* %17, i8** %11
%18 = load i8*, i8** %11
%19 = call i8* @skip_nonws(i8* %18)
store i8* %19, i8** %11
%20 = load i8*, i8** %12
%21 = call i8* @strchr(i8* %20, i8 signext 58)
store i8* %21, i8** %12
%22 = load i8*, i8** %12
%23 = icmp ne i8* %22, null
br i1 %23, label %31, label %24
24: ; preds = %3
%25 = load i8*, i8** %10
%26 = load i8, i8* %25
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @parse_error(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
store i32 0, i32* %4
br label %79
31: ; preds = %3
%32 = load i8*, i8** %12
%33 = load i8*, i8** %11
%34 = icmp uge i8* %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @parse_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = load i8*, i8** %12
%39 = load i8*, i8** %10
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
store i64 %42, i64* %8
%43 = load i8*, i8** %11
%44 = load i8*, i8** %12
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = ptrtoint i8* %43 to i64
%47 = ptrtoint i8* %45 to i64
%48 = sub i64 %46, %47
store i64 %48, i64* %9
%49 = load i64, i64* %8
%50 = icmp ne i64 %49, 0
br i1 %50, label %64, label %51
51: ; preds = %37
%52 = load i8*, i8** %11
%53 = call i8* @skip_ws(i8* %52)
store i8* %53, i8** %11
%54 = call i8* @xstrdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%55 = load i8**, i8*** %6
store i8* %54, i8** %55
%56 = load i8*, i8** %11
%57 = call i8* @xstrdup(i8* %56)
%58 = load i8**, i8*** %7
store i8* %57, i8** %58
%59 = load i8*, i8** %11
%60 = call i32 @strlen(i8* %59)
%61 = load i8*, i8** %11
%62 = sext i32 %60 to i64
%63 = getelementptr inbounds i8, i8* %61, i64 %62
store i8* %63, i8** %11
br label %76
64: ; preds = %37
%65 = load i8*, i8** %10
%66 = load i64, i64* %8
%67 = call i8* @op_xstrndup(i8* %65, i64 %66)
%68 = load i8**, i8*** %6
store i8* %67, i8** %68
%69 = load i8*, i8** %12
%70 = getelementptr inbounds i8, i8* %69, i64 1
%71 = load i64, i64* %9
%72 = call i8* @op_xstrndup(i8* %70, i64 %71)
%73 = load i8**, i8*** %7
store i8* %72, i8** %73
%74 = load i8*, i8** %11
%75 = call i8* @skip_ws(i8* %74)
store i8* %75, i8** %11
br label %76
76: ; preds = %64, %51
%77 = load i8*, i8** %11
%78 = load i8**, i8*** %5
store i8* %77, i8** %78
store i32 1, i32* %4
br label %79
79: ; preds = %76, %30
%80 = load i32, i32* %4
ret i32 %80
}

LLVM IR (-O2):
@.str = [37 x i8] c"next_token(): garbage at end of line\00"
@.str.1 = [26 x i8] c"next_token() expected ':'\00"
@.str.2 = [5 x i8] c"desc\00"
define i32 @next_token(i8** nocapture %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = load i8*, i8** %0
%5 = tail call i8* @skip_ws(i8* %4)
%6 = tail call i8* @skip_nonws(i8* %5)
%7 = tail call i8* @strchr(i8* dereferenceable(1) %5, i8 signext 58)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i8, i8* %5
%11 = icmp eq i8 %10, 0
br i1 %11, label %40, label %12
12: ; preds = %9
%13 = tail call i32 @parse_error(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %40
14: ; preds = %3
%15 = icmp ult i8* %7, %6
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 @parse_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
%19 = ptrtoint i8* %7 to i64
%20 = ptrtoint i8* %5 to i64
%21 = sub i64 %19, %20
%22 = getelementptr inbounds i8, i8* %7, i64 1
%23 = icmp eq i64 %21, 0
br i1 %23, label %24, label %31
24: ; preds = %18
%25 = tail call i8* @skip_ws(i8* %6)
%26 = tail call i8* @xstrdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %26, i8** %1
%27 = tail call i8* @xstrdup(i8* %25)
store i8* %27, i8** %2
%28 = tail call i32 @strlen(i8* %25)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
br label %38
31: ; preds = %18
%32 = ptrtoint i8* %6 to i64
%33 = ptrtoint i8* %22 to i64
%34 = sub i64 %32, %33
%35 = tail call i8* @op_xstrndup(i8* %5, i64 %21)
store i8* %35, i8** %1
%36 = tail call i8* @op_xstrndup(i8* %22, i64 %34)
store i8* %36, i8** %2
%37 = tail call i8* @skip_ws(i8* %6)
br label %38
38: ; preds = %31, %24
%39 = phi i8* [ %37, %31 ], [ %30, %24 ]
store i8* %39, i8** %0
br label %40
40: ; preds = %9, %12, %38
%41 = phi i32 [ 1, %38 ], [ 0, %12 ], [ 0, %9 ]
ret i32 %41
}