#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 */
unsigned int dns_dnlen(unsigned char const *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, unsigned int);
unsigned dns_dnreverse(register const unsigned char *dn,
                       register unsigned char *rdn, register unsigned len) {
  register unsigned c;
  if (!len)
    len = dns_dnlen(dn);
  rdn += len;
  *--rdn = '\0';
  while ((c = *dn) != 0) {
    ++c;
    rdn -= c;
    memcpy(rdn, dn, c);
    dn += c;
  }
  return len;
}


x86 assembly (clang, -O0):
<dns_dnreverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1149 <dns_dnreverse+0x29>
mov    -0x8(%rbp),%rdi
call   1030 <dns_dnlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,-0x1(%rax)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     11c4 <dns_dnreverse+0xa4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    116c <dns_dnreverse+0x4c>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dns_dnreverse>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%r15
test   %edx,%edx
jne    113f <dns_dnreverse+0x1f>
mov    %r15,%rdi
call   1030 <dns_dnlen@plt>
mov    %eax,%r14d
mov    %r14d,%ecx
movb   $0x0,-0x1(%rbp,%rcx,1)
mov    (%r15),%al
test   %al,%al
je     1186 <dns_dnreverse+0x66>
add    %rcx,%rbp
add    $0xffffffffffffffff,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
movzbl %al,%ebx
lea    0x1(%rbx),%rdx
sub    %rdx,%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <memcpy@plt>
movzbl 0x1(%r15,%rbx,1),%eax
add    %rbx,%r15
add    $0x1,%r15
test   %al,%al
jne    1160 <dns_dnreverse+0x40>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dns_dnreverse(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = call i32 @dns_dnlen(i8* %11)
store i32 %12, i32* %6
br label %13
13: ; preds = %10, %3
%14 = load i32, i32* %6
%15 = load i8*, i8** %5
%16 = zext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %15, i64 %16
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i32 -1
store i8* %19, i8** %5
store i8 0, i8* %19
br label %20
20: ; preds = %25, %13
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
store i32 %23, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %41
25: ; preds = %20
%26 = load i32, i32* %7
%27 = add i32 %26, 1
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = load i8*, i8** %5
%30 = zext i32 %28 to i64
%31 = sub i64 0, %30
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8* %32, i8** %5
%33 = load i8*, i8** %5
%34 = load i8*, i8** %4
%35 = load i32, i32* %7
%36 = call i32 @memcpy(i8* %33, i8* %34, i32 %35)
%37 = load i32, i32* %7
%38 = load i8*, i8** %4
%39 = zext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8* %40, i8** %4
br label %20
41: ; preds = %20
%42 = load i32, i32* %6
ret i32 %42
}

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