#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 */
int /*<<< orphan*/ memcpy(char *, char const *, int);
int DnsDomain2stdDomain(const char *dnsDomain, char *domain) {
  const char *pStr = dnsDomain;
  int cnt;
  int i = 0;
  while (*pStr && pStr < dnsDomain + 256) {
    cnt = *pStr++;
    memcpy(&domain[i], pStr, cnt);
    i += cnt;
    domain[i++] = '.';
    pStr += cnt;
  }
  domain[i - 1] = 0;
  return 0;
}


x86 assembly (clang, -O0):
<DnsDomain2stdDomain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     115c <DnsDomain2stdDomain+0x4c>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    $0x100,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    116c <DnsDomain2stdDomain+0x5c>
jmp    11cd <DnsDomain2stdDomain+0xbd>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    112f <DnsDomain2stdDomain+0x1f>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DnsDomain2stdDomain>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    (%rdi),%al
test   %al,%al
je     117c <DnsDomain2stdDomain+0x6c>
mov    %rdi,%r15
xor    %r12d,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl %al,%r13d
lea    (%r15,%rbx,1),%rsi
add    $0x1,%rsi
movslq %r12d,%rdi
add    %r14,%rdi
mov    %r13d,%edx
call   1030 <memcpy@plt>
lea    (%r12,%r13,1),%eax
movslq %eax,%rcx
movb   $0x2e,(%r14,%rcx,1)
movsbq %r13b,%rax
add    %rax,%rbx
add    $0x1,%rbx
movzbl (%r15,%rbx,1),%eax
test   %al,%al
je     1183 <DnsDomain2stdDomain+0x73>
add    %r13d,%r12d
add    $0x1,%r12d
cmp    $0x100,%rbx
jl     1130 <DnsDomain2stdDomain+0x20>
jmp    1183 <DnsDomain2stdDomain+0x73>
mov    $0xffffffffffffffff,%rcx
movb   $0x0,(%r14,%rcx,1)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @DnsDomain2stdDomain(i8* %0, i8* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %28, label %5
5: ; preds = %2, %5
%6 = phi i8 [ %22, %5 ], [ %3, %2 ]
%7 = phi i32 [ %16, %5 ], [ 0, %2 ]
%8 = phi i64 [ %20, %5 ], [ 0, %2 ]
%9 = sext i8 %6 to i32
%10 = add nsw i64 %8, 1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = tail call i32 @memcpy(i8* %13, i8* %11, i32 %9)
%15 = add nsw i32 %7, %9
%16 = add nsw i32 %15, 1
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 46, i8* %18
%19 = sext i8 %6 to i64
%20 = add nsw i64 %10, %19
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
%24 = icmp slt i64 %20, 256
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %5, label %26
26: ; preds = %5
%27 = sext i32 %15 to i64
br label %28
28: ; preds = %26, %2
%29 = phi i64 [ -1, %2 ], [ %27, %26 ]
%30 = getelementptr inbounds i8, i8* %1, i64 %29
store i8 0, i8* %30
ret i32 0
}