#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*/ *strchr(char const *, char const);
size_t strcspn(char const *, char const *);
int arg_find_token_length(const char *token) {
  static const char *blank = " \t\n";
  static const char *blank_or_quote = " \t\n'\"\\";
  size_t total_len = 0;
  while (*token) {
    size_t len = 0;
    if (strchr(blank, *token) != NULL) {
      break;
    } else if (*token == '\\') {
      if (token[1])
        len = 2;
      else
        return total_len + 1;
    } else if (*token == '\'') {
      len = strcspn(token + 1, "\'");
      len += 2;
    } else if (*token == '\"') {
      len = strcspn(token + 1, "\"");
      len += 2;
    } else {
      len += strcspn(token, blank_or_quote);
    }
    token += len;
    total_len += len;
  }
  return total_len;
}


x86 assembly (clang, -O0):
<arg_find_token_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1261 <arg_find_token_length+0x141>
movq   $0x0,-0x20(%rbp)
mov    0x2ee0(%rip),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     116b <arg_find_token_length+0x4b>
jmp    1261 <arg_find_token_length+0x141>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11ab <arg_find_token_length+0x8b>
mov    -0x10(%rbp),%rax
cmpb   $0x0,0x1(%rax)
je     1196 <arg_find_token_length+0x76>
movq   $0x2,-0x20(%rbp)
jmp    11a6 <arg_find_token_length+0x86>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x4(%rbp)
jmp    1268 <arg_find_token_length+0x148>
jmp    123f <arg_find_token_length+0x11f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    11e4 <arg_find_token_length+0xc4>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    0xe41(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    123a <arg_find_token_length+0x11a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    121d <arg_find_token_length+0xfd>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    0xe0a(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    1235 <arg_find_token_length+0x115>
mov    -0x10(%rbp),%rdi
mov    0x2e10(%rip),%rsi
call   1040 <strcspn@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    123a <arg_find_token_length+0x11a>
jmp    123f <arg_find_token_length+0x11f>
jmp    1244 <arg_find_token_length+0x124>
mov    -0x20(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1134 <arg_find_token_length+0x14>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_find_token_length>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%cl
test   %cl,%cl
je     11cd <arg_find_token_length+0xad>
mov    %rdi,%rbx
xor    %r14d,%r14d
lea    0xebe(%rip),%r15
lea    0xec4(%rip),%r12
lea    0xebb(%rip),%r13
lea    0xead(%rip),%rbp
jmp    117e <arg_find_token_length+0x5e>
nopl   0x0(%rax)
lea    0x1(%rbx),%rdi
mov    %r13,%rsi
call   1040 <strcspn@plt>
add    $0x2,%rax
movzbl (%rbx,%rax,1),%ecx
add    %rax,%rbx
add    %rax,%r14
test   %cl,%cl
je     11d0 <arg_find_token_length+0xb0>
movsbl %cl,%esi
mov    %r15,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
jne    11d0 <arg_find_token_length+0xb0>
movzbl (%rbx),%eax
cmp    $0x22,%al
je     11b0 <arg_find_token_length+0x90>
cmp    $0x27,%al
je     1160 <arg_find_token_length+0x40>
cmp    $0x5c,%al
jne    11c0 <arg_find_token_length+0xa0>
mov    $0x2,%eax
cmpb   $0x0,0x1(%rbx)
jne    1170 <arg_find_token_length+0x50>
jmp    11e2 <arg_find_token_length+0xc2>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%rdi
mov    %r12,%rsi
jmp    1167 <arg_find_token_length+0x47>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcspn@plt>
jmp    1170 <arg_find_token_length+0x50>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%r14d
jmp    11d0 <arg_find_token_length+0xb0>

LLVM IR (-O0):
@arg_find_token_length.blank = internal global i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0)
@.str = [4 x i8] c" \09\0A\00"
@arg_find_token_length.blank_or_quote = internal global i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0)
@.str.1 = [7 x i8] c" \09\0A'\22\\\00"
@.str.2 = [2 x i8] c"'\00"
@.str.3 = [2 x i8] c"\22\00"
define i32 @arg_find_token_length(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 0, i64* %4
br label %6
6: ; preds = %64, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %71
10: ; preds = %6
store i64 0, i64* %5
%11 = load i8*, i8** @arg_find_token_length.blank
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = call i32* @strchr(i8* %11, i8 signext %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %10
br label %71
17: ; preds = %10
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 92
br i1 %21, label %22, label %33
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i64 2, i64* %5
br label %32
28: ; preds = %22
%29 = load i64, i64* %4
%30 = add i64 %29, 1
%31 = trunc i64 %30 to i32
store i32 %31, i32* %2
br label %74
32: ; preds = %27
br label %63
33: ; preds = %17
%34 = load i8*, i8** %3
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 39
br i1 %37, label %38, label %44
38: ; preds = %33
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = call i64 @strcspn(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i64 %41, i64* %5
%42 = load i64, i64* %5
%43 = add i64 %42, 2
store i64 %43, i64* %5
br label %62
44: ; preds = %33
%45 = load i8*, i8** %3
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 34
br i1 %48, label %49, label %55
49: ; preds = %44
%50 = load i8*, i8** %3
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = call i64 @strcspn(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i64 %52, i64* %5
%53 = load i64, i64* %5
%54 = add i64 %53, 2
store i64 %54, i64* %5
br label %61
55: ; preds = %44
%56 = load i8*, i8** %3
%57 = load i8*, i8** @arg_find_token_length.blank_or_quote
%58 = call i64 @strcspn(i8* %56, i8* %57)
%59 = load i64, i64* %5
%60 = add i64 %59, %58
store i64 %60, i64* %5
br label %61
61: ; preds = %55, %49
br label %62
62: ; preds = %61, %38
br label %63
63: ; preds = %62, %32
br label %64
64: ; preds = %63
%65 = load i64, i64* %5
%66 = load i8*, i8** %3
%67 = getelementptr inbounds i8, i8* %66, i64 %65
store i8* %67, i8** %3
%68 = load i64, i64* %5
%69 = load i64, i64* %4
%70 = add i64 %69, %68
store i64 %70, i64* %4
br label %6
71: ; preds = %16, %6
%72 = load i64, i64* %4
%73 = trunc i64 %72 to i32
store i32 %73, i32* %2
br label %74
74: ; preds = %71, %28
%75 = load i32, i32* %2
ret i32 %75
}

LLVM IR (-O2):
@.str = [4 x i8] c" \09\0A\00"
@.str.1 = [7 x i8] c" \09\0A'\22\\\00"
@.str.2 = [2 x i8] c"'\00"
@.str.3 = [2 x i8] c"\22\00"
define i32 @arg_find_token_length(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %35, label %4
4: ; preds = %1, %29
%5 = phi i8 [ %33, %29 ], [ %2, %1 ]
%6 = phi i64 [ %32, %29 ], [ 0, %1 ]
%7 = phi i8* [ %31, %29 ], [ %0, %1 ]
%8 = tail call i32* @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %35
10: ; preds = %4
%11 = load i8, i8* %7
switch i8 %11, label %27 [
i8 92, label %12
i8 39, label %19
i8 34, label %23
]
12: ; preds = %10
%13 = getelementptr inbounds i8, i8* %7, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %12
%17 = trunc i64 %6 to i32
%18 = add i32 %17, 1
br label %38
19: ; preds = %10
%20 = getelementptr inbounds i8, i8* %7, i64 1
%21 = tail call i64 @strcspn(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = add i64 %21, 2
br label %29
23: ; preds = %10
%24 = getelementptr inbounds i8, i8* %7, i64 1
%25 = tail call i64 @strcspn(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = add i64 %25, 2
br label %29
27: ; preds = %10
%28 = tail call i64 @strcspn(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %19, %27, %23, %12
%30 = phi i64 [ %22, %19 ], [ %26, %23 ], [ %28, %27 ], [ 2, %12 ]
%31 = getelementptr inbounds i8, i8* %7, i64 %30
%32 = add i64 %30, %6
%33 = load i8, i8* %31
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %4
35: ; preds = %29, %4, %1
%36 = phi i64 [ 0, %1 ], [ %6, %4 ], [ %32, %29 ]
%37 = trunc i64 %36 to i32
br label %38
38: ; preds = %16, %35
%39 = phi i32 [ %37, %35 ], [ %18, %16 ]
ret i32 %39
}