#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*/ memmove(char *, char *, size_t);
size_t strlen(char const *const);
char *strstr(char *, char const *const);
char *strstrstrip(char *haystack, const char *const needle) {
  char *loc = 0;
  size_t haystack_size = strlen(haystack);
  size_t needle_size = strlen(needle);
  while ((loc = strstr(haystack, needle)) != NULL) {
    haystack_size -= needle_size;
    memmove(loc, loc + needle_size, haystack_size);
  }
  return haystack;
}


x86 assembly (clang, -O0):
<strstrstrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11a6 <strstrstrip+0x76>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memmove@plt>
jmp    1162 <strstrstrip+0x32>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstrstrip>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1195 <strstrstrip+0x65>
mov    %rax,%r13
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
sub    %r12,%rbx
nopl   0x0(%rax,%rax,1)
lea    (%r12,%r13,1),%rsi
mov    %r13,%rdi
mov    %rbx,%rdx
call   1040 <memmove@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
mov    %rax,%r13
sub    %r12,%rbx
test   %rax,%rax
jne    1170 <strstrstrip+0x40>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strstrstrip(i8* returned %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
br label %8
8: ; preds = %6, %8
%9 = phi i8* [ %14, %8 ], [ %4, %6 ]
%10 = phi i64 [ %11, %8 ], [ %7, %6 ]
%11 = sub i64 %10, %3
%12 = getelementptr inbounds i8, i8* %9, i64 %3
%13 = tail call i32 @memmove(i8* %9, i8* %12, i64 %11)
%14 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %8
16: ; preds = %8, %2
ret i8* %0
}