#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 strcspn(char const *, char const *);
int strlen(char const *);
int get_arg_valuelen(const char *arg, char *quoted) {
  if (*arg == '"' || *arg == '\'') {
    const char *end = *arg == '"' ? "\"" : "'";
    int valuelen = strcspn(arg + 1, end);
    if (quoted)
      *quoted = *arg;
    return valuelen > 0 ? valuelen + 2 : strlen(arg);
  } else {
    if (quoted)
      *quoted = 0;
    return strcspn(arg, " \t");
  }
}


x86 assembly (clang, -O0):
<get_arg_valuelen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     1150 <get_arg_valuelen+0x30>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    11ca <get_arg_valuelen+0xaa>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
lea    0xea4(%rip),%rax
lea    0xe9b(%rip),%rcx
cmp    $0x22,%edx
cmove  %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119b <get_arg_valuelen+0x7b>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
cmpl   $0x0,-0x24(%rbp)
jle    11b3 <get_arg_valuelen+0x93>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x28(%rbp)
jmp    11bf <get_arg_valuelen+0x9f>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ef <get_arg_valuelen+0xcf>
cmpq   $0x0,-0x18(%rbp)
je     11dc <get_arg_valuelen+0xbc>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1040 <strcspn@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_arg_valuelen>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%bl
cmp    $0x27,%bl
je     1137 <get_arg_valuelen+0x17>
cmp    $0x22,%bl
jne    116a <get_arg_valuelen+0x4a>
cmp    $0x22,%bl
lea    0xebf(%rip),%rax
lea    0xeba(%rip),%rsi
cmove  %rax,%rsi
lea    0x1(%r15),%rdi
call   1040 <strcspn@plt>
test   %r14,%r14
je     115d <get_arg_valuelen+0x3d>
mov    %bl,(%r14)
test   %eax,%eax
jle    1187 <get_arg_valuelen+0x67>
add    $0x2,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
test   %r14,%r14
je     1173 <get_arg_valuelen+0x53>
movb   $0x0,(%r14)
lea    0xe8a(%rip),%rsi
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <strcspn@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strlen@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\22\00"
@.str.1 = [2 x i8] c"'\00"
@.str.2 = [3 x i8] c" \09\00"
define i32 @get_arg_valuelen(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 34
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 39
br i1 %16, label %17, label %45
17: ; preds = %12, %2
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 34
%22 = zext i1 %21 to i64
%23 = select i1 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
store i8* %23, i8** %6
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8*, i8** %6
%27 = call i32 @strcspn(i8* %25, i8* %26)
store i32 %27, i32* %7
%28 = load i8*, i8** %5
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %17
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = load i8*, i8** %5
store i8 %32, i8* %33
br label %34
34: ; preds = %30, %17
%35 = load i32, i32* %7
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 2
br label %43
40: ; preds = %34
%41 = load i8*, i8** %4
%42 = call i32 @strlen(i8* %41)
br label %43
43: ; preds = %40, %37
%44 = phi i32 [ %39, %37 ], [ %42, %40 ]
store i32 %44, i32* %3
br label %53
45: ; preds = %12
%46 = load i8*, i8** %5
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = load i8*, i8** %5
store i8 0, i8* %49
br label %50
50: ; preds = %48, %45
%51 = load i8*, i8** %4
%52 = call i32 @strcspn(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 %52, i32* %3
br label %53
53: ; preds = %50, %43
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [2 x i8] c"\22\00"
@.str.1 = [2 x i8] c"'\00"
@.str.2 = [3 x i8] c" \09\00"
define i32 @get_arg_valuelen(i8* %0, i8* writeonly %1) {
%3 = load i8, i8* %0
switch i8 %3, label %17 [
i8 34, label %4
i8 39, label %4
]
4: ; preds = %2, %2
%5 = icmp eq i8 %3, 34
%6 = select i1 %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = tail call i32 @strcspn(i8* %7, i8* %6)
%9 = icmp eq i8* %1, null
br i1 %9, label %11, label %10
10: ; preds = %4
store i8 %3, i8* %1
br label %11
11: ; preds = %10, %4
%12 = icmp sgt i32 %8, 0
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = add nuw nsw i32 %8, 2
br label %22
15: ; preds = %11
%16 = tail call i32 @strlen(i8* %0)
br label %22
17: ; preds = %2
%18 = icmp eq i8* %1, null
br i1 %18, label %20, label %19
19: ; preds = %17
store i8 0, i8* %1
br label %20
20: ; preds = %19, %17
%21 = tail call i32 @strcspn(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %13, %15, %20
%23 = phi i32 [ %21, %20 ], [ %14, %13 ], [ %16, %15 ]
ret i32 %23
}