#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 */
char *my_strcpy(char *, char *);
int strlen(char const *);
char *strstr(char *, char const *);
void str_delete(char *s, const char *target) {
  char *p;
  int n;
  if (s == NULL || target == NULL || *target == '\0')
    return;
  n = strlen(target);
  p = s;
  while ((p = strstr(p, target)))
    p = my_strcpy(p, p + n);
}


x86 assembly (clang, -O0):
<str_delete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1166 <str_delete+0x36>
cmpq   $0x0,-0x10(%rbp)
je     1166 <str_delete+0x36>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116b <str_delete+0x3b>
jmp    11b7 <str_delete+0x87>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11b7 <str_delete+0x87>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   1030 <my_strcpy@plt>
mov    %rax,-0x18(%rbp)
jmp    117f <str_delete+0x4f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_delete>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     118c <str_delete+0x5c>
mov    %rsi,%rbx
test   %rsi,%rsi
je     118c <str_delete+0x5c>
cmpb   $0x0,(%rbx)
je     118c <str_delete+0x5c>
mov    %rdi,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     118c <str_delete+0x5c>
movslq %ebp,%rbp
cs nopw 0x0(%rax,%rax,1)
lea    (%rax,%rbp,1),%rsi
mov    %rax,%rdi
call   1030 <my_strcpy@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
jne    1170 <str_delete+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @str_delete(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
%8 = icmp eq i8* %7, null
br i1 %8, label %17, label %9
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12, %9, %2
br label %34
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %6
%21 = load i8*, i8** %3
store i8* %21, i8** %5
br label %22
22: ; preds = %27, %18
%23 = load i8*, i8** %5
%24 = load i8*, i8** %4
%25 = call i8* @strstr(i8* %23, i8* %24)
store i8* %25, i8** %5
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = load i8*, i8** %5
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = call i8* @my_strcpy(i8* %28, i8* %32)
store i8* %33, i8** %5
br label %22
34: ; preds = %17, %22
ret void
}

LLVM IR (-O2):
define void @str_delete(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %6
%10 = tail call i32 @strlen(i8* %1)
%11 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* %1)
%12 = icmp eq i8* %11, null
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = sext i32 %10 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i8* [ %11, %13 ], [ %19, %15 ]
%17 = getelementptr inbounds i8, i8* %16, i64 %14
%18 = tail call i8* @my_strcpy(i8* %16, i8* %17)
%19 = tail call i8* @strstr(i8* dereferenceable(1) %18, i8* %1)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %15
21: ; preds = %15, %9, %2, %6
ret void
}