#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 /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
void replace_not_larger(char *s, char *replace_what, char *replace_with) {
  char *p, *pend;
  p = s;
  while ((p = strstr(p, replace_what))) {
    pend = p + strlen(replace_what);
    snprintf(p, strlen(p), "%s%s", replace_with, pend);
  }
}


x86 assembly (clang, -O0):
<replace_not_larger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11b8 <replace_not_larger+0x88>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe52(%rip),%rdx
call   1040 <snprintf@plt>
jmp    114c <replace_not_larger+0x1c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_not_larger>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
call   1050 <strstr@plt>
test   %rax,%rax
je     119c <replace_not_larger+0x6c>
mov    %rax,%rbx
lea    0xead(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1030 <strlen@plt>
movslq %eax,%r13
add    %rbx,%r13
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r13,%r8
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <replace_not_larger+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
define void @replace_not_larger(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** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
store i8* %9, i8** %7
br label %10
10: ; preds = %15, %3
%11 = load i8*, i8** %7
%12 = load i8*, i8** %5
%13 = call i8* @strstr(i8* %11, i8* %12)
store i8* %13, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %27
15: ; preds = %10
%16 = load i8*, i8** %7
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
store i8* %20, i8** %8
%21 = load i8*, i8** %7
%22 = load i8*, i8** %7
%23 = call i32 @strlen(i8* %22)
%24 = load i8*, i8** %6
%25 = load i8*, i8** %8
%26 = call i32 @snprintf(i8* %21, i32 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %25)
br label %10
27: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
define void @replace_not_larger(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 %15, label %6
6: ; preds = %3, %6
%7 = phi i8* [ %13, %6 ], [ %4, %3 ]
%8 = tail call i32 @strlen(i8* %1)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = tail call i32 @strlen(i8* %7)
%12 = tail call i32 @snprintf(i8* %7, i32 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %10)
%13 = tail call i8* @strstr(i8* dereferenceable(1) %7, i8* dereferenceable(1) %1)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %6
15: ; preds = %6, %3
ret void
}