#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*/ free(char *);
char *str2cstr(unsigned long);
char *strdup(char *);
unsigned long string_new(char *);
int strlen(char *);
char *strstr(char *, char *);
unsigned long int string_minus(unsigned long int self,
                               unsigned long int subobj) {
  char *buf, *ptr, *sub;
  int sublen;
  unsigned long int ret;
  buf = strdup(str2cstr(self));
  sub = str2cstr(subobj);
  sublen = strlen(sub);
  while ((ptr = strstr(buf, sub))) {
    while ((*ptr = ptr[sublen]))
      ptr[sublen] = '\0', ptr++;
  }
  ret = string_new(buf);
  free(buf);
  return ret;
}


x86 assembly (clang, -O0):
<string_minus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <str2cstr@plt>
mov    %rax,%rdi
call   1070 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <str2cstr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f9 <string_minus+0x99>
jmp    11be <string_minus+0x5e>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%rcx
mov    %al,(%rcx)
cmp    $0x0,%al
je     11f4 <string_minus+0x94>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11be <string_minus+0x5e>
jmp    119e <string_minus+0x3e>
mov    -0x18(%rbp),%rdi
call   1040 <string_new@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_minus>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
call   1060 <str2cstr@plt>
mov    %rax,%rdi
call   1070 <strdup@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <str2cstr@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11e5 <string_minus+0x85>
movslq %ebp,%rbp
jmp    11c0 <string_minus+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11e5 <string_minus+0x85>
mov    (%rax,%rbp,1),%cl
mov    %cl,(%rax)
test   %cl,%cl
je     11b0 <string_minus+0x50>
add    $0x1,%rax
nopl   (%rax)
movb   $0x0,-0x1(%rax,%rbp,1)
movzbl (%rax,%rbp,1),%ecx
mov    %cl,(%rax)
add    $0x1,%rax
test   %cl,%cl
jne    11d0 <string_minus+0x70>
jmp    11b0 <string_minus+0x50>
mov    %r14,%rdi
call   1040 <string_new@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @string_minus(i64 %0, i64 %1) {
%3 = tail call i8* @str2cstr(i64 %0)
%4 = tail call i8* @strdup(i8* %3)
%5 = tail call i8* @str2cstr(i64 %1)
%6 = tail call i32 @strlen(i8* %5)
%7 = tail call i8* @strstr(i8* dereferenceable(1) %4, i8* dereferenceable(1) %5)
%8 = icmp eq i8* %7, null
br i1 %8, label %26, label %9
9: ; preds = %2
%10 = sext i32 %6 to i64
br label %14
11: ; preds = %19, %14
%12 = tail call i8* @strstr(i8* dereferenceable(1) %4, i8* dereferenceable(1) %5)
%13 = icmp eq i8* %12, null
br i1 %13, label %26, label %14
14: ; preds = %9, %11
%15 = phi i8* [ %7, %9 ], [ %12, %11 ]
%16 = getelementptr inbounds i8, i8* %15, i64 %10
%17 = load i8, i8* %16
store i8 %17, i8* %15
%18 = icmp eq i8 %17, 0
br i1 %18, label %11, label %19
19: ; preds = %14, %19
%20 = phi i8* [ %23, %19 ], [ %16, %14 ]
%21 = phi i8* [ %22, %19 ], [ %15, %14 ]
store i8 0, i8* %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = getelementptr inbounds i8, i8* %22, i64 %10
%24 = load i8, i8* %23
store i8 %24, i8* %22
%25 = icmp eq i8 %24, 0
br i1 %25, label %11, label %19
26: ; preds = %11, %2
%27 = tail call i64 @string_new(i8* %4)
%28 = tail call i32 @free(i8* %4)
ret i64 %27
}