unsigned char *install_domain_name(p, domain_name)
unsigned char *p;
char *domain_name;
{
  *p++ = '.';
  strcpy((char *)p, domain_name);
  p--;
  while (*p != '\0') {
    if (*p == '.') {
      unsigned char *end = p + 1;
      while (*end != '.' && *end != '\0')
        end++;
      *p = end - p - 1;
    }
    p++;
  }
  return p + 1;
}


x86 assembly (clang, -O0):
<install_domain_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x2e,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     11e5 <install_domain_name+0xd5>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2e,%eax
jne    11d4 <install_domain_name+0xc4>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x19(%rbp)
je     119c <install_domain_name+0x8c>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11ac <install_domain_name+0x9c>
jmp    11bd <install_domain_name+0xad>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1177 <install_domain_name+0x67>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    114b <install_domain_name+0x3b>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<install_domain_name>:
push   %rbx
mov    %rdi,%rbx
add    $0x1,%rdi
movb   $0x2e,(%rbx)
call   1030 <strcpy@plt>
mov    $0x2e,%al
jmp    113b <install_domain_name+0x2b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %al,%al
je     1167 <install_domain_name+0x57>
mov    0x1(%rbx),%al
add    $0x1,%rbx
cmp    $0x2e,%al
jne    1130 <install_domain_name+0x20>
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx,%rax,1),%ecx
add    $0x1,%rax
cmp    $0x2e,%cl
je     1161 <install_domain_name+0x51>
test   %cl,%cl
jne    1150 <install_domain_name+0x40>
add    $0xfe,%al
mov    %al,(%rbx)
jmp    1134 <install_domain_name+0x24>
add    $0x1,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @install_domain_name(i8* %0, i8* nocapture %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 1
store i8 46, i8* %0
%4 = tail call i8* @strcpy(i8* %3, i8* dereferenceable(1) %1)
br label %5
5: ; preds = %18, %2
%6 = phi i8 [ %20, %18 ], [ 46, %2 ]
%7 = phi i8* [ %19, %18 ], [ %0, %2 ]
switch i8 %6, label %18 [
i8 0, label %21
i8 46, label %8
]
8: ; preds = %5, %8
%9 = phi i8* [ %10, %8 ], [ %7, %5 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %10
switch i8 %11, label %8 [
i8 46, label %12
i8 0, label %12
]
12: ; preds = %8, %8
%13 = ptrtoint i8* %10 to i64
%14 = ptrtoint i8* %7 to i64
%15 = xor i64 %14, -1
%16 = add i64 %13, %15
%17 = trunc i64 %16 to i8
store i8 %17, i8* %7
br label %18
18: ; preds = %5, %12
%19 = getelementptr inbounds i8, i8* %7, i64 1
%20 = load i8, i8* %19
br label %5
21: ; preds = %5
%22 = getelementptr inbounds i8, i8* %7, i64 1
ret i8* %22
}