#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *strstr(char const *, char const *);
void typereplace(const char *s, char *d, const char *from, const char *to) {
  int i;
  char *p, s2[200];
  if ((p = strstr(s, from))) {
    i = strlen(from);
    strcpy(s2, p + i);
    strcpy(p, to);
    strcat(p, s2);
    p = d + (int)(p - s);
    strcpy(s2, p + i);
    strcpy(p, to);
    strcat(p, s2);
  }
}


x86 assembly (clang, -O0):
<typereplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1203 <typereplace+0xc3>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   1050 <strcat@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<typereplace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r15
mov    %rdx,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11cc <typereplace+0x8c>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbp
mov    %rbx,%rsi
add    %rbp,%rsi
mov    %rsp,%r12
mov    %r12,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
sub    %r15d,%ebx
movslq %ebx,%rax
add    %rax,%r13
add    %r13,%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @typereplace(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [200 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%12 = load i8*, i8** %5
%13 = load i8*, i8** %7
%14 = call i8* @strstr(i8* %12, i8* %13)
store i8* %14, i8** %10
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %52
16: ; preds = %4
%17 = load i8*, i8** %7
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %9
%19 = getelementptr inbounds [200 x i8], [200 x i8]* %11, i64 0, i64 0
%20 = load i8*, i8** %10
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = call i32 @strcpy(i8* %19, i8* %23)
%25 = load i8*, i8** %10
%26 = load i8*, i8** %8
%27 = call i32 @strcpy(i8* %25, i8* %26)
%28 = load i8*, i8** %10
%29 = getelementptr inbounds [200 x i8], [200 x i8]* %11, i64 0, i64 0
%30 = call i32 @strcat(i8* %28, i8* %29)
%31 = load i8*, i8** %6
%32 = load i8*, i8** %10
%33 = load i8*, i8** %5
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = trunc i64 %36 to i32
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %31, i64 %38
store i8* %39, i8** %10
%40 = getelementptr inbounds [200 x i8], [200 x i8]* %11, i64 0, i64 0
%41 = load i8*, i8** %10
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = call i32 @strcpy(i8* %40, i8* %44)
%46 = load i8*, i8** %10
%47 = load i8*, i8** %8
%48 = call i32 @strcpy(i8* %46, i8* %47)
%49 = load i8*, i8** %10
%50 = getelementptr inbounds [200 x i8], [200 x i8]* %11, i64 0, i64 0
%51 = call i32 @strcat(i8* %49, i8* %50)
br label %52
52: ; preds = %16, %4
ret void
}

LLVM IR (-O2):
define void @typereplace(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [200 x i8]
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%7 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %2)
%8 = icmp eq i8* %7, null
br i1 %8, label %26, label %9
9: ; preds = %4
%10 = tail call i32 @strlen(i8* %2)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = call i32 @strcpy(i8* %6, i8* %12)
%14 = call i32 @strcpy(i8* %7, i8* %3)
%15 = call i32 @strcat(i8* %7, i8* %6)
%16 = ptrtoint i8* %7 to i64
%17 = ptrtoint i8* %0 to i64
%18 = sub i64 %16, %17
%19 = shl i64 %18, 32
%20 = ashr exact i64 %19, 32
%21 = getelementptr inbounds i8, i8* %1, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 %11
%23 = call i32 @strcpy(i8* %6, i8* %22)
%24 = call i32 @strcpy(i8* %21, i8* %3)
%25 = call i32 @strcat(i8* %21, i8* %6)
br label %26
26: ; preds = %9, %4
ret void
}