glob_compile(pattern, buffer) char *pattern;
char *buffer;
{
  char *x;
  int c;
  int result;
  if (pattern == 0 || pattern[0] == 0)
    return (-2);
  x = buffer;
  while (x < &buffer[1024 - 5]) {
    c = *pattern++;
    if (c == 0) {
      *x++ = '$';
      return (0);
    }
    switch (c) {
    case '?':
      *x++ = '?';
      continue;
    case '[':
      if ((result = compile_set(pattern, x, &buffer[1024 - 5])) < 0)
        return (result);
      pattern += result + 1;
      x += x[1] + 2;
      continue;
    case '*':
      *x++ = '*';
      continue;
    default:
      *x++ = 'X';
      *x++ = c;
      continue;
    }
  }
  return (-1);
}


x86 assembly (clang, -O0):
<glob_compile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     113b <glob_compile+0x2b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1147 <glob_compile+0x37>
movl   $0xfffffffe,-0x4(%rbp)
jmp    129f <glob_compile+0x18f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x3fb,%rcx
cmp    %rcx,%rax
jae    1298 <glob_compile+0x188>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11a4 <glob_compile+0x94>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x24,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    129f <glob_compile+0x18f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x2a,%eax
je     1254 <glob_compile+0x144>
jmp    11b8 <glob_compile+0xa8>
mov    -0x2c(%rbp),%eax
sub    $0x3f,%eax
je     11da <glob_compile+0xca>
jmp    11c9 <glob_compile+0xb9>
mov    -0x2c(%rbp),%eax
sub    $0x5b,%eax
je     11f1 <glob_compile+0xe1>
jmp    126b <glob_compile+0x15b>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x3f,(%rax)
jmp    114f <glob_compile+0x3f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x3fb,%rdx
mov    $0x0,%al
call   1030 <compile_set@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    1222 <glob_compile+0x112>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    129f <glob_compile+0x18f>
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%ecx
add    $0x2,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    114f <glob_compile+0x3f>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2a,(%rax)
jmp    114f <glob_compile+0x3f>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x58,(%rax)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    114f <glob_compile+0x3f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glob_compile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0xfffffffe,%eax
test   %rdi,%rdi
je     1212 <glob_compile+0x102>
mov    %rdi,%r12
mov    (%rdi),%cl
test   %cl,%cl
je     1212 <glob_compile+0x102>
mov    %rsi,%r14
lea    0x3fb(%rsi),%r15
xor    %r13d,%r13d
mov    %rsi,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r12
movsbl %cl,%eax
cmp    $0x2a,%eax
je     1180 <glob_compile+0x70>
cmp    $0x5b,%eax
je     11a0 <glob_compile+0x90>
cmp    $0x3f,%eax
jne    11e0 <glob_compile+0xd0>
add    $0x1,%r13
movb   $0x3f,(%rbx)
cmp    $0x3fa,%r13
jle    11f5 <glob_compile+0xe5>
jmp    120d <glob_compile+0xfd>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
movb   $0x2a,(%rbx)
cmp    $0x3fa,%r13
jle    11f5 <glob_compile+0xe5>
jmp    120d <glob_compile+0xfd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <compile_set@plt>
test   %eax,%eax
js     1212 <glob_compile+0x102>
mov    %eax,%eax
add    %rax,%r12
add    $0x1,%r12
movsbq 0x1(%rbx),%rax
add    %rax,%r13
add    $0x2,%r13
cmp    $0x3fa,%r13
jle    11f5 <glob_compile+0xe5>
jmp    120d <glob_compile+0xfd>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x58,(%rbx)
mov    %cl,0x1(%r13,%r14,1)
add    $0x2,%r13
cmp    $0x3fa,%r13
jg     120d <glob_compile+0xfd>
lea    (%r14,%r13,1),%rbx
movzbl (%r12),%ecx
test   %cl,%cl
jne    1150 <glob_compile+0x40>
movb   $0x24,(%rbx)
xor    %eax,%eax
jmp    1212 <glob_compile+0x102>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @glob_compile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11, %2
store i32 -2, i32* %3
br label %74
18: ; preds = %11
%19 = load i8*, i8** %5
store i8* %19, i8** %6
br label %20
20: ; preds = %66, %63, %49, %37, %18
%21 = load i8*, i8** %6
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 1019
%24 = icmp ult i8* %21, %23
br i1 %24, label %25, label %73
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
%28 = load i8, i8* %26
%29 = sext i8 %28 to i32
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %6
store i8 36, i8* %33
store i32 0, i32* %3
br label %74
35: ; preds = %25
%36 = load i32, i32* %7
switch i32 %36, label %66 [
i32 63, label %37
i32 91, label %40
i32 42, label %63
]
37: ; preds = %35
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %6
store i8 63, i8* %38
br label %20
40: ; preds = %35
%41 = load i8*, i8** %4
%42 = load i8*, i8** %6
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 1019
%45 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @compile_set to i32 (i8*, i8*, i8*, ...)*)(i8* %41, i8* %42, i8* %44)
store i32 %45, i32* %8
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %40
%48 = load i32, i32* %8
store i32 %48, i32* %3
br label %74
49: ; preds = %40
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
%52 = load i8*, i8** %4
%53 = sext i32 %51 to i64
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8* %54, i8** %4
%55 = load i8*, i8** %6
%56 = getelementptr inbounds i8, i8* %55, i64 1
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = add nsw i32 %58, 2
%60 = load i8*, i8** %6
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds i8, i8* %60, i64 %61
store i8* %62, i8** %6
br label %20
63: ; preds = %35
%64 = load i8*, i8** %6
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %6
store i8 42, i8* %64
br label %20
66: ; preds = %35
%67 = load i8*, i8** %6
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %6
store i8 88, i8* %67
%69 = load i32, i32* %7
%70 = trunc i32 %69 to i8
%71 = load i8*, i8** %6
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %6
store i8 %70, i8* %71
br label %20
73: ; preds = %20
store i32 -1, i32* %3
br label %74
74: ; preds = %73, %47, %32, %17
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
define i32 @glob_compile(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %45, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %45, label %7
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %1, i64 1019
br label %10
9: ; preds = %23
store i8 36, i8* %24
br label %45
10: ; preds = %7, %23
%11 = phi i8* [ %0, %7 ], [ %21, %23 ]
%12 = phi i64 [ 0, %7 ], [ %20, %23 ]
%13 = phi i8* [ %1, %7 ], [ %24, %23 ]
%14 = phi i8 [ %5, %7 ], [ %25, %23 ]
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = sext i8 %14 to i32
switch i32 %16, label %41 [
i32 63, label %17
i32 91, label %27
i32 42, label %39
]
17: ; preds = %10
%18 = add nsw i64 %12, 1
store i8 63, i8* %13
br label %19
19: ; preds = %17, %30, %39, %41
%20 = phi i64 [ %44, %41 ], [ %40, %39 ], [ %38, %30 ], [ %18, %17 ]
%21 = phi i8* [ %15, %41 ], [ %15, %39 ], [ %33, %30 ], [ %15, %17 ]
%22 = icmp slt i64 %20, 1019
br i1 %22, label %23, label %45
23: ; preds = %19
%24 = getelementptr inbounds i8, i8* %1, i64 %20
%25 = load i8, i8* %21
%26 = icmp eq i8 %25, 0
br i1 %26, label %9, label %10
27: ; preds = %10
%28 = tail call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @compile_set to i32 (i8*, i8*, i8*, ...)*)(i8* %15, i8* %13, i8* %8)
%29 = icmp slt i32 %28, 0
br i1 %29, label %45, label %30
30: ; preds = %27
%31 = add nuw nsw i32 %28, 1
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %15, i64 %32
%34 = getelementptr inbounds i8, i8* %13, i64 1
%35 = load i8, i8* %34
%36 = sext i8 %35 to i64
%37 = add nsw i64 %12, 2
%38 = add i64 %37, %36
br label %19
39: ; preds = %10
%40 = add nsw i64 %12, 1
store i8 42, i8* %13
br label %19
41: ; preds = %10
%42 = add nsw i64 %12, 1
%43 = getelementptr inbounds i8, i8* %1, i64 %42
store i8 88, i8* %13
%44 = add nsw i64 %12, 2
store i8 %14, i8* %43
br label %19
45: ; preds = %19, %27, %2, %4, %9
%46 = phi i32 [ 0, %9 ], [ -2, %4 ], [ -2, %2 ], [ -1, %19 ], [ %28, %27 ]
ret i32 %46
}