#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 /*<<< orphan*/ memmove(int *, int *, int);
char *strcpy(int *, char *);
char *dns_decode_name(uint8_t *p) {
  uint8_t *end = (p + 255);
  uint8_t *start = p;
  if (!*p)
    return strcpy(p, ".");
  do {
    int len = *p;
    if (len & 0xc0)
      return NULL;
    if ((p + len) > (end - 2))
      return NULL;
    memmove(p, p + 1, len);
    p += len;
    *p++ = '.';
  } while (*p);
  return start;
}


x86 assembly (clang, -O0):
<dns_decode_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x3fc,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1168 <dns_decode_name+0x48>
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    1214 <dns_decode_name+0xf4>
jmp    116d <dns_decode_name+0x4d>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
and    $0xc0,%eax
cmp    $0x0,%eax
je     1194 <dns_decode_name+0x74>
movq   $0x0,-0x8(%rbp)
jmp    1214 <dns_decode_name+0xf4>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    -0x18(%rbp),%rcx
add    $0xfffffffffffffff8,%rcx
cmp    %rcx,%rax
jbe    11c1 <dns_decode_name+0xa1>
movq   $0x0,-0x8(%rbp)
jmp    1214 <dns_decode_name+0xf4>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    -0x24(%rbp),%edx
call   1040 <memmove@plt>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movl   $0x2e,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    116d <dns_decode_name+0x4d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dns_decode_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    (%rdi),%edx
test   %edx,%edx
je     1182 <dns_decode_name+0x62>
xor    %r14d,%r14d
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   $0xc0,%dl
jne    1179 <dns_decode_name+0x59>
movslq %edx,%rbx
add    %rax,%rbx
cmp    $0xfd,%rbx
jg     1179 <dns_decode_name+0x59>
lea    (%r15,%rax,4),%rdi
lea    0x4(%rdi),%rsi
call   1040 <memmove@plt>
lea    0x1(%rbx),%rax
movl   $0x2e,(%r15,%rbx,4)
mov    0x4(%r15,%rbx,4),%edx
test   %edx,%edx
jne    1140 <dns_decode_name+0x20>
mov    %r15,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe77(%rip),%rsi
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @dns_decode_name(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = getelementptr inbounds i32, i32* %7, i64 255
store i32* %8, i32** %4
%9 = load i32*, i32** %3
store i32* %9, i32** %5
%10 = load i32*, i32** %3
%11 = load i32, i32* %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = load i32*, i32** %3
%15 = call i8* @strcpy(i32* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %2
br label %52
16: ; preds = %1
br label %17
17: ; preds = %45, %16
%18 = load i32*, i32** %3
%19 = load i32, i32* %18
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = and i32 %20, 192
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i8* null, i8** %2
br label %52
24: ; preds = %17
%25 = load i32*, i32** %3
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32*, i32** %4
%30 = getelementptr inbounds i32, i32* %29, i64 -2
%31 = icmp ugt i32* %28, %30
br i1 %31, label %32, label %33
32: ; preds = %24
store i8* null, i8** %2
br label %52
33: ; preds = %24
%34 = load i32*, i32** %3
%35 = load i32*, i32** %3
%36 = getelementptr inbounds i32, i32* %35, i64 1
%37 = load i32, i32* %6
%38 = call i32 @memmove(i32* %34, i32* %36, i32 %37)
%39 = load i32, i32* %6
%40 = load i32*, i32** %3
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i32, i32* %40, i64 %41
store i32* %42, i32** %3
%43 = load i32*, i32** %3
%44 = getelementptr inbounds i32, i32* %43, i32 1
store i32* %44, i32** %3
store i32 46, i32* %43
br label %45
45: ; preds = %33
%46 = load i32*, i32** %3
%47 = load i32, i32* %46
%48 = icmp ne i32 %47, 0
br i1 %48, label %17, label %49
49: ; preds = %45
%50 = load i32*, i32** %5
%51 = bitcast i32* %50 to i8*
store i8* %51, i8** %2
br label %52
52: ; preds = %49, %32, %23, %13
%53 = load i8*, i8** %2
ret i8* %53
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @dns_decode_name(i32* %0) {
%2 = load i32, i32* %0
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* @strcpy(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %26
6: ; preds = %1, %16
%7 = phi i32 [ %22, %16 ], [ %2, %1 ]
%8 = phi i64 [ %20, %16 ], [ 0, %1 ]
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = and i32 %7, 192
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %6
%13 = sext i32 %7 to i64
%14 = add nsw i64 %8, %13
%15 = icmp sgt i64 %14, 253
br i1 %15, label %26, label %16
16: ; preds = %12
%17 = getelementptr inbounds i32, i32* %0, i64 %14
%18 = getelementptr inbounds i32, i32* %9, i64 1
%19 = tail call i32 @memmove(i32* %9, i32* %18, i32 %7)
%20 = add nsw i64 %14, 1
store i32 46, i32* %17
%21 = getelementptr inbounds i32, i32* %0, i64 %20
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %6
24: ; preds = %16
%25 = bitcast i32* %0 to i8*
br label %26
26: ; preds = %12, %6, %24, %4
%27 = phi i8* [ %25, %24 ], [ %5, %4 ], [ null, %6 ], [ null, %12 ]
ret i8* %27
}