#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*/ addchar(char const);
int /*<<< orphan*/ addchars(char const *, int);
char *getstring();
char *twiddle(const char *p) {
  if (*p == '^') {
    addchar(*p);
    p++;
  }
  if (*p == '+') {
    addchar('\\');
  }
  while (*p != '\0') {
    if (*p == '\\') {
      switch (p[1]) {
      case '(':
      case ')':
      case '|':
        addchar(p[1]);
        break;
      case 'w':
        addchars(("[_a-zA-Z0-9]"), sizeof("[_a-zA-Z0-9]") - 1);
        break;
      case 'W':
        addchars(("[^_a-zA-Z0-9]"), sizeof("[^_a-zA-Z0-9]") - 1);
        break;
      case '<':
        addchars(("[[:<:]]"), sizeof("[[:<:]]") - 1);
        break;
      case '>':
        addchars(("[[:>:]]"), sizeof("[[:>:]]") - 1);
        break;
      default:
        addchars(p, 2);
        break;
      }
      p += 2;
      continue;
    }
    if (*p == '(' || *p == ')' || *p == '|')
      addchar('\\');
    addchar(*p);
    p++;
  }
  return getstring();
}


x86 assembly (clang, -O0):
<twiddle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5e,%eax
jne    1164 <twiddle+0x34>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <addchar@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    117e <twiddle+0x4e>
mov    $0x5c,%edi
call   1040 <addchar@plt>
jmp    1183 <twiddle+0x53>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12f4 <twiddle+0x1c4>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    129d <twiddle+0x16d>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0xc(%rbp)
add    $0xffffffd8,%eax
sub    $0x2,%eax
jb     1214 <twiddle+0xe4>
jmp    11bf <twiddle+0x8f>
mov    -0xc(%rbp),%eax
sub    $0x3c,%eax
je     1252 <twiddle+0x122>
jmp    11d0 <twiddle+0xa0>
mov    -0xc(%rbp),%eax
sub    $0x3e,%eax
je     1268 <twiddle+0x138>
jmp    11e1 <twiddle+0xb1>
mov    -0xc(%rbp),%eax
sub    $0x57,%eax
je     123c <twiddle+0x10c>
jmp    11f2 <twiddle+0xc2>
mov    -0xc(%rbp),%eax
sub    $0x77,%eax
je     1226 <twiddle+0xf6>
jmp    1203 <twiddle+0xd3>
mov    -0xc(%rbp),%eax
sub    $0x7c,%eax
jne    127e <twiddle+0x14e>
jmp    1214 <twiddle+0xe4>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <addchar@plt>
jmp    128c <twiddle+0x15c>
lea    0xdd3(%rip),%rdi
mov    $0xc,%esi
call   1050 <addchars@plt>
jmp    128c <twiddle+0x15c>
lea    0xdca(%rip),%rdi
mov    $0xd,%esi
call   1050 <addchars@plt>
jmp    128c <twiddle+0x15c>
lea    0xdc2(%rip),%rdi
mov    $0x7,%esi
call   1050 <addchars@plt>
jmp    128c <twiddle+0x15c>
lea    0xdb4(%rip),%rdi
mov    $0x7,%esi
call   1050 <addchars@plt>
jmp    128c <twiddle+0x15c>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
call   1050 <addchars@plt>
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    1183 <twiddle+0x53>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
je     12cd <twiddle+0x19d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
je     12cd <twiddle+0x19d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7c,%eax
jne    12d7 <twiddle+0x1a7>
mov    $0x5c,%edi
call   1040 <addchar@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <addchar@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1183 <twiddle+0x53>
mov    $0x0,%al
call   1030 <getstring@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twiddle>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%al
cmp    $0x5e,%al
jne    1155 <twiddle+0x25>
mov    $0x5e,%edi
call   1040 <addchar@plt>
mov    0x1(%rbx),%al
add    $0x1,%rbx
cmp    $0x2b,%al
jne    1163 <twiddle+0x33>
mov    $0x5c,%edi
call   1040 <addchar@plt>
mov    $0x1,%ebp
mov    $0x2,%r14d
lea    0xe8b(%rip),%r15
lea    0xf67(%rip),%r12
lea    0xf4a(%rip),%r13
jmp    11b0 <twiddle+0x80>
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x28(%rax),%ecx
cmp    $0x2,%cl
jae    11dd <twiddle+0xad>
mov    $0x5c,%edi
call   1040 <addchar@plt>
movzbl (%rbx),%eax
movsbl %al,%edi
call   1040 <addchar@plt>
add    %rbp,%rbx
movzbl (%rbx),%eax
cmp    $0x5b,%al
jle    1190 <twiddle+0x60>
cmp    $0x7c,%al
je     1198 <twiddle+0x68>
cmp    $0x5c,%al
jne    11a5 <twiddle+0x75>
movsbl 0x1(%rbx),%edi
lea    -0x28(%rdi),%eax
cmp    $0x2f,%eax
ja     11e3 <twiddle+0xb3>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
lea    0xf00(%rip),%rdi
jmp    1204 <twiddle+0xd4>
test   %al,%al
jne    11a5 <twiddle+0x75>
jmp    122b <twiddle+0xfb>
cmp    $0x77,%edi
je     1215 <twiddle+0xe5>
cmp    $0x7c,%edi
jne    11f7 <twiddle+0xc7>
call   1040 <addchar@plt>
add    %r14,%rbx
jmp    11b0 <twiddle+0x80>
mov    %rbx,%rdi
mov    $0x2,%esi
jmp    1221 <twiddle+0xf1>
mov    %r12,%rdi
mov    $0x7,%esi
jmp    1221 <twiddle+0xf1>
mov    %r13,%rdi
mov    $0xd,%esi
jmp    1221 <twiddle+0xf1>
lea    0xea4(%rip),%rdi
mov    $0xc,%esi
call   1050 <addchars@plt>
add    %r14,%rbx
jmp    11b0 <twiddle+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <getstring@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"[_a-zA-Z0-9]\00"
@.str.1 = [14 x i8] c"[^_a-zA-Z0-9]\00"
@.str.2 = [8 x i8] c"[[:<:]]\00"
@.str.3 = [8 x i8] c"[[:>:]]\00"
define i8* @twiddle(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
%6 = icmp eq i32 %5, 94
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = call i32 @addchar(i8 signext %9)
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %2
br label %13
13: ; preds = %7, %1
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 43
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @addchar(i8 signext 92)
br label %20
20: ; preds = %18, %13
br label %21
21: ; preds = %72, %52, %20
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %78
26: ; preds = %21
%27 = load i8*, i8** %2
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 92
br i1 %30, label %31, label %55
31: ; preds = %26
%32 = load i8*, i8** %2
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
switch i32 %35, label %49 [
i32 40, label %36
i32 41, label %36
i32 124, label %36
i32 119, label %41
i32 87, label %43
i32 60, label %45
i32 62, label %47
]
36: ; preds = %31, %31, %31
%37 = load i8*, i8** %2
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = call i32 @addchar(i8 signext %39)
br label %52
41: ; preds = %31
%42 = call i32 @addchars(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 12)
br label %52
43: ; preds = %31
%44 = call i32 @addchars(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 13)
br label %52
45: ; preds = %31
%46 = call i32 @addchars(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
br label %52
47: ; preds = %31
%48 = call i32 @addchars(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
br label %52
49: ; preds = %31
%50 = load i8*, i8** %2
%51 = call i32 @addchars(i8* %50, i32 2)
br label %52
52: ; preds = %49, %47, %45, %43, %41, %36
%53 = load i8*, i8** %2
%54 = getelementptr inbounds i8, i8* %53, i64 2
store i8* %54, i8** %2
br label %21
55: ; preds = %26
%56 = load i8*, i8** %2
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 40
br i1 %59, label %70, label %60
60: ; preds = %55
%61 = load i8*, i8** %2
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 41
br i1 %64, label %70, label %65
65: ; preds = %60
%66 = load i8*, i8** %2
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 124
br i1 %69, label %70, label %72
70: ; preds = %65, %60, %55
%71 = call i32 @addchar(i8 signext 92)
br label %72
72: ; preds = %70, %65
%73 = load i8*, i8** %2
%74 = load i8, i8* %73
%75 = call i32 @addchar(i8 signext %74)
%76 = load i8*, i8** %2
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %2
br label %21
78: ; preds = %21
%79 = call i8* (...) @getstring()
ret i8* %79
}

LLVM IR (-O2):
@.str = [13 x i8] c"[_a-zA-Z0-9]\00"
@.str.1 = [14 x i8] c"[^_a-zA-Z0-9]\00"
@.str.2 = [8 x i8] c"[[:<:]]\00"
@.str.3 = [8 x i8] c"[[:>:]]\00"
define i8* @twiddle(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 94
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @addchar(i8 signext 94)
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
br label %8
8: ; preds = %4, %1
%9 = phi i8 [ %7, %4 ], [ %2, %1 ]
%10 = phi i8* [ %6, %4 ], [ %0, %1 ]
%11 = icmp eq i8 %9, 43
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @addchar(i8 signext 92)
br label %14
14: ; preds = %12, %8
br label %15
15: ; preds = %14, %34
%16 = phi i8* [ %36, %34 ], [ %10, %14 ]
%17 = load i8, i8* %16
switch i8 %17, label %40 [
i8 0, label %43
i8 92, label %18
i8 40, label %37
i8 41, label %37
i8 124, label %37
]
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %16, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
switch i32 %21, label %32 [
i32 40, label %22
i32 41, label %22
i32 124, label %22
i32 119, label %24
i32 87, label %26
i32 60, label %28
i32 62, label %30
]
22: ; preds = %18, %18, %18
%23 = tail call i32 @addchar(i8 signext %20)
br label %34
24: ; preds = %18
%25 = tail call i32 @addchars(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 12)
br label %34
26: ; preds = %18
%27 = tail call i32 @addchars(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 13)
br label %34
28: ; preds = %18
%29 = tail call i32 @addchars(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
br label %34
30: ; preds = %18
%31 = tail call i32 @addchars(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
br label %34
32: ; preds = %18
%33 = tail call i32 @addchars(i8* %16, i32 2)
br label %34
34: ; preds = %22, %24, %26, %28, %30, %32, %40
%35 = phi i64 [ 1, %40 ], [ 2, %32 ], [ 2, %30 ], [ 2, %28 ], [ 2, %26 ], [ 2, %24 ], [ 2, %22 ]
%36 = getelementptr inbounds i8, i8* %16, i64 %35
br label %15
37: ; preds = %15, %15, %15
%38 = tail call i32 @addchar(i8 signext 92)
%39 = load i8, i8* %16
br label %40
40: ; preds = %15, %37
%41 = phi i8 [ %17, %15 ], [ %39, %37 ]
%42 = tail call i32 @addchar(i8 signext %41)
br label %34
43: ; preds = %15
%44 = tail call i8* (...) @getstring()
ret i8* %44
}