#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*/ str_cpy(char *, char *);
char *str_find_right(char *, char *, char const *, int);
int strlen(char const *);
char *str_del_all(char *str, const char *substr) {
  int sublen = strlen(substr);
  char *pos = NULL, *s = str;
  char *last = str + strlen(str) - 1;
  while ((pos = str_find_right(s, last, substr, sublen))) {
    str_cpy(pos, pos + sublen);
    last -= sublen;
  }
  return str;
}


x86 assembly (clang, -O0):
<str_del_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1040 <str_find_right@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11d2 <str_del_all+0xa2>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
call   1050 <str_cpy@plt>
mov    -0x14(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1181 <str_del_all+0x51>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_del_all>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbp
lea    (%r12,%rbp,1),%rsi
add    $0xffffffffffffffff,%rsi
mov    %r12,%rdi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1040 <str_find_right@plt>
test   %rax,%rax
je     11b5 <str_del_all+0x85>
movslq %r15d,%r13
mov    %r13,%rbx
neg    %rbx
sub    %r13,%rbp
add    %r12,%rbp
add    $0xffffffffffffffff,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rax,%r13,1),%rsi
mov    %rax,%rdi
call   1050 <str_cpy@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1040 <str_find_right@plt>
add    %rbx,%rbp
test   %rax,%rax
jne    1190 <str_del_all+0x60>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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