int CdsObjectToDidl_Helper_DoubleEscapeLength(const char *data) {
  int i = 0, j = 0;
  while (data[i] != 0) {
    switch (data[i]) {
    case '"':
      j += 10;
      break;
    case '\'':
      j += 10;
      break;
    case '<':
      j += 8;
      break;
    case '>':
      j += 8;
      break;
    case '&':
      j += 9;
      break;
    default:
      j++;
    }
    i++;
  }
  return j;
}


x86 assembly (clang, -O0):
<CdsObjectToDidl_Helper_DoubleEscapeLength>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ba <CdsObjectToDidl_Helper_DoubleEscapeLength+0xba>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x1c,%eax
ja     11a3 <CdsObjectToDidl_Helper_DoubleEscapeLength+0xa3>
mov    -0x18(%rbp),%rax
lea    0xeac(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x10(%rbp)
jmp    11ac <CdsObjectToDidl_Helper_DoubleEscapeLength+0xac>
mov    -0x10(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x10(%rbp)
jmp    11ac <CdsObjectToDidl_Helper_DoubleEscapeLength+0xac>
mov    -0x10(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x10(%rbp)
jmp    11ac <CdsObjectToDidl_Helper_DoubleEscapeLength+0xac>
mov    -0x10(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x10(%rbp)
jmp    11ac <CdsObjectToDidl_Helper_DoubleEscapeLength+0xac>
mov    -0x10(%rbp),%eax
add    $0x9,%eax
mov    %eax,-0x10(%rbp)
jmp    11ac <CdsObjectToDidl_Helper_DoubleEscapeLength+0xac>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1116 <CdsObjectToDidl_Helper_DoubleEscapeLength+0x16>
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<CdsObjectToDidl_Helper_DoubleEscapeLength>:
mov    (%rdi),%dl
test   %dl,%dl
je     1155 <CdsObjectToDidl_Helper_DoubleEscapeLength+0x55>
add    $0x1,%rdi
xor    %eax,%eax
lea    0xeed(%rip),%rcx
jmp    112d <CdsObjectToDidl_Helper_DoubleEscapeLength+0x2d>
mov    $0x1,%edx
nopw   0x0(%rax,%rax,1)
add    %edx,%eax
movzbl (%rdi),%edx
add    $0x1,%rdi
test   %dl,%dl
je     1154 <CdsObjectToDidl_Helper_DoubleEscapeLength+0x54>
movsbl %dl,%esi
add    $0xffffffde,%esi
cmp    $0x1c,%esi
ja     1115 <CdsObjectToDidl_Helper_DoubleEscapeLength+0x15>
mov    $0xa,%edx
movslq (%rcx,%rsi,4),%rsi
add    %rcx,%rsi
jmp    *%rsi
mov    $0x8,%edx
jmp    1120 <CdsObjectToDidl_Helper_DoubleEscapeLength+0x20>
mov    $0x9,%edx
jmp    1120 <CdsObjectToDidl_Helper_DoubleEscapeLength+0x20>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @CdsObjectToDidl_Helper_DoubleEscapeLength(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %38, %1
%6 = load i8*, i8** %2
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %41
13: ; preds = %5
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
switch i32 %19, label %35 [
i32 34, label %20
i32 39, label %23
i32 60, label %26
i32 62, label %29
i32 38, label %32
]
20: ; preds = %13
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 10
store i32 %22, i32* %4
br label %38
23: ; preds = %13
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 10
store i32 %25, i32* %4
br label %38
26: ; preds = %13
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 8
store i32 %28, i32* %4
br label %38
29: ; preds = %13
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 8
store i32 %31, i32* %4
br label %38
32: ; preds = %13
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 9
store i32 %34, i32* %4
br label %38
35: ; preds = %13
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %38
38: ; preds = %35, %32, %29, %26, %23, %20
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %5
41: ; preds = %5
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
define i32 @CdsObjectToDidl_Helper_DoubleEscapeLength(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1, %13
%5 = phi i64 [ %16, %13 ], [ 0, %1 ]
%6 = phi i8 [ %18, %13 ], [ %2, %1 ]
%7 = phi i32 [ %15, %13 ], [ 0, %1 ]
%8 = sext i8 %6 to i32
switch i32 %8, label %12 [
i32 34, label %13
i32 39, label %13
i32 60, label %9
i32 62, label %10
i32 38, label %11
]
9: ; preds = %4
br label %13
10: ; preds = %4
br label %13
11: ; preds = %4
br label %13
12: ; preds = %4
br label %13
13: ; preds = %4, %4, %12, %11, %10, %9
%14 = phi i32 [ 1, %12 ], [ 9, %11 ], [ 8, %10 ], [ 8, %9 ], [ 10, %4 ], [ 10, %4 ]
%15 = add nuw nsw i32 %7, %14
%16 = add nuw i64 %5, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %4
20: ; preds = %13, %1
%21 = phi i32 [ 0, %1 ], [ %15, %13 ]
ret i32 %21
}