#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 */
scalar_t__ xmalloc(int);
int compilephrase_rx(char *phrase, const char *end, unsigned **sequenceBuf,
                     int *lengthBuf) {
  unsigned *sequence = (unsigned *)xmalloc(sizeof(int) * (end - phrase));
  int length = 0;
  int escape = 0;
  unsigned char byte;
  while (phrase != end) {
    byte = *phrase;
    ++phrase;
    if (escape) {
      escape = 0;
      switch (byte) {
      case 'S':
        sequence[length] = ((unsigned)0x103);
        ++length;
        break;
      case 's':
        sequence[length] = ((unsigned)0x104);
        ++length;
        break;
      case 'D':
        sequence[length] = ((unsigned)0x105);
        ++length;
        break;
      case 'd':
        sequence[length] = ((unsigned)0x106);
        ++length;
        break;
      default:
        sequence[length] = ((unsigned)byte);
        ++length;
      }
    } else {
      switch (byte) {
      case '\\':
        escape = 1;
        break;
      case '*':
        sequence[length] = ((unsigned)0x102);
        ++length;
        break;
      case '?':
        sequence[length] = ((unsigned)0x101);
        ++length;
        break;
      default:
        sequence[length] = ((unsigned)byte);
        ++length;
      }
    }
  }
  *sequenceBuf = sequence;
  *lengthBuf = length;
  return 0;
}


x86 assembly (clang, -O0):
<compilephrase_rx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <xmalloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     12fc <compilephrase_rx+0x1ec>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x31(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     125d <compilephrase_rx+0x14d>
movl   $0x0,-0x30(%rbp)
movzbl -0x31(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x44,%eax
je     1206 <compilephrase_rx+0xf6>
jmp    1199 <compilephrase_rx+0x89>
mov    -0x38(%rbp),%eax
sub    $0x53,%eax
je     11cc <compilephrase_rx+0xbc>
jmp    11aa <compilephrase_rx+0x9a>
mov    -0x38(%rbp),%eax
sub    $0x64,%eax
je     1223 <compilephrase_rx+0x113>
jmp    11bb <compilephrase_rx+0xab>
mov    -0x38(%rbp),%eax
sub    $0x73,%eax
je     11e9 <compilephrase_rx+0xd9>
jmp    1240 <compilephrase_rx+0x130>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x103,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1258 <compilephrase_rx+0x148>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x104,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1258 <compilephrase_rx+0x148>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x105,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1258 <compilephrase_rx+0x148>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x106,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1258 <compilephrase_rx+0x148>
movzbl -0x31(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12f7 <compilephrase_rx+0x1e7>
movzbl -0x31(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x2a,%eax
je     12a0 <compilephrase_rx+0x190>
jmp    1272 <compilephrase_rx+0x162>
mov    -0x3c(%rbp),%eax
sub    $0x3f,%eax
je     12bd <compilephrase_rx+0x1ad>
jmp    1283 <compilephrase_rx+0x173>
mov    -0x3c(%rbp),%eax
sub    $0x5c,%eax
jne    12da <compilephrase_rx+0x1ca>
jmp    1294 <compilephrase_rx+0x184>
movl   $0x1,-0x30(%rbp)
jmp    12f2 <compilephrase_rx+0x1e2>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x102,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12f2 <compilephrase_rx+0x1e2>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x101,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12f2 <compilephrase_rx+0x1e2>
movzbl -0x31(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12f7 <compilephrase_rx+0x1e7>
jmp    1150 <compilephrase_rx+0x40>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compilephrase_rx>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %r12d,%edi
sub    %ebx,%edi
shl    $0x2,%edi
call   1030 <xmalloc@plt>
cmp    %rbx,%r12
je     11e6 <compilephrase_rx+0xd6>
xor    %esi,%esi
xor    %ecx,%ecx
xchg   %ax,%ax
movzbl (%rbx),%edx
add    $0x1,%rbx
test   %esi,%esi
je     1170 <compilephrase_rx+0x60>
cmp    $0x63,%dl
jg     1190 <compilephrase_rx+0x80>
cmp    $0x44,%dl
je     11a7 <compilephrase_rx+0x97>
mov    $0x103,%esi
cmp    $0x53,%dl
je     11c0 <compilephrase_rx+0xb0>
jmp    11a3 <compilephrase_rx+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x2a,%dl
je     11b5 <compilephrase_rx+0xa5>
cmp    $0x5c,%dl
je     11d6 <compilephrase_rx+0xc6>
cmp    $0x3f,%dl
jne    11a3 <compilephrase_rx+0x93>
mov    $0x101,%esi
jmp    11c0 <compilephrase_rx+0xb0>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x64,%dl
je     11ae <compilephrase_rx+0x9e>
mov    %edx,%esi
cmp    $0x73,%dl
jne    11c0 <compilephrase_rx+0xb0>
mov    $0x104,%esi
jmp    11c0 <compilephrase_rx+0xb0>
mov    %edx,%esi
jmp    11c0 <compilephrase_rx+0xb0>
mov    $0x105,%esi
jmp    11c0 <compilephrase_rx+0xb0>
mov    $0x106,%esi
jmp    11c0 <compilephrase_rx+0xb0>
mov    $0x102,%esi
nopw   0x0(%rax,%rax,1)
movslq %ecx,%rcx
mov    %esi,(%rax,%rcx,4)
add    $0x1,%ecx
xor    %esi,%esi
cmp    %r12,%rbx
jne    1140 <compilephrase_rx+0x30>
jmp    11e8 <compilephrase_rx+0xd8>
mov    $0x1,%esi
cmp    %r12,%rbx
jne    1140 <compilephrase_rx+0x30>
jmp    11e8 <compilephrase_rx+0xd8>
xor    %ecx,%ecx
mov    %rax,(%r15)
mov    %ecx,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @compilephrase_rx(i8* %0, i8* %1, i32** %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32**
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32** %2, i32*** %7
store i32* %3, i32** %8
%13 = load i8*, i8** %6
%14 = load i8*, i8** %5
%15 = ptrtoint i8* %13 to i64
%16 = ptrtoint i8* %14 to i64
%17 = sub i64 %15, %16
%18 = mul i64 4, %17
%19 = trunc i64 %18 to i32
%20 = call i64 @xmalloc(i32 %19)
%21 = inttoptr i64 %20 to i32*
store i32* %21, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %22
22: ; preds = %102, %4
%23 = load i8*, i8** %5
%24 = load i8*, i8** %6
%25 = icmp ne i8* %23, %24
br i1 %25, label %26, label %103
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
store i8 %28, i8* %12
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %5
%31 = load i32, i32* %11
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %74
33: ; preds = %26
store i32 0, i32* %11
%34 = load i8, i8* %12
%35 = zext i8 %34 to i32
switch i32 %35, label %64 [
i32 83, label %36
i32 115, label %43
i32 68, label %50
i32 100, label %57
]
36: ; preds = %33
%37 = load i32*, i32** %9
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 259, i32* %40
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %73
43: ; preds = %33
%44 = load i32*, i32** %9
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
store i32 260, i32* %47
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
br label %73
50: ; preds = %33
%51 = load i32*, i32** %9
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
store i32 261, i32* %54
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %73
57: ; preds = %33
%58 = load i32*, i32** %9
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
store i32 262, i32* %61
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
br label %73
64: ; preds = %33
%65 = load i8, i8* %12
%66 = zext i8 %65 to i32
%67 = load i32*, i32** %9
%68 = load i32, i32* %10
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
store i32 %66, i32* %70
%71 = load i32, i32* %10
%72 = add nsw i32 %71, 1
store i32 %72, i32* %10
br label %73
73: ; preds = %64, %57, %50, %43, %36
br label %102
74: ; preds = %26
%75 = load i8, i8* %12
%76 = zext i8 %75 to i32
switch i32 %76, label %92 [
i32 92, label %77
i32 42, label %78
i32 63, label %85
]
77: ; preds = %74
store i32 1, i32* %11
br label %101
78: ; preds = %74
%79 = load i32*, i32** %9
%80 = load i32, i32* %10
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %79, i64 %81
store i32 258, i32* %82
%83 = load i32, i32* %10
%84 = add nsw i32 %83, 1
store i32 %84, i32* %10
br label %101
85: ; preds = %74
%86 = load i32*, i32** %9
%87 = load i32, i32* %10
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i32, i32* %86, i64 %88
store i32 257, i32* %89
%90 = load i32, i32* %10
%91 = add nsw i32 %90, 1
store i32 %91, i32* %10
br label %101
92: ; preds = %74
%93 = load i8, i8* %12
%94 = zext i8 %93 to i32
%95 = load i32*, i32** %9
%96 = load i32, i32* %10
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i32, i32* %95, i64 %97
store i32 %94, i32* %98
%99 = load i32, i32* %10
%100 = add nsw i32 %99, 1
store i32 %100, i32* %10
br label %101
101: ; preds = %92, %85, %78, %77
br label %102
102: ; preds = %101, %73
br label %22
103: ; preds = %22
%104 = load i32*, i32** %9
%105 = load i32**, i32*** %7
store i32* %104, i32** %105
%106 = load i32, i32* %10
%107 = load i32*, i32** %8
store i32 %106, i32* %107
ret i32 0
}

LLVM IR (-O2):
define i32 @compilephrase_rx(i8* %0, i8* %1, i32** nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = ptrtoint i8* %1 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
%8 = trunc i64 %7 to i32
%9 = shl i32 %8, 2
%10 = tail call i64 @xmalloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
%12 = icmp eq i8* %0, %1
br i1 %12, label %39, label %13
13: ; preds = %4, %35
%14 = phi i8* [ %18, %35 ], [ %0, %4 ]
%15 = phi i32 [ %37, %35 ], [ 0, %4 ]
%16 = phi i32 [ %36, %35 ], [ 0, %4 ]
%17 = load i8, i8* %14
%18 = getelementptr inbounds i8, i8* %14, i64 1
%19 = icmp eq i32 %15, 0
br i1 %19, label %26, label %20
20: ; preds = %13
switch i8 %17, label %24 [
i8 83, label %30
i8 115, label %21
i8 68, label %22
i8 100, label %23
]
21: ; preds = %20
br label %30
22: ; preds = %20
br label %30
23: ; preds = %20
br label %30
24: ; preds = %20
%25 = zext i8 %17 to i32
br label %30
26: ; preds = %13
switch i8 %17, label %28 [
i8 92, label %35
i8 42, label %30
i8 63, label %27
]
27: ; preds = %26
br label %30
28: ; preds = %26
%29 = zext i8 %17 to i32
br label %30
30: ; preds = %26, %20, %24, %23, %22, %21, %28, %27
%31 = phi i32 [ 257, %27 ], [ %29, %28 ], [ 260, %21 ], [ 261, %22 ], [ 262, %23 ], [ %25, %24 ], [ 259, %20 ], [ 258, %26 ]
%32 = sext i32 %16 to i64
%33 = getelementptr inbounds i32, i32* %11, i64 %32
store i32 %31, i32* %33
%34 = add nsw i32 %16, 1
br label %35
35: ; preds = %30, %26
%36 = phi i32 [ %16, %26 ], [ %34, %30 ]
%37 = phi i32 [ 1, %26 ], [ 0, %30 ]
%38 = icmp eq i8* %18, %1
br i1 %38, label %39, label %13
39: ; preds = %35, %4
%40 = phi i32 [ 0, %4 ], [ %36, %35 ]
store i32* %11, i32** %2
store i32 %40, i32* %3
ret i32 0
}