#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*/ strcat(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
void removeSubstr(char *string, char *sub) {
  char *match = string;
  int len = strlen(sub);
  while ((match = strstr(match, sub))) {
    *match = '\0';
    strcat(string, match + len);
    match++;
  }
}


x86 assembly (clang, -O0):
<removeSubstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     119b <removeSubstr+0x6b>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   1040 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1154 <removeSubstr+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeSubstr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1186 <removeSubstr+0x56>
mov    %rax,%rbx
movslq %ebp,%rbp
nopl   (%rax)
movb   $0x0,(%rbx)
lea    (%rbx,%rbp,1),%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <removeSubstr+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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