#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 *, int);
int strlen(char const *);
char *strstr(char *, char const *);
void strdelstr(char *s1, const char *s2) {
  int t_len = strlen(s2);
  if (!strstr(s1, s2)) {
    return;
  }
  while ((s1 = strstr(s1, s2))) {
    memmove(s1, s1 + t_len, 1 + strlen(s1 + t_len));
  }
}


x86 assembly (clang, -O0):
<strdelstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
jne    1168 <strdelstr+0x38>
jmp    11c6 <strdelstr+0x96>
jmp    116d <strdelstr+0x3d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11c6 <strdelstr+0x96>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <memmove@plt>
jmp    116d <strdelstr+0x3d>
add    $0x30,%rsp
pop    %rbp
ret

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

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

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