#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 */
char *find_next_token(char const **, unsigned int *);
unsigned int strlen(char const *);
scalar_t__ strncmp(char const *, char const *, unsigned int);
char *subst_expand(char *, char const *, char const *, char const *,
                   unsigned int, unsigned int, int);
char *variable_buffer_output(char *, char const *, int);
char *patsubst_expand_pat(char *o, const char *text, const char *pattern,
                          const char *replace, const char *pattern_percent,
                          const char *replace_percent) {
  unsigned int pattern_prepercent_len, pattern_postpercent_len;
  unsigned int replace_prepercent_len, replace_postpercent_len;
  const char *t;
  unsigned int len;
  int doneany = 0;
  if (replace_percent) {
    replace_prepercent_len = replace_percent - replace - 1;
    replace_postpercent_len = strlen(replace_percent);
  } else {
    replace_prepercent_len = strlen(replace);
    replace_postpercent_len = 0;
  }
  if (!pattern_percent)
    return subst_expand(o, text, pattern, replace, strlen(pattern),
                        strlen(replace), 1);
  pattern_prepercent_len = pattern_percent - pattern - 1;
  pattern_postpercent_len = strlen(pattern_percent);
  while ((t = find_next_token(&text, &len)) != 0) {
    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[-2] ||
         !(strncmp((t + 1), (pattern + 1), (pattern_prepercent_len - 1)) == 0)))
      fail = 1;
    if (!fail && pattern_postpercent_len > 0 &&
        (t[len - 1] != pattern_percent[pattern_postpercent_len - 1] ||
         t[len - pattern_postpercent_len] != *pattern_percent ||
         !(strncmp((&t[len - pattern_postpercent_len]), (pattern_percent),
                   (pattern_postpercent_len - 1)) == 0)))
      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, 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_pat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%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)
je     11a8 <patsubst_expand_pat+0x58>
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x48(%rbp)
jmp    11bb <patsubst_expand_pat+0x6b>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1227 <patsubst_expand_pat+0xd7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x60(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%rcx
mov    -0x60(%rbp),%r8d
mov    %eax,%r9d
movl   $0x1,(%rsp)
call   1050 <subst_expand@plt>
mov    %rax,-0x8(%rbp)
jmp    146d <patsubst_expand_pat+0x31d>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x54(%rbp),%rsi
call   1070 <find_next_token@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
je     144f <patsubst_expand_pat+0x2ff>
movl   $0x0,-0x5c(%rbp)
mov    -0x54(%rbp),%eax
mov    -0x3c(%rbp),%ecx
add    -0x40(%rbp),%ecx
cmp    %ecx,%eax
jae    127f <patsubst_expand_pat+0x12f>
movl   $0x1,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    12f5 <patsubst_expand_pat+0x1a5>
cmpl   $0x0,-0x3c(%rbp)
jbe    12f5 <patsubst_expand_pat+0x1a5>
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    12ee <patsubst_expand_pat+0x19e>
mov    -0x50(%rbp),%rax
mov    -0x3c(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x30(%rbp),%rcx
movsbl -0x2(%rcx),%ecx
cmp    %ecx,%eax
jne    12ee <patsubst_expand_pat+0x19e>
mov    -0x50(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x3c(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12f5 <patsubst_expand_pat+0x1a5>
movl   $0x1,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    137f <patsubst_expand_pat+0x22f>
cmpl   $0x0,-0x40(%rbp)
jbe    137f <patsubst_expand_pat+0x22f>
mov    -0x50(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x30(%rbp),%rcx
mov    -0x40(%rbp),%edx
sub    $0x1,%edx
mov    %edx,%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1378 <patsubst_expand_pat+0x228>
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 (%rcx),%ecx
cmp    %ecx,%eax
jne    1378 <patsubst_expand_pat+0x228>
mov    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%eax
sub    -0x40(%rbp),%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     137f <patsubst_expand_pat+0x22f>
movl   $0x1,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     13a2 <patsubst_expand_pat+0x252>
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1060 <variable_buffer_output@plt>
mov    %rax,-0x10(%rbp)
jmp    13fc <patsubst_expand_pat+0x2ac>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1060 <variable_buffer_output@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     13f7 <patsubst_expand_pat+0x2a7>
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x3c(%rbp),%eax
add    %rax,%rsi
mov    -0x54(%rbp),%edx
mov    -0x3c(%rbp),%eax
add    -0x40(%rbp),%eax
sub    %eax,%edx
call   1060 <variable_buffer_output@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x48(%rbp),%edx
call   1060 <variable_buffer_output@plt>
mov    %rax,-0x10(%rbp)
jmp    13fc <patsubst_expand_pat+0x2ac>
cmpl   $0x0,-0x5c(%rbp)
jne    142a <patsubst_expand_pat+0x2da>
cmpl   $0x0,-0x44(%rbp)
ja     142a <patsubst_expand_pat+0x2da>
cmpq   $0x0,-0x38(%rbp)
je     144a <patsubst_expand_pat+0x2fa>
mov    -0x54(%rbp),%eax
add    -0x48(%rbp),%eax
cmp    $0x0,%eax
jbe    144a <patsubst_expand_pat+0x2fa>
mov    -0x10(%rbp),%rdi
lea    0xbcb(%rip),%rsi
mov    $0x1,%edx
call   1060 <variable_buffer_output@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    1245 <patsubst_expand_pat+0xf5>
cmpl   $0x0,-0x58(%rbp)
je     1465 <patsubst_expand_pat+0x315>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<patsubst_expand_pat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r9,%r15
mov    %r8,%r13
mov    %rcx,%r14
mov    %rdx,0x30(%rsp)
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rsi,0x50(%rsp)
test   %r9,%r9
je     13cb <patsubst_expand_pat+0x27b>
mov    %r14d,%ebp
not    %ebp
add    %r15d,%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,0x18(%rsp)
test   %r13,%r13
je     13e6 <patsubst_expand_pat+0x296>
mov    %ebp,0x3c(%rsp)
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x50(%rsp),%rdi
lea    0x14(%rsp),%rsi
call   1070 <find_next_token@plt>
test   %rax,%rax
je     141e <patsubst_expand_pat+0x2ce>
mov    %rax,%r12
mov    %r15,0x68(%rsp)
mov    %r14,0x70(%rsp)
mov    0x30(%rsp),%rax
mov    %rax,%r15
not    %r15
add    %r13,%r15
mov    %rbp,%r14
add    %r15d,%ebp
lea    -0x1(%r15),%ecx
mov    %rcx,0x48(%rsp)
add    $0x1,%rax
mov    %rax,0x60(%rsp)
lea    -0x1(%r14),%eax
mov    %rax,0x40(%rsp)
mov    %r15d,%eax
mov    %rax,0x58(%rsp)
mov    0x18(%rsp),%eax
neg    %eax
mov    %eax,0x38(%rsp)
movl   $0x0,0x1c(%rsp)
mov    %r13,0x28(%rsp)
mov    %r14,0x20(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x14(%rsp),%ecx
xor    %eax,%eax
cmp    %ebp,%ecx
setb   %al
test   %r15d,%r15d
je     1290 <patsubst_expand_pat+0x140>
cmp    %ebp,%ecx
jb     1290 <patsubst_expand_pat+0x140>
movzbl (%r12),%eax
mov    0x30(%rsp),%rcx
cmp    (%rcx),%al
jne    1360 <patsubst_expand_pat+0x210>
mov    0x48(%rsp),%rax
movzbl (%r12,%rax,1),%eax
cmp    -0x2(%r13),%al
jne    1360 <patsubst_expand_pat+0x210>
lea    0x1(%r12),%rdi
mov    0x60(%rsp),%rsi
mov    0x48(%rsp),%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1360 <patsubst_expand_pat+0x210>
xor    %eax,%eax
nopl   0x0(%rax)
test   %eax,%eax
jne    1350 <patsubst_expand_pat+0x200>
test   %r14d,%r14d
je     1350 <patsubst_expand_pat+0x200>
mov    0x14(%rsp),%edi
lea    -0x1(%rdi),%eax
movzbl (%r12,%rax,1),%eax
mov    0x40(%rsp),%rcx
cmp    0x0(%r13,%rcx,1),%al
jne    1360 <patsubst_expand_pat+0x210>
sub    %r14d,%edi
movzbl (%r12,%rdi,1),%eax
cmp    0x0(%r13),%al
jne    1360 <patsubst_expand_pat+0x210>
add    %r12,%rdi
mov    %r13,%rsi
mov    0x40(%rsp),%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1360 <patsubst_expand_pat+0x210>
mov    %rbx,%rdi
mov    0x70(%rsp),%rsi
mov    0x3c(%rsp),%r14d
mov    %r14d,%edx
call   1060 <variable_buffer_output@plt>
mov    %rax,%rbx
mov    0x68(%rsp),%r13
test   %r13,%r13
je     13ae <patsubst_expand_pat+0x25e>
add    0x58(%rsp),%r12
mov    0x14(%rsp),%edx
sub    %ebp,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <variable_buffer_output@plt>
mov    %rax,%rdi
mov    %r13,%rsi
mov    0x18(%rsp),%edx
call   1060 <variable_buffer_output@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jne    13bf <patsubst_expand_pat+0x26f>
mov    0x38(%rsp),%eax
cmp    %eax,0x14(%rsp)
jmp    13b1 <patsubst_expand_pat+0x261>
cs nopw 0x0(%rax,%rax,1)
nop
test   %eax,%eax
je     12e4 <patsubst_expand_pat+0x194>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x14(%rsp),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <variable_buffer_output@plt>
mov    %rax,%rbx
movl   $0x1,0x1c(%rsp)
mov    %rbx,%rdi
lea    0xc7c(%rip),%rsi
mov    $0x1,%edx
call   1060 <variable_buffer_output@plt>
mov    %rax,%rbx
lea    0x50(%rsp),%rdi
lea    0x14(%rsp),%rsi
call   1070 <find_next_token@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1230 <patsubst_expand_pat+0xe0>
jmp    1426 <patsubst_expand_pat+0x2d6>
test   %r14d,%r14d
mov    0x28(%rsp),%r13
mov    0x20(%rsp),%r14
je     1391 <patsubst_expand_pat+0x241>
jmp    1372 <patsubst_expand_pat+0x222>
mov    0x28(%rsp),%r13
mov    0x20(%rsp),%r14
jmp    1372 <patsubst_expand_pat+0x222>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
movl   $0x0,0x18(%rsp)
test   %r13,%r13
jne    119d <patsubst_expand_pat+0x4d>
mov    0x30(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
movl   $0x1,(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %r15d,%r8d
mov    %eax,%r9d
call   1050 <subst_expand@plt>
jmp    1432 <patsubst_expand_pat+0x2e2>
movl   $0x0,0x1c(%rsp)
cmpl   $0x1,0x1c(%rsp)
adc    $0xffffffffffffffff,%rbx
mov    %rbx,%rax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @patsubst_expand_pat(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 %18, label %11
11: ; preds = %6
%12 = ptrtoint i8* %5 to i64
%13 = ptrtoint i8* %3 to i64
%14 = xor i64 %13, -1
%15 = add i64 %12, %14
%16 = trunc i64 %15 to i32
%17 = tail call i32 @strlen(i8* %5)
br label %20
18: ; preds = %6
%19 = tail call i32 @strlen(i8* %3)
br label %20
20: ; preds = %18, %11
%21 = phi i32 [ %16, %11 ], [ %19, %18 ]
%22 = phi i32 [ %17, %11 ], [ 0, %18 ]
%23 = icmp eq i8* %4, null
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = tail call i32 @strlen(i8* %2)
%26 = tail call i32 @strlen(i8* %3)
%27 = tail call i8* @subst_expand(i8* %0, i8* %1, i8* %2, i8* %3, i32 %25, i32 %26, i32 1)
br label %124
28: ; preds = %20
%29 = ptrtoint i8* %4 to i64
%30 = ptrtoint i8* %2 to i64
%31 = xor i64 %30, -1
%32 = add i64 %29, %31
%33 = trunc i64 %32 to i32
%34 = tail call i32 @strlen(i8* %4)
%35 = call i8* @find_next_token(i8** %7, i32* %8)
%36 = icmp eq i8* %35, null
br i1 %36, label %118, label %37
37: ; preds = %28
%38 = add i32 %34, %33
%39 = icmp eq i32 %33, 0
%40 = add i32 %33, -1
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %4, i64 -2
%43 = getelementptr inbounds i8, i8* %2, i64 1
%44 = icmp ne i32 %34, 0
%45 = add i32 %34, -1
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %4, i64 %46
%48 = and i64 %32, 4294967295
%49 = icmp eq i32 %21, 0
%50 = sub i32 0, %22
br label %51
51: ; preds = %37, %113
%52 = phi i8* [ %35, %37 ], [ %116, %113 ]
%53 = phi i32 [ 0, %37 ], [ %115, %113 ]
%54 = phi i8* [ %0, %37 ], [ %114, %113 ]
%55 = load i32, i32* %8
%56 = icmp ult i32 %55, %38
%57 = zext i1 %56 to i32
%58 = or i1 %39, %56
br i1 %58, label %72, label %59
59: ; preds = %51
%60 = load i8, i8* %52
%61 = load i8, i8* %2
%62 = icmp eq i8 %60, %61
br i1 %62, label %63, label %95
63: ; preds = %59
%64 = getelementptr inbounds i8, i8* %52, i64 %41
%65 = load i8, i8* %64
%66 = load i8, i8* %42
%67 = icmp eq i8 %65, %66
br i1 %67, label %68, label %95
68: ; preds = %63
%69 = getelementptr inbounds i8, i8* %52, i64 1
%70 = call i64 @strncmp(i8* %69, i8* %43, i32 %40)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %95
72: ; preds = %68, %51
%73 = phi i32 [ 0, %68 ], [ %57, %51 ]
%74 = icmp eq i32 %73, 0
%75 = select i1 %74, i1 %44, i1 false
br i1 %75, label %76, label %94
76: ; preds = %72
%77 = load i32, i32* %8
%78 = add i32 %77, -1
%79 = zext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %52, i64 %79
%81 = load i8, i8* %80
%82 = load i8, i8* %47
%83 = icmp eq i8 %81, %82
br i1 %83, label %84, label %95
84: ; preds = %76
%85 = sub i32 %77, %34
%86 = zext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %52, i64 %86
%88 = load i8, i8* %87
%89 = load i8, i8* %4
%90 = icmp eq i8 %88, %89
br i1 %90, label %91, label %95
91: ; preds = %84
%92 = call i64 @strncmp(i8* %87, i8* %4, i32 %45)
%93 = icmp eq i64 %92, 0
br i1 %93, label %98, label %95
94: ; preds = %72
br i1 %74, label %98, label %95
95: ; preds = %94, %59, %63, %68, %91, %84, %76
%96 = load i32, i32* %8
%97 = call i8* @variable_buffer_output(i8* %54, i8* %52, i32 %96)
br label %110
98: ; preds = %91, %94
%99 = call i8* @variable_buffer_output(i8* %54, i8* %3, i32 %21)
br i1 %10, label %100, label %101
100: ; preds = %98
br i1 %49, label %113, label %110
101: ; preds = %98
%102 = getelementptr inbounds i8, i8* %52, i64 %48
%103 = load i32, i32* %8
%104 = sub i32 %103, %38
%105 = call i8* @variable_buffer_output(i8* %99, i8* %102, i32 %104)
%106 = call i8* @variable_buffer_output(i8* %105, i8* %5, i32 %22)
%107 = load i32, i32* %8
%108 = icmp eq i32 %107, %50
%109 = select i1 %49, i1 %108, i1 false
br i1 %109, label %113, label %110
110: ; preds = %101, %95, %100
%111 = phi i8* [ %97, %95 ], [ %99, %100 ], [ %106, %101 ]
%112 = call i8* @variable_buffer_output(i8* %111, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %113
113: ; preds = %101, %100, %110
%114 = phi i8* [ %112, %110 ], [ %99, %100 ], [ %106, %101 ]
%115 = phi i32 [ 1, %110 ], [ %53, %100 ], [ %53, %101 ]
%116 = call i8* @find_next_token(i8** %7, i32* %8)
%117 = icmp eq i8* %116, null
br i1 %117, label %118, label %51
118: ; preds = %113, %28
%119 = phi i8* [ %0, %28 ], [ %114, %113 ]
%120 = phi i32 [ 0, %28 ], [ %115, %113 ]
%121 = icmp ne i32 %120, 0
%122 = sext i1 %121 to i64
%123 = getelementptr i8, i8* %119, i64 %122
br label %124
124: ; preds = %118, %24
%125 = phi i8* [ %123, %118 ], [ %27, %24 ]
ret i8* %125
}