#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*/ free(char *);
int /*<<< orphan*/ memmove(char *, char *, int);
size_t strcspn(char const *, char const *);
char *strdup(char const *);
int strlen(char *);
char *strndup(char const *, size_t);
char *parse_title(const char *name, size_t *len) {
  const char *escapes = "'\\";
  char *title;
  char *end;
  char *ch;
  if (*name != '\'') {
    *len = strcspn(name, "|");
    if (!*len)
      return NULL;
    return strndup(name, *len);
  }
  title = strdup(name + 1);
  if (!title)
    return NULL;
  *len = 1;
  ch = title;
  end = title + strlen(title);
  while (ch < end) {
    size_t l = strcspn(ch, escapes);
    *len += l + 1;
    ch += l;
    switch (*ch) {
    case '\'':
      *ch = 0;
      return title;
    case '\\':
      if (!ch[1] || strcspn(ch + 1, escapes)) {
        free(title);
        return NULL;
      }
      memmove(ch, ch + 1, strlen(ch));
      ch++;
      (*len)++;
      break;
    default:
      free(title);
      return NULL;
    }
  }
  free(title);
  return NULL;
}


x86 assembly (clang, -O0):
<parse_title>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe89(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
je     11d9 <parse_title+0x79>
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1050 <strcspn@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11c0 <parse_title+0x60>
movq   $0x0,-0x8(%rbp)
jmp    136a <parse_title+0x20a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1060 <strndup@plt>
mov    %rax,-0x8(%rbp)
jmp    136a <parse_title+0x20a>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1202 <parse_title+0xa2>
movq   $0x0,-0x8(%rbp)
jmp    136a <parse_title+0x20a>
mov    -0x18(%rbp),%rax
movq   $0x1,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1359 <parse_title+0x1f9>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcspn@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0x1(%rcx,%rdx,1),%rcx
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4c(%rbp)
sub    $0x27,%eax
je     12a0 <parse_title+0x140>
jmp    128f <parse_title+0x12f>
mov    -0x4c(%rbp),%eax
sub    $0x5c,%eax
je     12b4 <parse_title+0x154>
jmp    133e <parse_title+0x1de>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    136a <parse_title+0x20a>
mov    -0x38(%rbp),%rax
cmpb   $0x0,0x1(%rax)
je     12dd <parse_title+0x17d>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcspn@plt>
cmp    $0x0,%rax
je     12f3 <parse_title+0x193>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    136a <parse_title+0x20a>
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1070 <memmove@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1354 <parse_title+0x1f4>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    136a <parse_title+0x20a>
jmp    1236 <parse_title+0xd6>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_title>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%rbx
cmpb   $0x27,(%rdi)
jne    122f <parse_title+0xcf>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1080 <strdup@plt>
test   %rax,%rax
je     1274 <parse_title+0x114>
mov    %rax,%r14
movq   $0x1,(%r12)
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    126c <parse_title+0x10c>
cltq
mov    %r14,%r15
add    %rax,%r15
mov    (%r12),%rbp
mov    %r14,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
lea    0xe36(%rip),%rsi
call   1050 <strcspn@plt>
lea    (%rax,%rbp,1),%rcx
add    $0x1,%rcx
mov    %rcx,(%r12)
lea    (%rbx,%rax,1),%r13
movsbl (%rbx,%rax,1),%eax
cmp    $0x5c,%eax
jne    1260 <parse_title+0x100>
cmpb   $0x0,0x1(%r13)
je     126c <parse_title+0x10c>
lea    0x1(%r13),%rbx
mov    %rbx,%rdi
lea    0xe03(%rip),%rsi
call   1050 <strcspn@plt>
test   %rax,%rax
jne    126c <parse_title+0x10c>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <memmove@plt>
mov    (%r12),%rbp
add    $0x1,%rbp
mov    %rbp,(%r12)
cmp    %r15,%rbx
jb     11c0 <parse_title+0x60>
jmp    126c <parse_title+0x10c>
lea    0xdcd(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcspn@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     1274 <parse_title+0x114>
mov    %rbx,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <strndup@plt>
cmp    $0x27,%eax
jne    126c <parse_title+0x10c>
movb   $0x0,0x0(%r13)
jmp    1277 <parse_title+0x117>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"'\\\00"
@.str.1 = [2 x i8] c"|\00"
define i8* @parse_title(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %6
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 39
br i1 %14, label %15, label %28
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i64 @strcspn(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = load i64*, i64** %5
store i64 %17, i64* %18
%19 = load i64*, i64** %5
%20 = load i64, i64* %19
%21 = icmp ne i64 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %15
store i8* null, i8** %3
br label %98
23: ; preds = %15
%24 = load i8*, i8** %4
%25 = load i64*, i64** %5
%26 = load i64, i64* %25
%27 = call i8* @strndup(i8* %24, i64 %26)
store i8* %27, i8** %3
br label %98
28: ; preds = %2
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = call i8* @strdup(i8* %30)
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = icmp ne i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %28
store i8* null, i8** %3
br label %98
35: ; preds = %28
%36 = load i64*, i64** %5
store i64 1, i64* %36
%37 = load i8*, i8** %7
store i8* %37, i8** %9
%38 = load i8*, i8** %7
%39 = load i8*, i8** %7
%40 = call i32 @strlen(i8* %39)
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
store i8* %42, i8** %8
br label %43
43: ; preds = %94, %35
%44 = load i8*, i8** %9
%45 = load i8*, i8** %8
%46 = icmp ult i8* %44, %45
br i1 %46, label %47, label %95
47: ; preds = %43
%48 = load i8*, i8** %9
%49 = load i8*, i8** %6
%50 = call i64 @strcspn(i8* %48, i8* %49)
store i64 %50, i64* %10
%51 = load i64, i64* %10
%52 = add i64 %51, 1
%53 = load i64*, i64** %5
%54 = load i64, i64* %53
%55 = add i64 %54, %52
store i64 %55, i64* %53
%56 = load i64, i64* %10
%57 = load i8*, i8** %9
%58 = getelementptr inbounds i8, i8* %57, i64 %56
store i8* %58, i8** %9
%59 = load i8*, i8** %9
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
switch i32 %61, label %91 [
i32 39, label %62
i32 92, label %65
]
62: ; preds = %47
%63 = load i8*, i8** %9
store i8 0, i8* %63
%64 = load i8*, i8** %7
store i8* %64, i8** %3
br label %98
65: ; preds = %47
%66 = load i8*, i8** %9
%67 = getelementptr inbounds i8, i8* %66, i64 1
%68 = load i8, i8* %67
%69 = icmp ne i8 %68, 0
br i1 %69, label %70, label %76
70: ; preds = %65
%71 = load i8*, i8** %9
%72 = getelementptr inbounds i8, i8* %71, i64 1
%73 = load i8*, i8** %6
%74 = call i64 @strcspn(i8* %72, i8* %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %70, %65
%77 = load i8*, i8** %7
%78 = call i32 @free(i8* %77)
store i8* null, i8** %3
br label %98
79: ; preds = %70
%80 = load i8*, i8** %9
%81 = load i8*, i8** %9
%82 = getelementptr inbounds i8, i8* %81, i64 1
%83 = load i8*, i8** %9
%84 = call i32 @strlen(i8* %83)
%85 = call i32 @memmove(i8* %80, i8* %82, i32 %84)
%86 = load i8*, i8** %9
%87 = getelementptr inbounds i8, i8* %86, i32 1
store i8* %87, i8** %9
%88 = load i64*, i64** %5
%89 = load i64, i64* %88
%90 = add i64 %89, 1
store i64 %90, i64* %88
br label %94
91: ; preds = %47
%92 = load i8*, i8** %7
%93 = call i32 @free(i8* %92)
store i8* null, i8** %3
br label %98
94: ; preds = %79
br label %43
95: ; preds = %43
%96 = load i8*, i8** %7
%97 = call i32 @free(i8* %96)
store i8* null, i8** %3
br label %98
98: ; preds = %95, %91, %76, %62, %34, %23, %22
%99 = load i8*, i8** %3
ret i8* %99
}

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