#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 */
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int strlen(char const *);
char *dns_domain_replace(const char *full, const char *old_domain,
                         const char *new_domain) {
  int llen = strlen(full) - strlen(old_domain);
  int rlen = strlen(new_domain);
  char *ret = malloc(llen + rlen + 1);
  memcpy(ret, full, llen);
  memcpy(ret + llen, new_domain, rlen);
  ret[llen + rlen] = 0;
  return ret;
}


x86 assembly (clang, -O0):
<dns_domain_replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
add    -0x20(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dns_domain_replace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
lea    (%rbx,%r12,1),%ebp
lea    (%rbx,%r12,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movslq %ebx,%rdi
add    %r13,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @dns_domain_replace(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %11, %13
store i32 %14, i32* %7
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %8
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = add nsw i32 %17, %18
%20 = add nsw i32 %19, 1
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = load i8*, i8** %4
%24 = load i32, i32* %7
%25 = call i32 @memcpy(i8* %22, i8* %23, i32 %24)
%26 = load i8*, i8** %9
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8*, i8** %6
%31 = load i32, i32* %8
%32 = call i32 @memcpy(i8* %29, i8* %30, i32 %31)
%33 = load i8*, i8** %9
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = add nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %33, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %9
ret i8* %39
}

LLVM IR (-O2):
define i8* @dns_domain_replace(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = sub nsw i32 %4, %5
%7 = tail call i32 @strlen(i8* %2)
%8 = add nsw i32 %6, %7
%9 = add nsw i32 %8, 1
%10 = tail call i8* @malloc(i32 %9)
%11 = tail call i32 @memcpy(i8* %10, i8* %0, i32 %6)
%12 = sext i32 %6 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = tail call i32 @memcpy(i8* %13, i8* %2, i32 %7)
%15 = sext i32 %8 to i64
%16 = getelementptr inbounds i8, i8* %10, i64 %15
store i8 0, i8* %16
ret i8* %10
}