#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*/ strdel(char *, int, unsigned int);
int /*<<< orphan*/ strinsert(char const *, char *, int);
unsigned int strlen(char const *);
int strpos(char *, char const *);
void strreplace(char cadena1[], const char cadena2[], const char cadena3[]) {
  if (cadena1 != NULL && cadena2 != NULL && cadena3 != NULL) {
    unsigned int tamCad2 = strlen(cadena2);
    int pos = strpos(cadena1, cadena2);
    while (pos >= 0) {
      strdel(cadena1, pos, tamCad2);
      strinsert(cadena3, cadena1, pos);
      pos = strpos(cadena1, cadena2);
    }
  }
}


x86 assembly (clang, -O0):
<strreplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11d4 <strreplace+0x94>
cmpq   $0x0,-0x10(%rbp)
je     11d4 <strreplace+0x94>
cmpq   $0x0,-0x18(%rbp)
je     11d4 <strreplace+0x94>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strpos@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     11cf <strreplace+0x8f>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <strdel@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1060 <strinsert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strpos@plt>
mov    %eax,-0x20(%rbp)
jmp    1191 <strreplace+0x51>
jmp    11d4 <strreplace+0x94>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strreplace>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     11ab <strreplace+0x6b>
mov    %rsi,%r15
test   %rsi,%rsi
je     11ab <strreplace+0x6b>
mov    %rdx,%r14
test   %rdx,%rdx
je     11ab <strreplace+0x6b>
mov    %rdi,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strpos@plt>
test   %eax,%eax
js     11ab <strreplace+0x6b>
mov    %eax,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
call   1030 <strdel@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <strinsert@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strpos@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1180 <strreplace+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @strreplace(i8* %0, i8* %1, i8* %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
%7 = icmp ne i8* %2, null
%8 = and i1 %6, %7
br i1 %8, label %9, label %19
9: ; preds = %3
%10 = tail call i32 @strlen(i8* %1)
%11 = tail call i32 @strpos(i8* %0, i8* %1)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %9, %13
%14 = phi i32 [ %17, %13 ], [ %11, %9 ]
%15 = tail call i32 @strdel(i8* %0, i32 %14, i32 %10)
%16 = tail call i32 @strinsert(i8* %2, i8* %0, i32 %14)
%17 = tail call i32 @strpos(i8* %0, i8* %1)
%18 = icmp sgt i32 %17, -1
br i1 %18, label %13, label %19
19: ; preds = %13, %9, %3
ret void
}