#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 */
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
char *fillPlaceHolder(char *stringToSearch, char *placeHolder,
                      char *replaceWith) {
  static char output[150];
  char *p;
  if (!(p = strstr(stringToSearch, placeHolder))) {
    return stringToSearch;
  }
  strncpy(output, stringToSearch, p - stringToSearch);
  output[p - stringToSearch] = '\0';
  snprintf(output + (p - stringToSearch), output - stringToSearch, "%s%s",
           replaceWith, p + strlen(placeHolder));
  return output;
}


x86 assembly (clang, -O0):
<fillPlaceHolder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    117c <fillPlaceHolder+0x3c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121d <fillPlaceHolder+0xdd>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
lea    0x2ebc(%rip),%rdi
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rax,%rcx
lea    0x2ea5(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rax,%rcx
lea    0x2e8f(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rcx
lea    0x2e7d(%rip),%rax
sub    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%r8
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rcx
cltq
add    %rax,%r8
lea    0xdf3(%rip),%rdx
call   1050 <snprintf@plt>
lea    0x2e37(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fillPlaceHolder>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r13
call   1060 <strstr@plt>
test   %rax,%rax
je     11b2 <fillPlaceHolder+0x72>
mov    %rax,%r12
mov    %rbx,(%rsp)
mov    %rax,%rbx
sub    %r13,%rbx
lea    0x2ede(%rip),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
lea    (%rbx,%rbp,1),%r14
movb   $0x0,(%rbx,%rbp,1)
mov    %ebp,%ebx
sub    %r13d,%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%r8
add    %r12,%r8
lea    0xe5f(%rip),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
mov    (%rsp),%rcx
call   1050 <snprintf@plt>
mov    %rbp,%r13
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@fillPlaceHolder.output = internal global [150 x i8] zeroinitializer
@.str = [5 x i8] c"%s%s\00"
define i8* @fillPlaceHolder(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = load i8*, i8** %6
%11 = call i8* @strstr(i8* %9, i8* %10)
store i8* %11, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = load i8*, i8** %5
store i8* %14, i8** %4
br label %47
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i8*, i8** %8
%18 = load i8*, i8** %5
%19 = ptrtoint i8* %17 to i64
%20 = ptrtoint i8* %18 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
%23 = call i32 @strncpy(i8* getelementptr inbounds ([150 x i8], [150 x i8]* @fillPlaceHolder.output, i64 0, i64 0), i8* %16, i32 %22)
%24 = load i8*, i8** %8
%25 = load i8*, i8** %5
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = getelementptr inbounds [150 x i8], [150 x i8]* @fillPlaceHolder.output, i64 0, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %8
%31 = load i8*, i8** %5
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = getelementptr inbounds i8, i8* getelementptr inbounds ([150 x i8], [150 x i8]* @fillPlaceHolder.output, i64 0, i64 0), i64 %34
%36 = load i8*, i8** %5
%37 = ptrtoint i8* %36 to i64
%38 = sub i64 ptrtoint ([150 x i8]* @fillPlaceHolder.output to i64), %37
%39 = trunc i64 %38 to i32
%40 = load i8*, i8** %7
%41 = load i8*, i8** %8
%42 = load i8*, i8** %6
%43 = call i32 @strlen(i8* %42)
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
%46 = call i32 @snprintf(i8* %35, i32 %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %40, i8* %45)
store i8* getelementptr inbounds ([150 x i8], [150 x i8]* @fillPlaceHolder.output, i64 0, i64 0), i8** %4
br label %47
47: ; preds = %15, %13
%48 = load i8*, i8** %4
ret i8* %48
}

LLVM IR (-O2):
@fillPlaceHolder.output = internal global [150 x i8] zeroinitializer
@.str = [5 x i8] c"%s%s\00"
define i8* @fillPlaceHolder(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = tail call i32 @strncpy(i8* getelementptr inbounds ([150 x i8], [150 x i8]* @fillPlaceHolder.output, i64 0, i64 0), i8* %0, i32 %10)
%12 = getelementptr inbounds [150 x i8], [150 x i8]* @fillPlaceHolder.output, i64 0, i64 %9
store i8 0, i8* %12
%13 = trunc i64 %8 to i32
%14 = sub i32 ptrtoint ([150 x i8]* @fillPlaceHolder.output to i32), %13
%15 = tail call i32 @strlen(i8* %1)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %4, i64 %16
%18 = tail call i32 @snprintf(i8* %12, i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %17)
br label %19
19: ; preds = %3, %6
%20 = phi i8* [ getelementptr inbounds ([150 x i8], [150 x i8]* @fillPlaceHolder.output, i64 0, i64 0), %6 ], [ %0, %3 ]
ret i8* %20
}