char *patsubst_expand(o, text, pattern, replace, pattern_percent,
                      replace_percent)
char *o;
char *text;
register char *pattern, *replace;
register char *pattern_percent, *replace_percent;
{
  register int pattern_prepercent_len, pattern_postpercent_len;
  register int replace_prepercent_len, replace_postpercent_len;
  register char *t;
  unsigned int len;
  int doneany = 0;
  if (replace_percent == 0)
    replace_percent = find_percent(replace);
  if (replace_percent != 0) {
    replace_prepercent_len = replace_percent - replace;
    replace_postpercent_len = strlen(replace_percent + 1);
  } else
    replace_prepercent_len = strlen(replace);
  if (pattern_percent == 0)
    pattern_percent = find_percent(pattern);
  if (pattern_percent == 0)
    return subst_expand(o, text, pattern, replace, strlen(pattern),
                        strlen(replace), 1, 0);
  pattern_prepercent_len = pattern_percent - pattern;
  pattern_postpercent_len = strlen(pattern_percent + 1);
  while (t = find_next_token(&text, &len)) {
    int fail = 0;
    if (len < pattern_prepercent_len + pattern_postpercent_len)
      fail = 1;
    if (!fail && pattern_prepercent_len > 0 &&
        (*t != *pattern ||
         t[pattern_prepercent_len - 1] != pattern_percent[-1] ||
         strncmp(t + 1, pattern + 1, pattern_prepercent_len - 1)))
      fail = 1;
    if (!fail && pattern_postpercent_len > 0 &&
        (t[len - 1] != pattern_percent[pattern_postpercent_len] ||
         t[len - pattern_postpercent_len] != pattern_percent[1] ||
         strncmp(&t[len - pattern_postpercent_len], &pattern_percent[1],
                 pattern_postpercent_len - 1)))
      fail = 1;
    if (fail)
      o = variable_buffer_output(o, t, len);
    else {
      o = variable_buffer_output(o, replace, replace_prepercent_len);
      if (replace_percent != 0) {
        o = variable_buffer_output(
            o, t + pattern_prepercent_len,
            len - (pattern_prepercent_len + pattern_postpercent_len));
        o = variable_buffer_output(o, replace_percent + 1,
                                   replace_postpercent_len);
      }
    }
    if (fail || replace_prepercent_len > 0 ||
        (replace_percent != 0 && len + replace_postpercent_len > 0)) {
      o = variable_buffer_output(o, " ", 1);
      doneany = 1;
    }
  }
  if (doneany)
    --o;
  return o;
}


x86 assembly (clang, -O0):
<patsubst_expand>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movl   $0x0,-0x58(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11a6 <patsubst_expand+0x46>
mov    -0x28(%rbp),%rdi
mov    $0x0,%al
call   1070 <find_percent@plt>
cltq
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11d4 <patsubst_expand+0x74>
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1040 <strlen@plt>
mov    %eax,-0x48(%rbp)
jmp    11e0 <patsubst_expand+0x80>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11fc <patsubst_expand+0x9c>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1070 <find_percent@plt>
cltq
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    127d <patsubst_expand+0x11d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    -0x78(%rbp),%rdx
mov    -0x70(%rbp),%rcx
mov    -0x68(%rbp),%r8
mov    %rax,%r9
xor    %eax,%eax
movl   $0x1,(%rsp)
movl   $0x0,0x8(%rsp)
mov    $0x0,%al
call   1050 <subst_expand@plt>
cltq
mov    %rax,-0x8(%rbp)
jmp    14e6 <patsubst_expand+0x386>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x54(%rbp),%rsi
mov    $0x0,%al
call   1080 <find_next_token@plt>
cltq
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
je     14c8 <patsubst_expand+0x368>
movl   $0x0,-0x5c(%rbp)
mov    -0x54(%rbp),%eax
mov    -0x3c(%rbp),%ecx
add    -0x40(%rbp),%ecx
cmp    %ecx,%eax
jae    12d9 <patsubst_expand+0x179>
movl   $0x1,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    1352 <patsubst_expand+0x1f2>
cmpl   $0x0,-0x3c(%rbp)
jle    1352 <patsubst_expand+0x1f2>
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    134b <patsubst_expand+0x1eb>
mov    -0x50(%rbp),%rax
mov    -0x3c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x30(%rbp),%rcx
movsbl -0x1(%rcx),%ecx
cmp    %ecx,%eax
jne    134b <patsubst_expand+0x1eb>
mov    -0x50(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     1352 <patsubst_expand+0x1f2>
movl   $0x1,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    13df <patsubst_expand+0x27f>
cmpl   $0x0,-0x40(%rbp)
jle    13df <patsubst_expand+0x27f>
mov    -0x50(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x30(%rbp),%rcx
movslq -0x40(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    13d8 <patsubst_expand+0x278>
mov    -0x50(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    -0x40(%rbp),%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x30(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
cmp    %ecx,%eax
jne    13d8 <patsubst_expand+0x278>
mov    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%eax
sub    -0x40(%rbp),%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
add    $0x1,%rsi
mov    -0x40(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     13df <patsubst_expand+0x27f>
movl   $0x1,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     1406 <patsubst_expand+0x2a6>
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
mov    $0x0,%al
call   1060 <variable_buffer_output@plt>
cltq
mov    %rax,-0x10(%rbp)
jmp    1471 <patsubst_expand+0x311>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x44(%rbp),%edx
mov    $0x0,%al
call   1060 <variable_buffer_output@plt>
cltq
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     146c <patsubst_expand+0x30c>
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
mov    -0x54(%rbp),%edx
mov    -0x3c(%rbp),%eax
add    -0x40(%rbp),%eax
sub    %eax,%edx
mov    $0x0,%al
call   1060 <variable_buffer_output@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
mov    -0x48(%rbp),%edx
mov    $0x0,%al
call   1060 <variable_buffer_output@plt>
cltq
mov    %rax,-0x10(%rbp)
jmp    1471 <patsubst_expand+0x311>
cmpl   $0x0,-0x5c(%rbp)
jne    149f <patsubst_expand+0x33f>
cmpl   $0x0,-0x44(%rbp)
jg     149f <patsubst_expand+0x33f>
cmpq   $0x0,-0x38(%rbp)
je     14c3 <patsubst_expand+0x363>
mov    -0x54(%rbp),%eax
add    -0x48(%rbp),%eax
cmp    $0x0,%eax
jbe    14c3 <patsubst_expand+0x363>
mov    -0x10(%rbp),%rdi
lea    0xb56(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1060 <variable_buffer_output@plt>
cltq
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    129b <patsubst_expand+0x13b>
cmpl   $0x0,-0x58(%rbp)
je     14de <patsubst_expand+0x37e>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<patsubst_expand>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r9,%rbp
mov    %r8,%r13
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,0x50(%rsp)
test   %r9,%r9
jne    119e <patsubst_expand+0x3e>
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <find_percent@plt>
test   %eax,%eax
je     11db <patsubst_expand+0x7b>
movslq %eax,%rbp
mov    %rbp,%rax
sub    %r12,%rax
mov    %rax,0x28(%rsp)
lea    0x1(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,0x10(%rsp)
movl   $0x0,0xc(%rsp)
test   %r13,%r13
jne    11fa <patsubst_expand+0x9a>
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <find_percent@plt>
test   %eax,%eax
je     142e <patsubst_expand+0x2ce>
movslq %eax,%r13
jmp    11fa <patsubst_expand+0x9a>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rax,0x28(%rsp)
mov    $0x1,%al
mov    %eax,0xc(%rsp)
xor    %ebp,%ebp
mov    %rax,0x10(%rsp)
test   %r13,%r13
je     11c4 <patsubst_expand+0x64>
mov    %rbp,0x20(%rsp)
lea    0x1(%r13),%rdi
mov    %rdi,0x30(%rsp)
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r13,%rbp
xor    %r13d,%r13d
lea    0x50(%rsp),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1080 <find_next_token@plt>
test   %eax,%eax
je     1411 <patsubst_expand+0x2b1>
mov    %r12,0x70(%rsp)
mov    %r14,%rcx
mov    %rbp,0x40(%rsp)
mov    %rbp,%r14
sub    %rcx,%r14
mov    %r15,%rdx
add    %r14d,%r15d
mov    $0xffffffff,%esi
lea    (%r14,%rsi,1),%edi
mov    %rdi,0x38(%rsp)
mov    %rcx,0x80(%rsp)
add    $0x1,%rcx
mov    %rcx,0x68(%rsp)
mov    %rdx,0x48(%rsp)
movslq %edx,%rdx
mov    %rdx,%rcx
mov    %rdx,0x78(%rsp)
add    %edx,%esi
mov    %rsi,0x60(%rsp)
movslq %r14d,%rcx
mov    %rcx,0x58(%rsp)
addq   $0x1,0x20(%rsp)
mov    0x10(%rsp),%rcx
neg    %ecx
mov    %ecx,0x1c(%rsp)
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
movslq %eax,%r12
mov    0x8(%rsp),%ebp
xor    %eax,%eax
cmp    %r15d,%ebp
setb   %al
jb     1300 <patsubst_expand+0x1a0>
test   %r14d,%r14d
jle    1300 <patsubst_expand+0x1a0>
movzbl (%r12),%eax
mov    0x80(%rsp),%rcx
cmp    (%rcx),%al
jne    1354 <patsubst_expand+0x1f4>
mov    0x38(%rsp),%rax
movzbl (%r12,%rax,1),%eax
mov    0x40(%rsp),%rcx
cmp    -0x1(%rcx),%al
jne    1354 <patsubst_expand+0x1f4>
lea    0x1(%r12),%rdi
mov    0x68(%rsp),%rsi
mov    0x38(%rsp),%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1354 <patsubst_expand+0x1f4>
xor    %eax,%eax
nopl   0x0(%rax)
test   %eax,%eax
jne    1350 <patsubst_expand+0x1f0>
cmpl   $0x0,0x48(%rsp)
jle    1350 <patsubst_expand+0x1f0>
lea    -0x1(%rbp),%eax
movzbl (%r12,%rax,1),%eax
mov    0x40(%rsp),%rcx
mov    0x78(%rsp),%rdx
cmp    (%rcx,%rdx,1),%al
jne    1354 <patsubst_expand+0x1f4>
mov    %ebp,%edi
sub    0x48(%rsp),%edi
movzbl (%r12,%rdi,1),%eax
mov    0x30(%rsp),%rcx
cmp    (%rcx),%al
jne    1354 <patsubst_expand+0x1f4>
add    %r12,%rdi
mov    0x30(%rsp),%rsi
mov    0x60(%rsp),%rdx
call   1030 <strncmp@plt>
nopl   0x0(%rax,%rax,1)
test   %eax,%eax
je     13a0 <patsubst_expand+0x240>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <variable_buffer_output@plt>
movslq %eax,%rbx
mov    $0x1,%r13d
mov    %rbx,%rdi
lea    0xc8a(%rip),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1060 <variable_buffer_output@plt>
movslq %eax,%rbx
lea    0x50(%rsp),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1080 <find_next_token@plt>
test   %eax,%eax
jne    12a0 <patsubst_expand+0x140>
jmp    1411 <patsubst_expand+0x2b1>
mov    %rbx,%rdi
mov    0x70(%rsp),%rsi
mov    0x28(%rsp),%rbp
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <variable_buffer_output@plt>
movslq %eax,%rbx
cmpb   $0x0,0xc(%rsp)
je     13c6 <patsubst_expand+0x266>
test   %ebp,%ebp
jg     1366 <patsubst_expand+0x206>
jmp    1385 <patsubst_expand+0x225>
add    0x58(%rsp),%r12
mov    0x8(%rsp),%edx
sub    %r15d,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <variable_buffer_output@plt>
movslq %eax,%rdi
mov    0x20(%rsp),%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <variable_buffer_output@plt>
movslq %eax,%rbx
test   %ebp,%ebp
jg     1366 <patsubst_expand+0x206>
mov    0x1c(%rsp),%eax
cmp    %eax,0x8(%rsp)
je     1385 <patsubst_expand+0x225>
jmp    1366 <patsubst_expand+0x206>
cmp    $0x1,%r13d
adc    $0xffffffffffffffff,%rbx
mov    %rbx,%rax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rbp
mov    %rax,%r14
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r12,%rcx
mov    %r14,%r8
mov    %rax,%r9
xor    %eax,%eax
push   $0x0
push   $0x1
call   1050 <subst_expand@plt>
add    $0x10,%rsp
movslq %eax,%rbx
jmp    1419 <patsubst_expand+0x2b9>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8* @patsubst_expand(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i32 0, i32* %20
%22 = load i8*, i8** %13
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %6
%25 = load i8*, i8** %11
%26 = call i32 (i8*, ...) bitcast (i32 (...)* @find_percent to i32 (i8*, ...)*)(i8* %25)
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %13
br label %29
29: ; preds = %24, %6
%30 = load i8*, i8** %13
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %43
32: ; preds = %29
%33 = load i8*, i8** %13
%34 = load i8*, i8** %11
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
store i32 %38, i32* %16
%39 = load i8*, i8** %13
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = call i64 @strlen(i8* %40)
%42 = trunc i64 %41 to i32
store i32 %42, i32* %17
br label %47
43: ; preds = %29
%44 = load i8*, i8** %11
%45 = call i64 @strlen(i8* %44)
%46 = trunc i64 %45 to i32
store i32 %46, i32* %16
br label %47
47: ; preds = %43, %32
%48 = load i8*, i8** %12
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i8*, i8** %10
%52 = call i32 (i8*, ...) bitcast (i32 (...)* @find_percent to i32 (i8*, ...)*)(i8* %51)
%53 = sext i32 %52 to i64
%54 = inttoptr i64 %53 to i8*
store i8* %54, i8** %12
br label %55
55: ; preds = %50, %47
%56 = load i8*, i8** %12
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %70
58: ; preds = %55
%59 = load i8*, i8** %8
%60 = load i8*, i8** %9
%61 = load i8*, i8** %10
%62 = load i8*, i8** %11
%63 = load i8*, i8** %10
%64 = call i64 @strlen(i8* %63)
%65 = load i8*, i8** %11
%66 = call i64 @strlen(i8* %65)
%67 = call i32 (i8*, i8*, i8*, i8*, i64, i64, i32, i32, ...) bitcast (i32 (...)* @subst_expand to i32 (i8*, i8*, i8*, i8*, i64, i64, i32, i32, ...)*)(i8* %59, i8* %60, i8* %61, i8* %62, i64 %64, i64 %66, i32 1, i32 0)
%68 = sext i32 %67 to i64
%69 = inttoptr i64 %68 to i8*
store i8* %69, i8** %7
br label %250
70: ; preds = %55
%71 = load i8*, i8** %12
%72 = load i8*, i8** %10
%73 = ptrtoint i8* %71 to i64
%74 = ptrtoint i8* %72 to i64
%75 = sub i64 %73, %74
%76 = trunc i64 %75 to i32
store i32 %76, i32* %14
%77 = load i8*, i8** %12
%78 = getelementptr inbounds i8, i8* %77, i64 1
%79 = call i64 @strlen(i8* %78)
%80 = trunc i64 %79 to i32
store i32 %80, i32* %15
br label %81
81: ; preds = %241, %70
%82 = call i32 (i8**, i32*, ...) bitcast (i32 (...)* @find_next_token to i32 (i8**, i32*, ...)*)(i8** %9, i32* %19)
%83 = sext i32 %82 to i64
%84 = inttoptr i64 %83 to i8*
store i8* %84, i8** %18
%85 = icmp ne i8* %84, null
br i1 %85, label %86, label %242
86: ; preds = %81
store i32 0, i32* %21
%87 = load i32, i32* %19
%88 = load i32, i32* %14
%89 = load i32, i32* %15
%90 = add nsw i32 %88, %89
%91 = icmp ult i32 %87, %90
br i1 %91, label %92, label %93
92: ; preds = %86
store i32 1, i32* %21
br label %93
93: ; preds = %92, %86
%94 = load i32, i32* %21
%95 = icmp ne i32 %94, 0
br i1 %95, label %131, label %96
96: ; preds = %93
%97 = load i32, i32* %14
%98 = icmp sgt i32 %97, 0
br i1 %98, label %99, label %131
99: ; preds = %96
%100 = load i8*, i8** %18
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = load i8*, i8** %10
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = icmp ne i32 %102, %105
br i1 %106, label %130, label %107
107: ; preds = %99
%108 = load i8*, i8** %18
%109 = load i32, i32* %14
%110 = sub nsw i32 %109, 1
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8, i8* %108, i64 %111
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = load i8*, i8** %12
%116 = getelementptr inbounds i8, i8* %115, i64 -1
%117 = load i8, i8* %116
%118 = sext i8 %117 to i32
%119 = icmp ne i32 %114, %118
br i1 %119, label %130, label %120
120: ; preds = %107
%121 = load i8*, i8** %18
%122 = getelementptr inbounds i8, i8* %121, i64 1
%123 = load i8*, i8** %10
%124 = getelementptr inbounds i8, i8* %123, i64 1
%125 = load i32, i32* %14
%126 = sub nsw i32 %125, 1
%127 = sext i32 %126 to i64
%128 = call i32 @strncmp(i8* %122, i8* %124, i64 %127)
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %131
130: ; preds = %120, %107, %99
store i32 1, i32* %21
br label %131
131: ; preds = %130, %120, %96, %93
%132 = load i32, i32* %21
%133 = icmp ne i32 %132, 0
br i1 %133, label %181, label %134
134: ; preds = %131
%135 = load i32, i32* %15
%136 = icmp sgt i32 %135, 0
br i1 %136, label %137, label %181
137: ; preds = %134
%138 = load i8*, i8** %18
%139 = load i32, i32* %19
%140 = sub i32 %139, 1
%141 = zext i32 %140 to i64
%142 = getelementptr inbounds i8, i8* %138, i64 %141
%143 = load i8, i8* %142
%144 = sext i8 %143 to i32
%145 = load i8*, i8** %12
%146 = load i32, i32* %15
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds i8, i8* %145, i64 %147
%149 = load i8, i8* %148
%150 = sext i8 %149 to i32
%151 = icmp ne i32 %144, %150
br i1 %151, label %180, label %152
152: ; preds = %137
%153 = load i8*, i8** %18
%154 = load i32, i32* %19
%155 = load i32, i32* %15
%156 = sub i32 %154, %155
%157 = zext i32 %156 to i64
%158 = getelementptr inbounds i8, i8* %153, i64 %157
%159 = load i8, i8* %158
%160 = sext i8 %159 to i32
%161 = load i8*, i8** %12
%162 = getelementptr inbounds i8, i8* %161, i64 1
%163 = load i8, i8* %162
%164 = sext i8 %163 to i32
%165 = icmp ne i32 %160, %164
br i1 %165, label %180, label %166
166: ; preds = %152
%167 = load i8*, i8** %18
%168 = load i32, i32* %19
%169 = load i32, i32* %15
%170 = sub i32 %168, %169
%171 = zext i32 %170 to i64
%172 = getelementptr inbounds i8, i8* %167, i64 %171
%173 = load i8*, i8** %12
%174 = getelementptr inbounds i8, i8* %173, i64 1
%175 = load i32, i32* %15
%176 = sub nsw i32 %175, 1
%177 = sext i32 %176 to i64
%178 = call i32 @strncmp(i8* %172, i8* %174, i64 %177)
%179 = icmp ne i32 %178, 0
br i1 %179, label %180, label %181
180: ; preds = %166, %152, %137
store i32 1, i32* %21
br label %181
181: ; preds = %180, %166, %134, %131
%182 = load i32, i32* %21
%183 = icmp ne i32 %182, 0
br i1 %183, label %184, label %191
184: ; preds = %181
%185 = load i8*, i8** %8
%186 = load i8*, i8** %18
%187 = load i32, i32* %19
%188 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @variable_buffer_output to i32 (i8*, i8*, i32, ...)*)(i8* %185, i8* %186, i32 %187)
%189 = sext i32 %188 to i64
%190 = inttoptr i64 %189 to i8*
store i8* %190, i8** %8
br label %222
191: ; preds = %181
%192 = load i8*, i8** %8
%193 = load i8*, i8** %11
%194 = load i32, i32* %16
%195 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @variable_buffer_output to i32 (i8*, i8*, i32, ...)*)(i8* %192, i8* %193, i32 %194)
%196 = sext i32 %195 to i64
%197 = inttoptr i64 %196 to i8*
store i8* %197, i8** %8
%198 = load i8*, i8** %13
%199 = icmp ne i8* %198, null
br i1 %199, label %200, label %221
200: ; preds = %191
%201 = load i8*, i8** %8
%202 = load i8*, i8** %18
%203 = load i32, i32* %14
%204 = sext i32 %203 to i64
%205 = getelementptr inbounds i8, i8* %202, i64 %204
%206 = load i32, i32* %19
%207 = load i32, i32* %14
%208 = load i32, i32* %15
%209 = add nsw i32 %207, %208
%210 = sub i32 %206, %209
%211 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @variable_buffer_output to i32 (i8*, i8*, i32, ...)*)(i8* %201, i8* %205, i32 %210)
%212 = sext i32 %211 to i64
%213 = inttoptr i64 %212 to i8*
store i8* %213, i8** %8
%214 = load i8*, i8** %8
%215 = load i8*, i8** %13
%216 = getelementptr inbounds i8, i8* %215, i64 1
%217 = load i32, i32* %17
%218 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @variable_buffer_output to i32 (i8*, i8*, i32, ...)*)(i8* %214, i8* %216, i32 %217)
%219 = sext i32 %218 to i64
%220 = inttoptr i64 %219 to i8*
store i8* %220, i8** %8
br label %221
221: ; preds = %200, %191
br label %222
222: ; preds = %221, %184
%223 = load i32, i32* %21
%224 = icmp ne i32 %223, 0
br i1 %224, label %236, label %225
225: ; preds = %222
%226 = load i32, i32* %16
%227 = icmp sgt i32 %226, 0
br i1 %227, label %236, label %228
228: ; preds = %225
%229 = load i8*, i8** %13
%230 = icmp ne i8* %229, null
br i1 %230, label %231, label %241
231: ; preds = %228
%232 = load i32, i32* %19
%233 = load i32, i32* %17
%234 = add i32 %232, %233
%235 = icmp ugt i32 %234, 0
br i1 %235, label %236, label %241
236: ; preds = %231, %225, %222
%237 = load i8*, i8** %8
%238 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @variable_buffer_output to i32 (i8*, i8*, i32, ...)*)(i8* %237, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%239 = sext i32 %238 to i64
%240 = inttoptr i64 %239 to i8*
store i8* %240, i8** %8
store i32 1, i32* %20
br label %241
241: ; preds = %236, %231, %228
br label %81
242: ; preds = %81
%243 = load i32, i32* %20
%244 = icmp ne i32 %243, 0
br i1 %244, label %245, label %248
245: ; preds = %242
%246 = load i8*, i8** %8
%247 = getelementptr inbounds i8, i8* %246, i32 -1
store i8* %247, i8** %8
br label %248
248: ; preds = %245, %242
%249 = load i8*, i8** %8
store i8* %249, i8** %7
br label %250
250: ; preds = %248, %58
%251 = load i8*, i8** %7
ret i8* %251
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @patsubst_expand(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i32
store i8* %1, i8** %7
%9 = bitcast i32* %8 to i8*
%10 = icmp eq i8* %5, null
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = tail call i32 (i8*, ...) bitcast (i32 (...)* @find_percent to i32 (i8*, ...)*)(i8* %3)
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i32 %12, 0
br i1 %15, label %24, label %16
16: ; preds = %6, %11
%17 = phi i8* [ %14, %11 ], [ %5, %6 ]
%18 = ptrtoint i8* %17 to i64
%19 = ptrtoint i8* %3 to i64
%20 = sub i64 %18, %19
%21 = getelementptr inbounds i8, i8* %17, i64 1
%22 = tail call i64 @strlen(i8* %21)
%23 = trunc i64 %22 to i32
br label %26
24: ; preds = %11
%25 = tail call i64 @strlen(i8* dereferenceable(1) %3)
br label %26
26: ; preds = %24, %16
%27 = phi i1 [ false, %16 ], [ true, %24 ]
%28 = phi i8* [ %17, %16 ], [ null, %24 ]
%29 = phi i64 [ %20, %16 ], [ %25, %24 ]
%30 = phi i32 [ %23, %16 ], [ undef, %24 ]
%31 = trunc i64 %29 to i32
%32 = icmp eq i8* %4, null
br i1 %32, label %33, label %44
33: ; preds = %26
%34 = tail call i32 (i8*, ...) bitcast (i32 (...)* @find_percent to i32 (i8*, ...)*)(i8* %2)
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i8*
%37 = icmp eq i32 %34, 0
br i1 %37, label %38, label %44
38: ; preds = %33
%39 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%40 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%41 = tail call i32 (i8*, i8*, i8*, i8*, i64, i64, i32, i32, ...) bitcast (i32 (...)* @subst_expand to i32 (i8*, i8*, i8*, i8*, i64, i64, i32, i32, ...)*)(i8* %0, i8* %1, i8* %2, i8* %3, i64 %39, i64 %40, i32 1, i32 0)
%42 = sext i32 %41 to i64
%43 = inttoptr i64 %42 to i8*
br label %158
44: ; preds = %26, %33
%45 = phi i8* [ %36, %33 ], [ %4, %26 ]
%46 = ptrtoint i8* %45 to i64
%47 = ptrtoint i8* %2 to i64
%48 = sub i64 %46, %47
%49 = trunc i64 %48 to i32
%50 = getelementptr inbounds i8, i8* %45, i64 1
%51 = tail call i64 @strlen(i8* %50)
%52 = trunc i64 %51 to i32
%53 = call i32 (i8**, i32*, ...) bitcast (i32 (...)* @find_next_token to i32 (i8**, i32*, ...)*)(i8** %7, i32* %8)
%54 = icmp eq i32 %53, 0
br i1 %54, label %152, label %55
55: ; preds = %44
%56 = add nsw i32 %49, %52
%57 = icmp sgt i32 %49, 0
%58 = add i64 %48, 4294967295
%59 = and i64 %58, 4294967295
%60 = getelementptr inbounds i8, i8* %45, i64 -1
%61 = getelementptr inbounds i8, i8* %2, i64 1
%62 = icmp sgt i32 %52, 0
%63 = shl i64 %51, 32
%64 = ashr exact i64 %63, 32
%65 = getelementptr inbounds i8, i8* %45, i64 %64
%66 = add i64 %51, 4294967295
%67 = and i64 %66, 4294967295
%68 = shl i64 %48, 32
%69 = ashr exact i64 %68, 32
%70 = getelementptr inbounds i8, i8* %28, i64 1
%71 = icmp slt i32 %31, 1
%72 = sub i32 0, %30
%73 = icmp sgt i32 %31, 0
br label %74
74: ; preds = %55, %147
%75 = phi i32 [ %53, %55 ], [ %150, %147 ]
%76 = phi i32 [ 0, %55 ], [ %149, %147 ]
%77 = phi i8* [ %0, %55 ], [ %148, %147 ]
%78 = sext i32 %75 to i64
%79 = inttoptr i64 %78 to i8*
%80 = load i32, i32* %8
%81 = icmp ult i32 %80, %56
%82 = zext i1 %81 to i32
%83 = xor i1 %81, true
%84 = select i1 %83, i1 %57, i1 false
br i1 %84, label %85, label %98
85: ; preds = %74
%86 = load i8, i8* %79
%87 = load i8, i8* %2
%88 = icmp eq i8 %86, %87
br i1 %88, label %89, label %120
89: ; preds = %85
%90 = getelementptr inbounds i8, i8* %79, i64 %59
%91 = load i8, i8* %90
%92 = load i8, i8* %60
%93 = icmp eq i8 %91, %92
br i1 %93, label %94, label %120
94: ; preds = %89
%95 = getelementptr inbounds i8, i8* %79, i64 1
%96 = call i32 @strncmp(i8* %95, i8* %61, i64 %59)
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %120
98: ; preds = %94, %74
%99 = phi i32 [ 0, %94 ], [ %82, %74 ]
%100 = icmp eq i32 %99, 0
%101 = select i1 %100, i1 %62, i1 false
br i1 %101, label %102, label %119
102: ; preds = %98
%103 = add i32 %80, -1
%104 = zext i32 %103 to i64
%105 = getelementptr inbounds i8, i8* %79, i64 %104
%106 = load i8, i8* %105
%107 = load i8, i8* %65
%108 = icmp eq i8 %106, %107
br i1 %108, label %109, label %120
109: ; preds = %102
%110 = sub i32 %80, %52
%111 = zext i32 %110 to i64
%112 = getelementptr inbounds i8, i8* %79, i64 %111
%113 = load i8, i8* %112
%114 = load i8, i8* %50
%115 = icmp eq i8 %113, %114
br i1 %115, label %116, label %120
116: ; preds = %109
%117 = call i32 @strncmp(i8* %112, i8* %50, i64 %67)
%118 = icmp eq i32 %117, 0
br i1 %118, label %124, label %120
119: ; preds = %98
br i1 %100, label %124, label %120
120: ; preds = %119, %85, %89, %94, %116, %109, %102
%121 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @variable_buffer_output to i32 (i8*, i8*, i32, ...)*)(i8* %77, i8* %79, i32 %80)
%122 = sext i32 %121 to i64
%123 = inttoptr i64 %122 to i8*
br label %142
124: ; preds = %116, %119
%125 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @variable_buffer_output to i32 (i8*, i8*, i32, ...)*)(i8* %77, i8* %3, i32 %31)
%126 = sext i32 %125 to i64
%127 = inttoptr i64 %126 to i8*
br i1 %27, label %128, label %129
128: ; preds = %124
br i1 %73, label %142, label %147
129: ; preds = %124
%130 = getelementptr inbounds i8, i8* %79, i64 %69
%131 = load i32, i32* %8
%132 = sub i32 %131, %56
%133 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @variable_buffer_output to i32 (i8*, i8*, i32, ...)*)(i8* %127, i8* %130, i32 %132)
%134 = sext i32 %133 to i64
%135 = inttoptr i64 %134 to i8*
%136 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @variable_buffer_output to i32 (i8*, i8*, i32, ...)*)(i8* %135, i8* %70, i32 %30)
%137 = sext i32 %136 to i64
%138 = inttoptr i64 %137 to i8*
%139 = load i32, i32* %8
%140 = icmp eq i32 %139, %72
%141 = select i1 %71, i1 %140, i1 false
br i1 %141, label %147, label %142
142: ; preds = %129, %120, %128
%143 = phi i8* [ %123, %120 ], [ %127, %128 ], [ %138, %129 ]
%144 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @variable_buffer_output to i32 (i8*, i8*, i32, ...)*)(i8* %143, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%145 = sext i32 %144 to i64
%146 = inttoptr i64 %145 to i8*
br label %147
147: ; preds = %129, %128, %142
%148 = phi i8* [ %146, %142 ], [ %127, %128 ], [ %138, %129 ]
%149 = phi i32 [ 1, %142 ], [ %76, %128 ], [ %76, %129 ]
%150 = call i32 (i8**, i32*, ...) bitcast (i32 (...)* @find_next_token to i32 (i8**, i32*, ...)*)(i8** %7, i32* %8)
%151 = icmp eq i32 %150, 0
br i1 %151, label %152, label %74
152: ; preds = %147, %44
%153 = phi i8* [ %0, %44 ], [ %148, %147 ]
%154 = phi i32 [ 0, %44 ], [ %149, %147 ]
%155 = icmp ne i32 %154, 0
%156 = sext i1 %155 to i64
%157 = getelementptr i8, i8* %153, i64 %156
br label %158
158: ; preds = %152, %38
%159 = phi i8* [ %43, %38 ], [ %157, %152 ]
ret i8* %159
}