#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(int *);
int /*<<< orphan*/ memset(char *, char, int);
int *searchSubstring(char *, char *, int *, int);
int strlen(char *);
void deleteSubstring(char *input, char *substring) {
  if (input == NULL || substring == NULL) {
    return;
  }
  int substringLength = strlen(substring);
  int n = 0;
  int *positions = searchSubstring(input, substring, &n, !1);
  for (int i = 0; i < n; i++) {
    memset(input + positions[i], '_', substringLength);
  }
  free(positions);
}


x86 assembly (clang, -O0):
<deleteSubstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1166 <deleteSubstring+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    116b <deleteSubstring+0x2b>
jmp    11df <deleteSubstring+0x9f>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1050 <searchSubstring@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11d6 <deleteSubstring+0x96>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movslq (%rax,%rcx,4),%rax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
mov    $0x5f,%esi
call   1060 <memset@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119c <deleteSubstring+0x5c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deleteSubstring>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11ba <deleteSubstring+0x7a>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11ba <deleteSubstring+0x7a>
mov    %rdi,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1050 <searchSubstring@plt>
mov    %rax,%rbx
cmpl   $0x0,0x4(%rsp)
jle    11b2 <deleteSubstring+0x72>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movslq (%rbx,%rbp,4),%rdi
add    %r14,%rdi
mov    $0x5f,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
cmp    %rax,%rbp
jl     1190 <deleteSubstring+0x50>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @deleteSubstring(i8* %0, i8* %1) {
%3 = alloca i32
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
br i1 %6, label %26, label %7
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %1)
%9 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%10 = call i32* @searchSubstring(i8* %0, i8* %1, i32* %3, i32 0)
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %15, %7
%14 = call i32 @free(i32* %10)
br label %26
15: ; preds = %7, %15
%16 = phi i64 [ %22, %15 ], [ 0, %7 ]
%17 = getelementptr inbounds i32, i32* %10, i64 %16
%18 = load i32, i32* %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = call i32 @memset(i8* %20, i8 signext 95, i32 %8)
%22 = add nuw nsw i64 %16, 1
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %15, label %13
26: ; preds = %2, %13
ret void
}