#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 *malloc(int);
scalar_t__ strcasestr(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strscpy(char *, char *, int);
void strcasesandr(char textbuff[], int texbufftsize, char find[],
                  char replace[]) {
  char *cptr;
  int rlen = strlen(replace);
  int flen = strlen(find);
  char *buff = malloc((texbufftsize * 2));
  char *bptr;
  char *cprtold = textbuff;
  buff[0] = '\0';
  cptr = textbuff;
  bptr = buff;
  strcpy(buff, textbuff);
  while ((cptr = (char *)strcasestr(cptr, find))) {
    bptr = (bptr + (cptr - cprtold));
    cptr = (cptr + flen);
    strcpy(bptr, replace);
    bptr = (bptr + rlen);
    strcat(bptr, cptr);
    cprtold = cptr;
  }
  strscpy(textbuff, buff, texbufftsize);
  free(buff);
}


x86 assembly (clang, -O0):
<strcasesandr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
shl    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcasestr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1250 <strcasesandr+0xe0>
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x48(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    11da <strcasesandr+0x6a>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1090 <strscpy@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasesandr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rcx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %rbp,0x10(%rsp)
lea    0x0(%rbp,%rbp,1),%edi
call   1060 <malloc@plt>
movb   $0x0,(%rax)
mov    %rax,(%rsp)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcasestr@plt>
test   %rax,%rax
je     122b <strcasesandr+0xbb>
movslq %r15d,%r15
movslq %r13d,%r13
mov    0x8(%rsp),%rbp
mov    (%rsp),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rbx
sub    %rbp,%rbx
add    %rcx,%rbx
mov    %rax,%rbp
add    %r15,%rbp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
add    %r13,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <strcasestr@plt>
mov    %rbx,%rcx
test   %rax,%rax
jne    11f0 <strcasesandr+0x80>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rbx
mov    %rbx,%rsi
mov    0x10(%rsp),%rdx
call   1090 <strscpy@plt>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @strcasesandr(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%15 = load i8*, i8** %8
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %10
%17 = load i8*, i8** %7
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %11
%19 = load i32, i32* %6
%20 = mul nsw i32 %19, 2
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %12
%22 = load i8*, i8** %5
store i8* %22, i8** %14
%23 = load i8*, i8** %12
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 0, i8* %24
%25 = load i8*, i8** %5
store i8* %25, i8** %9
%26 = load i8*, i8** %12
store i8* %26, i8** %13
%27 = load i8*, i8** %12
%28 = load i8*, i8** %5
%29 = call i32 @strcpy(i8* %27, i8* %28)
br label %30
30: ; preds = %36, %4
%31 = load i8*, i8** %9
%32 = load i8*, i8** %7
%33 = call i64 @strcasestr(i8* %31, i8* %32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %9
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %59
36: ; preds = %30
%37 = load i8*, i8** %13
%38 = load i8*, i8** %9
%39 = load i8*, i8** %14
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = getelementptr inbounds i8, i8* %37, i64 %42
store i8* %43, i8** %13
%44 = load i8*, i8** %9
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8* %47, i8** %9
%48 = load i8*, i8** %13
%49 = load i8*, i8** %8
%50 = call i32 @strcpy(i8* %48, i8* %49)
%51 = load i8*, i8** %13
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8* %54, i8** %13
%55 = load i8*, i8** %13
%56 = load i8*, i8** %9
%57 = call i32 @strcat(i8* %55, i8* %56)
%58 = load i8*, i8** %9
store i8* %58, i8** %14
br label %30
59: ; preds = %30
%60 = load i8*, i8** %5
%61 = load i8*, i8** %12
%62 = load i32, i32* %6
%63 = call i32 @strscpy(i8* %60, i8* %61, i32 %62)
%64 = load i8*, i8** %12
%65 = call i32 @free(i8* %64)
ret void
}

LLVM IR (-O2):
define void @strcasesandr(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = tail call i32 @strlen(i8* %3)
%6 = tail call i32 @strlen(i8* %2)
%7 = shl nsw i32 %1, 1
%8 = tail call i8* @malloc(i32 %7)
store i8 0, i8* %8
%9 = tail call i32 @strcpy(i8* %8, i8* %0)
%10 = tail call i64 @strcasestr(i8* %0, i8* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %29, label %12
12: ; preds = %4
%13 = sext i32 %6 to i64
%14 = sext i32 %5 to i64
br label %15
15: ; preds = %12, %15
%16 = phi i64 [ %10, %12 ], [ %27, %15 ]
%17 = phi i8* [ %0, %12 ], [ %23, %15 ]
%18 = phi i8* [ %8, %12 ], [ %25, %15 ]
%19 = inttoptr i64 %16 to i8*
%20 = ptrtoint i8* %17 to i64
%21 = sub i64 %16, %20
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = getelementptr inbounds i8, i8* %19, i64 %13
%24 = tail call i32 @strcpy(i8* %22, i8* %3)
%25 = getelementptr inbounds i8, i8* %22, i64 %14
%26 = tail call i32 @strcat(i8* %25, i8* %23)
%27 = tail call i64 @strcasestr(i8* %23, i8* %2)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %15
29: ; preds = %15, %4
%30 = tail call i32 @strscpy(i8* %0, i8* %8, i32 %1)
%31 = tail call i32 @free(i8* %8)
ret void
}