#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);
scalar_t__ is_quoted_pair(char const *);
int /*<<< orphan*/ is_text(char const);
int get_quoted_str_len(const char *str, int size) {
  int len = 0;
  assert(*str == '"');
  str++;
  len++;
  size--;
  while (1) {
    if (size < 1)
      return 0;
    if (len >= 2 && is_quoted_pair(str)) {
      len += 2;
      str += 2;
      size -= 2;
    } else if (*str == '"') {
      return len + 1;
    } else {
      if (!is_text(*str))
        return 0;
      len++;
      str++;
      size--;
    }
  }
}


x86 assembly (clang, -O0):
<get_quoted_str_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    1191 <get_quoted_str_len+0x61>
movl   $0x0,-0x4(%rbp)
jmp    1238 <get_quoted_str_len+0x108>
cmpl   $0x2,-0x18(%rbp)
jl     11d1 <get_quoted_str_len+0xa1>
mov    -0x10(%rbp),%rdi
call   1040 <is_quoted_pair@plt>
cmp    $0x0,%rax
je     11d1 <get_quoted_str_len+0xa1>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1233 <get_quoted_str_len+0x103>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11ef <get_quoted_str_len+0xbf>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1238 <get_quoted_str_len+0x108>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <is_text@plt>
cmp    $0x0,%eax
jne    1210 <get_quoted_str_len+0xe0>
movl   $0x0,-0x4(%rbp)
jmp    1238 <get_quoted_str_len+0x108>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1233 <get_quoted_str_len+0x103>
jmp    117b <get_quoted_str_len+0x4b>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_quoted_str_len>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %edi,%edi
cmpb   $0x22,(%rbx)
sete   %dil
call   1030 <assert@plt>
xor    %r14d,%r14d
cmp    $0x2,%r15d
jl     11c5 <get_quoted_str_len+0x95>
add    $0xffffffff,%r15d
add    $0x1,%rbx
mov    $0x1,%ebp
jmp    1196 <get_quoted_str_len+0x66>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <is_quoted_pair@plt>
test   %rax,%rax
je     119b <get_quoted_str_len+0x6b>
mov    $0xfffffffe,%eax
mov    $0x2,%ecx
mov    $0x2,%edx
add    %edx,%ebp
add    %rcx,%rbx
add    %eax,%r15d
jle    11c5 <get_quoted_str_len+0x95>
cmp    $0x2,%ebp
jae    1170 <get_quoted_str_len+0x40>
movzbl (%rbx),%eax
cmp    $0x22,%al
je     11bf <get_quoted_str_len+0x8f>
movsbl %al,%edi
call   1050 <is_text@plt>
test   %eax,%eax
je     11c5 <get_quoted_str_len+0x95>
mov    $0xffffffff,%eax
mov    $0x1,%ecx
mov    $0x1,%edx
jmp    118c <get_quoted_str_len+0x5c>
add    $0x1,%ebp
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_quoted_str_len(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 34
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
%15 = load i32, i32* %6
%16 = add nsw i32 %15, 1
store i32 %16, i32* %6
%17 = load i32, i32* %5
%18 = add nsw i32 %17, -1
store i32 %18, i32* %5
br label %19
19: ; preds = %2, %59
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 0, i32* %3
br label %60
23: ; preds = %19
%24 = load i32, i32* %6
%25 = icmp sge i32 %24, 2
br i1 %25, label %26, label %37
26: ; preds = %23
%27 = load i8*, i8** %4
%28 = call i64 @is_quoted_pair(i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 2
store i32 %32, i32* %6
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8* %34, i8** %4
%35 = load i32, i32* %5
%36 = sub nsw i32 %35, 2
store i32 %36, i32* %5
br label %59
37: ; preds = %26, %23
%38 = load i8*, i8** %4
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 34
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %3
br label %60
45: ; preds = %37
%46 = load i8*, i8** %4
%47 = load i8, i8* %46
%48 = call i32 @is_text(i8 signext %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %51, label %50
50: ; preds = %45
store i32 0, i32* %3
br label %60
51: ; preds = %45
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
%54 = load i8*, i8** %4
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %4
%56 = load i32, i32* %5
%57 = add nsw i32 %56, -1
store i32 %57, i32* %5
br label %58
58: ; preds = %51
br label %59
59: ; preds = %58, %30
br label %19
60: ; preds = %50, %42, %22
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
define i32 @get_quoted_str_len(i8* %0, i32 %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 34
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp slt i32 %1, 2
br i1 %7, label %35, label %8
8: ; preds = %2
%9 = add nsw i32 %1, -1
%10 = getelementptr inbounds i8, i8* %0, i64 1
br label %11
11: ; preds = %8, %27
%12 = phi i32 [ %31, %27 ], [ 1, %8 ]
%13 = phi i32 [ %33, %27 ], [ %9, %8 ]
%14 = phi i8* [ %32, %27 ], [ %10, %8 ]
%15 = icmp ugt i32 %12, 1
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = tail call i64 @is_quoted_pair(i8* %14)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %16, %11
%20 = load i8, i8* %14
%21 = icmp eq i8 %20, 34
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = add nuw nsw i32 %12, 1
br label %35
24: ; preds = %19
%25 = tail call i32 @is_text(i8 signext %20)
%26 = icmp eq i32 %25, 0
br i1 %26, label %35, label %27
27: ; preds = %24, %16
%28 = phi i32 [ 2, %16 ], [ 1, %24 ]
%29 = phi i64 [ 2, %16 ], [ 1, %24 ]
%30 = phi i32 [ -2, %16 ], [ -1, %24 ]
%31 = add nuw nsw i32 %12, %28
%32 = getelementptr inbounds i8, i8* %14, i64 %29
%33 = add nsw i32 %13, %30
%34 = icmp slt i32 %33, 1
br i1 %34, label %35, label %11
35: ; preds = %27, %24, %2, %22
%36 = phi i32 [ %23, %22 ], [ 0, %2 ], [ 0, %24 ], [ 0, %27 ]
ret i32 %36
}