#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*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char const *);
char *xmalloc(int);
char *replaced(const char *s, const char *d, const char *src) {
  char *dst;
  unsigned long slen = strlen(s);
  unsigned long dlen = strlen(d);
  dst = xmalloc(strlen(src) - strlen(s) + strlen(d) + 1);
  memset(dst, 0, strlen(src) - strlen(s) + strlen(d) + 1);
  for (int i = 0; i < strlen(dst); ++i) {
  }
}


x86 assembly (clang, -O0):
<replaced>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x54(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1050 <xmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%rdi
add    %eax,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
cmp    %ecx,%eax
jge    1214 <replaced+0xe4>
jmp    1206 <replaced+0xd6>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e5 <replaced+0xb5>
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replaced>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    %ebp,%ebx
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1050 <xmalloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    %r15d,%ebp
lea    (%rax,%rbp,1),%edx
add    $0x1,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0xffffffff,%ebp
nop
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x1,%ebp
cmp    %eax,%ebp
jl     11b0 <replaced+0x80>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @replaced(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
store i64 %14, i64* %9
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
store i64 %17, i64* %10
%18 = load i8*, i8** %7
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %19, %21
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %22, %24
%26 = add nsw i32 %25, 1
%27 = call i8* @xmalloc(i32 %26)
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = load i8*, i8** %7
%30 = call i32 @strlen(i8* %29)
%31 = load i8*, i8** %5
%32 = call i32 @strlen(i8* %31)
%33 = sub nsw i32 %30, %32
%34 = load i8*, i8** %6
%35 = call i32 @strlen(i8* %34)
%36 = add nsw i32 %33, %35
%37 = add nsw i32 %36, 1
%38 = call i32 @memset(i8* %28, i32 0, i32 %37)
store i32 0, i32* %11
br label %39
39: ; preds = %45, %3
%40 = load i32, i32* %11
%41 = load i8*, i8** %8
%42 = call i32 @strlen(i8* %41)
%43 = icmp slt i32 %40, %42
br i1 %43, label %44, label %48
44: ; preds = %39
br label %45
45: ; preds = %44
%46 = load i32, i32* %11
%47 = add nsw i32 %46, 1
store i32 %47, i32* %11
br label %39
48: ; preds = %39
%49 = load i8*, i8** %4
ret i8* %49
}

LLVM IR (-O2):
define noalias i8* @replaced(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @strlen(i8* %2)
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @strlen(i8* %1)
%9 = add i32 %6, 1
%10 = sub i32 %9, %7
%11 = add i32 %10, %8
%12 = tail call i8* @xmalloc(i32 %11)
%13 = tail call i32 @strlen(i8* %2)
%14 = tail call i32 @strlen(i8* %0)
%15 = tail call i32 @strlen(i8* %1)
%16 = add i32 %13, 1
%17 = sub i32 %16, %14
%18 = add i32 %17, %15
%19 = tail call i32 @memset(i8* %12, i32 0, i32 %18)
br label %20
20: ; preds = %20, %3
%21 = phi i32 [ 0, %3 ], [ %24, %20 ]
%22 = tail call i32 @strlen(i8* %12)
%23 = icmp slt i32 %21, %22
%24 = add nuw nsw i32 %21, 1
br i1 %23, label %20, label %25
25: ; preds = %20
ret i8* undef
}