#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*/ coco_error(char *, char *, char *, char *);
char *coco_strdup(char *);
int /*<<< orphan*/ memmove(char *, char *, int);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
char *coco_remove_from_string(char *string, char *from, char *to) {
  char *result, *start, *stop;
  result = coco_strdup(string);
  if (strcmp(from, "") == 0) {
    start = result;
  } else
    start = strstr(result, from);
  if (strcmp(to, "") == 0) {
    stop = result + strlen(result);
  } else
    stop = strstr(result, to);
  if ((start == NULL) || (stop == NULL) || (stop < start)) {
    coco_error("coco_remove_from_string(): failed to remove characters between "
               "%s and %s from string %s",
               from, to, string);
    return NULL;
  }
  memmove(start, stop, strlen(stop) + 1);
  return result;
}


x86 assembly (clang, -O0):
<coco_remove_from_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <coco_strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xecb(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11a8 <coco_remove_from_string+0x48>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11b9 <coco_remove_from_string+0x59>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11f9 <coco_remove_from_string+0x99>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    120a <coco_remove_from_string+0xaa>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     122e <coco_remove_from_string+0xce>
cmpq   $0x0,-0x38(%rbp)
je     122e <coco_remove_from_string+0xce>
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1253 <coco_remove_from_string+0xf3>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdbf(%rip),%rdi
call   1050 <coco_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1286 <coco_remove_from_string+0x126>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1060 <memmove@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<coco_remove_from_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
call   1070 <coco_strdup@plt>
mov    %rax,%rbx
lea    0xed4(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
mov    %rbx,%r13
test   %rax,%rax
je     11a1 <coco_remove_from_string+0x41>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strstr@plt>
mov    %rax,%r13
lea    0xeaf(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     11ca <coco_remove_from_string+0x6a>
mov    %r14,%rsi
call   1080 <strstr@plt>
mov    %rax,%rbp
test   %r13,%r13
jne    11dc <coco_remove_from_string+0x7c>
jmp    11fe <coco_remove_from_string+0x9e>
call   1030 <strlen@plt>
cltq
mov    %rbx,%rbp
add    %rax,%rbp
test   %r13,%r13
je     11fe <coco_remove_from_string+0x9e>
test   %rbp,%rbp
je     11fe <coco_remove_from_string+0x9e>
cmp    %r13,%rbp
jb     11fe <coco_remove_from_string+0x9e>
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <memmove@plt>
jmp    1215 <coco_remove_from_string+0xb5>
lea    0xdfb(%rip),%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <coco_error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [88 x i8] c"coco_remove_from_string(): failed to remove characters between %s and %s from string %s\00"
define i8* @coco_remove_from_string(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %5
%12 = call i8* @coco_strdup(i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %6
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i8*, i8** %8
store i8* %17, i8** %9
br label %22
18: ; preds = %3
%19 = load i8*, i8** %8
%20 = load i8*, i8** %6
%21 = call i8* @strstr(i8* %19, i8* %20)
store i8* %21, i8** %9
br label %22
22: ; preds = %18, %16
%23 = load i8*, i8** %7
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i8*, i8** %8
%28 = load i8*, i8** %8
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8* %31, i8** %10
br label %36
32: ; preds = %22
%33 = load i8*, i8** %8
%34 = load i8*, i8** %7
%35 = call i8* @strstr(i8* %33, i8* %34)
store i8* %35, i8** %10
br label %36
36: ; preds = %32, %26
%37 = load i8*, i8** %9
%38 = icmp eq i8* %37, null
br i1 %38, label %46, label %39
39: ; preds = %36
%40 = load i8*, i8** %10
%41 = icmp eq i8* %40, null
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = load i8*, i8** %10
%44 = load i8*, i8** %9
%45 = icmp ult i8* %43, %44
br i1 %45, label %46, label %51
46: ; preds = %42, %39, %36
%47 = load i8*, i8** %6
%48 = load i8*, i8** %7
%49 = load i8*, i8** %5
%50 = call i32 @coco_error(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.1, i64 0, i64 0), i8* %47, i8* %48, i8* %49)
store i8* null, i8** %4
br label %59
51: ; preds = %42
%52 = load i8*, i8** %9
%53 = load i8*, i8** %10
%54 = load i8*, i8** %10
%55 = call i32 @strlen(i8* %54)
%56 = add nsw i32 %55, 1
%57 = call i32 @memmove(i8* %52, i8* %53, i32 %56)
%58 = load i8*, i8** %8
store i8* %58, i8** %4
br label %59
59: ; preds = %51, %46
%60 = load i8*, i8** %4
ret i8* %60
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [88 x i8] c"coco_remove_from_string(): failed to remove characters between %s and %s from string %s\00"
define i8* @coco_remove_from_string(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @coco_strdup(i8* %0)
%5 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i8* @strstr(i8* dereferenceable(1) %4, i8* dereferenceable(1) %1)
br label %9
9: ; preds = %3, %7
%10 = phi i8* [ %8, %7 ], [ %4, %3 ]
%11 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = tail call i32 @strlen(i8* %4)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %4, i64 %15
br label %19
17: ; preds = %9
%18 = tail call i8* @strstr(i8* dereferenceable(1) %4, i8* dereferenceable(1) %2)
br label %19
19: ; preds = %17, %13
%20 = phi i8* [ %16, %13 ], [ %18, %17 ]
%21 = icmp eq i8* %10, null
%22 = icmp eq i8* %20, null
%23 = select i1 %21, i1 true, i1 %22
%24 = icmp ult i8* %20, %10
%25 = select i1 %23, i1 true, i1 %24
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = tail call i32 @coco_error(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2, i8* %0)
br label %32
28: ; preds = %19
%29 = tail call i32 @strlen(i8* %20)
%30 = add nsw i32 %29, 1
%31 = tail call i32 @memmove(i8* %10, i8* %20, i32 %30)
br label %32
32: ; preds = %28, %26
%33 = phi i8* [ null, %26 ], [ %4, %28 ]
ret i8* %33
}