void _mangle_email_links(char *buf) {
  assert(buf);
  while (*buf && (buf = strstr(buf, "<email>"))) {
    char *temp, *end = strstr(buf, "</a>");
    assert(end);
    buf += 7;
    temp = _mangle_email(buf, end - buf);
    memmove(buf + strlen(temp), end, strlen(end) + 1);
    strncpy(buf, temp, strlen(temp));
    free(temp);
  }
}


x86 assembly (clang, -O0):
<_mangle_email_links>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1070 <assert@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     11ba <_mangle_email_links+0x4a>
mov    -0x8(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11ca <_mangle_email_links+0x5a>
jmp    128c <_mangle_email_links+0x11c>
mov    -0x8(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1070 <assert@plt>
mov    -0x8(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rax
sub    %rax,%rsi
mov    $0x0,%al
call   1050 <_mangle_email@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1080 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1187 <_mangle_email_links+0x17>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mangle_email_links>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
xor    %eax,%eax
call   1070 <assert@plt>
cmpb   $0x0,(%r12)
je     1239 <_mangle_email_links+0xc9>
lea    0xe69(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     1239 <_mangle_email_links+0xc9>
mov    %rax,%rbx
mov    %rax,%rdi
lea    0xe47(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,%r13
mov    %rax,%rdi
xor    %eax,%eax
call   1070 <assert@plt>
lea    0x7(%rbx),%r12
mov    %r13,%rsi
sub    %r12,%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <_mangle_email@plt>
movslq %eax,%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    (%rbx,%rax,1),%r14
add    $0x7,%r14
mov    %r13,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %r13,%rsi
call   1080 <memmove@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1040 <strncpy@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
cmpb   $0x0,0x7(%rbx)
jne    11a0 <_mangle_email_links+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"<email>\00"
@.str.1 = [5 x i8] c"</a>\00"
define void @_mangle_email_links(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %5)
br label %7
7: ; preds = %18, %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i8*, i8** %2
%14 = call i8* @strstr(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %2
%15 = icmp ne i8* %14, null
br label %16
16: ; preds = %12, %7
%17 = phi i1 [ false, %7 ], [ %15, %12 ]
br i1 %17, label %18, label %48
18: ; preds = %16
%19 = load i8*, i8** %2
%20 = call i8* @strstr(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %21)
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i64 7
store i8* %24, i8** %2
%25 = load i8*, i8** %2
%26 = load i8*, i8** %4
%27 = load i8*, i8** %2
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = call i32 (i8*, i64, ...) bitcast (i32 (...)* @_mangle_email to i32 (i8*, i64, ...)*)(i8* %25, i64 %30)
%32 = sext i32 %31 to i64
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %3
%34 = load i8*, i8** %2
%35 = load i8*, i8** %3
%36 = call i64 @strlen(i8* %35)
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8*, i8** %4
%39 = load i8*, i8** %4
%40 = call i64 @strlen(i8* %39)
%41 = add i64 %40, 1
%42 = load i8*, i8** %2
%43 = load i8*, i8** %3
%44 = load i8*, i8** %3
%45 = call i64 @strlen(i8* %44)
%46 = call i8* @strncpy(i8* %42, i8* %43, i64 %45)
%47 = load i8*, i8** %3
br label %7
48: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"<email>\00"
@.str.1 = [5 x i8] c"</a>\00"
define void @_mangle_email_links(i8* %0) {
%2 = tail call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %27, label %5
5: ; preds = %1, %9
%6 = phi i8* [ %12, %9 ], [ %0, %1 ]
%7 = tail call i8* @strstr(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %27, label %9
9: ; preds = %5
%10 = tail call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %10)
%12 = getelementptr inbounds i8, i8* %7, i64 7
%13 = ptrtoint i8* %10 to i64
%14 = ptrtoint i8* %12 to i64
%15 = sub i64 %13, %14
%16 = tail call i32 (i8*, i64, ...) bitcast (i32 (...)* @_mangle_email to i32 (i8*, i64, ...)*)(i8* %12, i64 %15)
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
%19 = tail call i64 @strlen(i8* dereferenceable(1) %18)
%20 = getelementptr inbounds i8, i8* %12, i64 %19
%21 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%22 = add i64 %21, 1
tail call void @llvm.memmove.p0i8.p0i8.i64(i8* align 1 %20, i8* align 1 %10, i64 %22, i1 false)
%23 = tail call i64 @strlen(i8* dereferenceable(1) %18)
%24 = tail call i8* @strncpy(i8* %12, i8* %18, i64 %23)
tail call void @free(i8* %18)
%25 = load i8, i8* %12
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %5
27: ; preds = %5, %9, %1
ret void
}