#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_percent(char *);
char *patsubst_expand_pat(char *, char const *, char *, char *, char const *,
                          char const *);
char *patsubst_expand(char *o, const char *text, char *pattern, char *replace) {
  const char *pattern_percent = find_percent(pattern);
  const char *replace_percent = find_percent(replace);
  if (replace_percent)
    ++replace_percent;
  if (pattern_percent)
    ++pattern_percent;
  return patsubst_expand_pat(o, text, pattern, replace, pattern_percent,
                             replace_percent);
}


x86 assembly (clang, -O0):
<patsubst_expand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <find_percent@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <find_percent@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1169 <patsubst_expand+0x49>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1180 <patsubst_expand+0x60>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
call   1030 <patsubst_expand_pat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<patsubst_expand>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rdx,%rdi
call   1040 <find_percent@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <find_percent@plt>
lea    0x1(%rax),%r9
test   %rax,%rax
cmove  %rax,%r9
lea    0x1(%rbx),%r8
test   %rbx,%rbx
cmove  %rbx,%r8
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <patsubst_expand_pat@plt>

LLVM IR (-O0):
define i8* @patsubst_expand(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i8*, i8** %7
%12 = call i8* @find_percent(i8* %11)
store i8* %12, i8** %9
%13 = load i8*, i8** %8
%14 = call i8* @find_percent(i8* %13)
store i8* %14, i8** %10
%15 = load i8*, i8** %10
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = load i8*, i8** %10
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %10
br label %20
20: ; preds = %17, %4
%21 = load i8*, i8** %9
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i8*, i8** %9
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %9
br label %26
26: ; preds = %23, %20
%27 = load i8*, i8** %5
%28 = load i8*, i8** %6
%29 = load i8*, i8** %7
%30 = load i8*, i8** %8
%31 = load i8*, i8** %9
%32 = load i8*, i8** %10
%33 = call i8* @patsubst_expand_pat(i8* %27, i8* %28, i8* %29, i8* %30, i8* %31, i8* %32)
ret i8* %33
}

LLVM IR (-O2):
define i8* @patsubst_expand(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call i8* @find_percent(i8* %2)
%6 = tail call i8* @find_percent(i8* %3)
%7 = icmp eq i8* %6, null
%8 = getelementptr inbounds i8, i8* %6, i64 1
%9 = select i1 %7, i8* null, i8* %8
%10 = icmp eq i8* %5, null
%11 = getelementptr inbounds i8, i8* %5, i64 1
%12 = select i1 %10, i8* null, i8* %11
%13 = tail call i8* @patsubst_expand_pat(i8* %0, i8* %1, i8* %2, i8* %3, i8* %12, i8* %9)
ret i8* %13
}