void gm2re(mask, dest) char *mask;
char *dest;
{
  *dest = 0;
  for (; *mask != 0; mask++)
    switch (*mask) {
    case '?':
      *dest = '.';
      *(++dest) = 0;
      break;
    case '*':
      *dest = '.';
      *(++dest) = '*';
      *(++dest) = 0;
      break;
    case '$':
    case '^':
    case '+':
    case '.':
      *dest = '\\';
      *(++dest) = *mask;
      *(++dest) = 0;
      break;
    default:
      *dest = *mask;
      *(++dest) = 0;
      break;
    }
}


x86 assembly (clang, -O0):
<gm2re>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     124d <gm2re+0x14d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x24,%eax
je     11e1 <gm2re+0xe1>
jmp    113b <gm2re+0x3b>
mov    -0x14(%rbp),%eax
sub    $0x2a,%eax
je     11af <gm2re+0xaf>
jmp    114c <gm2re+0x4c>
mov    -0x14(%rbp),%eax
sub    $0x2b,%eax
je     11e1 <gm2re+0xe1>
jmp    115d <gm2re+0x5d>
mov    -0x14(%rbp),%eax
sub    $0x2e,%eax
je     11e1 <gm2re+0xe1>
jmp    116e <gm2re+0x6e>
mov    -0x14(%rbp),%eax
sub    $0x3f,%eax
je     1190 <gm2re+0x90>
jmp    117f <gm2re+0x7f>
mov    -0x14(%rbp),%eax
sub    $0x5e,%eax
je     11e1 <gm2re+0xe1>
jmp    1218 <gm2re+0x118>
mov    -0x10(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,0x1(%rax)
jmp    1237 <gm2re+0x137>
mov    -0x10(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2a,0x1(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,0x1(%rax)
jmp    1237 <gm2re+0x137>
mov    -0x10(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,0x1(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,0x1(%rax)
jmp    1237 <gm2re+0x137>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,0x1(%rax)
jmp    123c <gm2re+0x13c>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1113 <gm2re+0x13>
pop    %rbp
ret

x86 assembly (clang, -O2):
<gm2re>:
movb   $0x0,(%rsi)
mov    (%rdi),%cl
test   %cl,%cl
je     1178 <gm2re+0x78>
add    $0x1,%rdi
movabs $0x400000000000481,%rax
jmp    1132 <gm2re+0x32>
mov    %cl,(%rsi)
mov    $0x1,%ecx
movb   $0x0,(%rsi,%rcx,1)
add    %rcx,%rsi
movzbl (%rdi),%ecx
add    $0x1,%rdi
test   %cl,%cl
je     1178 <gm2re+0x78>
movsbl %cl,%edx
add    $0xffffffdc,%edx
cmp    $0x3a,%edx
ja     1119 <gm2re+0x19>
bt     %rdx,%rax
jae    1160 <gm2re+0x60>
movb   $0x5c,(%rsi)
movzbl -0x1(%rdi),%ecx
mov    %cl,0x1(%rsi)
mov    $0x2,%ecx
jmp    1120 <gm2re+0x20>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x6,%rdx
je     1171 <gm2re+0x71>
cmp    $0x1b,%rdx
jne    1119 <gm2re+0x19>
movb   $0x2e,(%rsi)
jmp    111b <gm2re+0x1b>
movw   $0x2a2e,(%rsi)
jmp    114d <gm2re+0x4d>
ret

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

LLVM IR (-O2):
define void @gm2re(i8* nocapture %0, i8* nocapture writeonly %1) {
store i8 0, i8* %1
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %2, %17
%6 = phi i8 [ %21, %17 ], [ %3, %2 ]
%7 = phi i8* [ %19, %17 ], [ %1, %2 ]
%8 = phi i8* [ %20, %17 ], [ %0, %2 ]
%9 = sext i8 %6 to i32
switch i32 %9, label %16 [
i32 63, label %10
i32 42, label %11
i32 36, label %13
i32 94, label %13
i32 43, label %13
i32 46, label %13
]
10: ; preds = %5
store i8 46, i8* %7
br label %17
11: ; preds = %5
store i8 46, i8* %7
%12 = getelementptr inbounds i8, i8* %7, i64 1
store i8 42, i8* %12
br label %17
13: ; preds = %5, %5, %5, %5
store i8 92, i8* %7
%14 = load i8, i8* %8
%15 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %14, i8* %15
br label %17
16: ; preds = %5
store i8 %6, i8* %7
br label %17
17: ; preds = %10, %11, %13, %16
%18 = phi i64 [ 1, %10 ], [ 2, %11 ], [ 2, %13 ], [ 1, %16 ]
%19 = getelementptr inbounds i8, i8* %7, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds i8, i8* %8, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %5
23: ; preds = %17, %2
ret void
}