#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 */
typedef int uint8_t;

/* Variables and functions */
int _dns_cname_length(char *);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
void _dns_insert_cname(char *s, char *p) {
  int i;
  uint8_t len, dlen;
  if (s == NULL) {
    *p = 0;
    return;
  }
  if (!strcmp(s, ".")) {
    p[0] = 1;
    p[1] = '.';
    p[2] = 0;
    return;
  }
  len = _dns_cname_length(s);
  p[0] = '.';
  memmove(p + 1, s, len);
  p[len + 1] = '.';
  dlen = 0;
  for (i = len + 1; i >= 0; i--) {
    if (p[i] == '.') {
      p[i] = dlen;
      dlen = 0;
    } else
      dlen++;
  }
}


x86 assembly (clang, -O0):
<_dns_insert_cname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1157 <_dns_insert_cname+0x27>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    122b <_dns_insert_cname+0xfb>
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    118c <_dns_insert_cname+0x5c>
mov    -0x10(%rbp),%rax
movb   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x2e,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
jmp    122b <_dns_insert_cname+0xfb>
mov    -0x8(%rbp),%rdi
call   1050 <_dns_cname_length@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <memmove@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     122b <_dns_insert_cname+0xfb>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    120f <_dns_insert_cname+0xdf>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movl   $0x0,-0x1c(%rbp)
jmp    1218 <_dns_insert_cname+0xe8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    121d <_dns_insert_cname+0xed>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11d4 <_dns_insert_cname+0xa4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_dns_insert_cname>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
test   %rdi,%rdi
je     11b2 <_dns_insert_cname+0x82>
mov    %rdi,%r14
lea    0xeba(%rip),%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11a9 <_dns_insert_cname+0x79>
mov    %r14,%rdi
call   1050 <_dns_cname_length@plt>
mov    %eax,%ebp
movb   $0x2e,(%rbx)
lea    0x1(%rbx),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <memmove@plt>
movslq %ebp,%rax
movb   $0x2e,0x1(%rbx,%rax,1)
cmp    $0xffffffff,%eax
jl     11b5 <_dns_insert_cname+0x85>
lea    0x1(%rax),%rcx
mov    %ecx,%ecx
add    $0x2,%eax
add    %rcx,%rbx
xor    %ecx,%ecx
jmp    119e <_dns_insert_cname+0x6e>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ecx
add    $0xffffffff,%eax
add    $0xffffffffffffffff,%rbx
test   %eax,%eax
jle    11b5 <_dns_insert_cname+0x85>
cmpb   $0x2e,(%rbx)
jne    1190 <_dns_insert_cname+0x60>
mov    %cl,(%rbx)
xor    %ecx,%ecx
jmp    1193 <_dns_insert_cname+0x63>
movw   $0x2e01,(%rbx)
add    $0x2,%rbx
movb   $0x0,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define void @_dns_insert_cname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i8*, i8** %4
store i8 0, i8* %11
br label %65
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i32 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 1, i8* %18
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8 46, i8* %20
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 2
store i8 0, i8* %22
br label %65
23: ; preds = %12
%24 = load i8*, i8** %3
%25 = call i32 @_dns_cname_length(i8* %24)
store i32 %25, i32* %6
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 46, i8* %27
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8*, i8** %3
%31 = load i32, i32* %6
%32 = call i32 @memmove(i8* %29, i8* %30, i32 %31)
%33 = load i8*, i8** %4
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 46, i8* %37
store i32 0, i32* %7
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %40
40: ; preds = %62, %23
%41 = load i32, i32* %5
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %65
43: ; preds = %40
%44 = load i8*, i8** %4
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 46
br i1 %50, label %51, label %58
51: ; preds = %43
%52 = load i32, i32* %7
%53 = trunc i32 %52 to i8
%54 = load i8*, i8** %4
%55 = load i32, i32* %5
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 %53, i8* %57
store i32 0, i32* %7
br label %61
58: ; preds = %43
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %61
61: ; preds = %58, %51
br label %62
62: ; preds = %61
%63 = load i32, i32* %5
%64 = add nsw i32 %63, -1
store i32 %64, i32* %5
br label %40
65: ; preds = %10, %16, %40
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define void @_dns_insert_cname(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %35, label %4
4: ; preds = %2
%5 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
store i8 1, i8* %1
%8 = getelementptr inbounds i8, i8* %1, i64 1
store i8 46, i8* %8
%9 = getelementptr inbounds i8, i8* %1, i64 2
br label %35
10: ; preds = %4
%11 = tail call i32 @_dns_cname_length(i8* %0)
store i8 46, i8* %1
%12 = getelementptr inbounds i8, i8* %1, i64 1
%13 = tail call i32 @memmove(i8* %12, i8* %0, i32 %11)
%14 = add nsw i32 %11, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
store i8 46, i8* %16
%17 = icmp sgt i32 %11, -2
br i1 %17, label %18, label %37
18: ; preds = %10
%19 = zext i32 %14 to i64
br label %20
20: ; preds = %18, %30
%21 = phi i64 [ %19, %18 ], [ %32, %30 ]
%22 = phi i32 [ 0, %18 ], [ %31, %30 ]
%23 = getelementptr inbounds i8, i8* %1, i64 %21
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 46
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = trunc i32 %22 to i8
store i8 %27, i8* %23
br label %30
28: ; preds = %20
%29 = add nsw i32 %22, 1
br label %30
30: ; preds = %26, %28
%31 = phi i32 [ 0, %26 ], [ %29, %28 ]
%32 = add nsw i64 %21, -1
%33 = trunc i64 %21 to i32
%34 = icmp sgt i32 %33, 0
br i1 %34, label %20, label %37
35: ; preds = %2, %7
%36 = phi i8* [ %9, %7 ], [ %1, %2 ]
store i8 0, i8* %36
br label %37
37: ; preds = %30, %35, %10
ret void
}