#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*/ memcpy(char *, char const *, scalar_t__);
scalar_t__ strlen(char const *);
char *strstr(char *, char const *);
void replaceall(char *str, const char *from, const char *to) {
  char *p;
  if (strlen(from) != strlen(to)) {
    return;
  }
  while ((p = strstr(str, from)) != NULL) {
    memcpy(p, to, strlen(to));
  }
  return;
}


x86 assembly (clang, -O0):
<replaceall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     116f <replaceall+0x3f>
jmp    11c2 <replaceall+0x92>
jmp    1174 <replaceall+0x44>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11bd <replaceall+0x8d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1040 <memcpy@plt>
jmp    1174 <replaceall+0x44>
jmp    11c2 <replaceall+0x92>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replaceall>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    %rax,%rbx
jne    1199 <replaceall+0x69>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1199 <replaceall+0x69>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1040 <memcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1170 <replaceall+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @replaceall(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %5
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %6
%11 = call i64 @strlen(i8* %10)
%12 = icmp ne i64 %9, %11
br i1 %12, label %13, label %14
13: ; preds = %3
br label %27
14: ; preds = %3
br label %15
15: ; preds = %20, %14
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i8* @strstr(i8* %16, i8* %17)
store i8* %18, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i8*, i8** %7
%22 = load i8*, i8** %6
%23 = load i8*, i8** %6
%24 = call i64 @strlen(i8* %23)
%25 = call i32 @memcpy(i8* %21, i8* %22, i64 %24)
br label %15
26: ; preds = %15
br label %27
27: ; preds = %26, %13
ret void
}

LLVM IR (-O2):
define void @replaceall(i8* %0, i8* nocapture %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %16
7: ; preds = %3
%8 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %16, label %10
10: ; preds = %7, %10
%11 = phi i8* [ %14, %10 ], [ %8, %7 ]
%12 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%13 = tail call i32 @memcpy(i8* %11, i8* %2, i64 %12)
%14 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %10
16: ; preds = %10, %7, %3
ret void
}