#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*/ sprintf(char *, char *, ...);
int strlen(char *);
void doRevDnsZoneRoot(char *src, char *dst, int length) {
  int i = 0;
  dst[0] = 0;
  i = 15 - length / 8;
  switch (length % 8) {
  case 1:
    break;
  case 2:
    break;
  case 3:
    break;
  case 4:
    sprintf(dst + strlen(dst), "%x.", (src[i] & 0xf0) >> 4);
    break;
  case 5:
    break;
  case 6:
    break;
  case 7:
  default:
    break;
  }
  if (length % 8)
    i--;
  for (; i >= 0; i--) {
    sprintf(dst + strlen(dst), "%x.%x.", (src[i] & 0x0f),
            ((src[i] & 0xf0) >> 4));
  }
  sprintf(dst + strlen(dst), "ip6.arpa.");
}


x86 assembly (clang, -O0):
<doRevDnsZoneRoot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x14(%rbp),%ecx
mov    %ecx,%eax
add    $0x7,%eax
test   %ecx,%ecx
cmovs  %eax,%ecx
sar    $0x3,%ecx
mov    $0xf,%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x7,%edx
test   %ecx,%ecx
mov    %ecx,%eax
cmovs  %edx,%eax
not    %eax
or     $0x7,%eax
add    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x6,%eax
ja     11f4 <doRevDnsZoneRoot+0xd4>
mov    -0x20(%rbp),%rax
lea    0xe75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    11f9 <doRevDnsZoneRoot+0xd9>
jmp    11f9 <doRevDnsZoneRoot+0xd9>
jmp    11f9 <doRevDnsZoneRoot+0xd9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
and    $0xf0,%edx
sar    $0x4,%edx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    11f9 <doRevDnsZoneRoot+0xd9>
jmp    11f9 <doRevDnsZoneRoot+0xd9>
jmp    11f9 <doRevDnsZoneRoot+0xd9>
jmp    11f4 <doRevDnsZoneRoot+0xd4>
jmp    11f9 <doRevDnsZoneRoot+0xd9>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1216 <doRevDnsZoneRoot+0xf6>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    121b <doRevDnsZoneRoot+0xfb>
cmpl   $0x0,-0x18(%rbp)
jl     127f <doRevDnsZoneRoot+0x15f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
and    $0xf,%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
and    $0xf0,%ecx
sar    $0x4,%ecx
lea    0xdb2(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    121b <doRevDnsZoneRoot+0xfb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doRevDnsZoneRoot>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movb   $0x0,(%rsi)
lea    0x7(%rdx),%eax
test   %edx,%edx
cmovns %edx,%eax
mov    %eax,%ebp
sar    $0x3,%ebp
neg    %ebp
movslq %ebp,%r15
add    $0xf,%r15
and    $0xfffffff8,%eax
sub    %eax,%edx
je     117f <doRevDnsZoneRoot+0x5f>
cmp    $0x4,%edx
jne    1176 <doRevDnsZoneRoot+0x56>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
movzbl (%r14,%r15,1),%edx
shr    $0x4,%edx
lea    0xe94(%rip),%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
add    $0xe,%ebp
test   %ebp,%ebp
jns    1186 <doRevDnsZoneRoot+0x66>
jmp    11bb <doRevDnsZoneRoot+0x9b>
mov    %r15d,%ebp
test   %ebp,%ebp
js     11bb <doRevDnsZoneRoot+0x9b>
mov    %ebp,%ebp
lea    0xe71(%rip),%r15
nop
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
movzbl (%r14,%rbp,1),%ecx
mov    %ecx,%edx
and    $0xf,%edx
shr    $0x4,%ecx
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
add    $0xffffffffffffffff,%rbp
jb     1190 <doRevDnsZoneRoot+0x70>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movabs $0x617072612e367069,%rcx
72 70 61
mov    %rcx,(%rbx,%rax,1)
movw   $0x2e,0x8(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%x.\00"
@.str.1 = [7 x i8] c"%x.%x.\00"
@.str.2 = [10 x i8] c"ip6.arpa.\00"
define void @doRevDnsZoneRoot(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
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8 0, i8* %9
%10 = load i32, i32* %6
%11 = sdiv i32 %10, 8
%12 = sub nsw i32 15, %11
store i32 %12, i32* %7
%13 = load i32, i32* %6
%14 = srem i32 %13, 8
switch i32 %14, label %36 [
i32 1, label %15
i32 2, label %16
i32 3, label %17
i32 4, label %18
i32 5, label %33
i32 6, label %34
i32 7, label %35
]
15: ; preds = %3
br label %37
16: ; preds = %3
br label %37
17: ; preds = %3
br label %37
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8*, i8** %4
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = and i32 %29, 240
%31 = ashr i32 %30, 4
%32 = call i32 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %31)
br label %37
33: ; preds = %3
br label %37
34: ; preds = %3
br label %37
35: ; preds = %3
br label %36
36: ; preds = %3, %35
br label %37
37: ; preds = %36, %34, %33, %18, %17, %16, %15
%38 = load i32, i32* %6
%39 = srem i32 %38, 8
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %7
%43 = add nsw i32 %42, -1
store i32 %43, i32* %7
br label %44
44: ; preds = %41, %37
br label %45
45: ; preds = %70, %44
%46 = load i32, i32* %7
%47 = icmp sge i32 %46, 0
br i1 %47, label %48, label %73
48: ; preds = %45
%49 = load i8*, i8** %5
%50 = load i8*, i8** %5
%51 = call i32 @strlen(i8* %50)
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = load i8*, i8** %4
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = and i32 %59, 15
%61 = load i8*, i8** %4
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = and i32 %66, 240
%68 = ashr i32 %67, 4
%69 = call i32 (i8*, i8*, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %60, i32 %68)
br label %70
70: ; preds = %48
%71 = load i32, i32* %7
%72 = add nsw i32 %71, -1
store i32 %72, i32* %7
br label %45
73: ; preds = %45
%74 = load i8*, i8** %5
%75 = load i8*, i8** %5
%76 = call i32 @strlen(i8* %75)
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %74, i64 %77
%79 = call i32 (i8*, i8*, ...) @sprintf(i8* %78, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%x.\00"
@.str.1 = [7 x i8] c"%x.%x.\00"
@.str.2 = [10 x i8] c"ip6.arpa.\00"
define void @doRevDnsZoneRoot(i8* nocapture %0, i8* %1, i32 %2) {
store i8 0, i8* %1
%4 = sdiv i32 %2, -8
%5 = add nsw i32 %4, 15
%6 = srem i32 %2, 8
switch i32 %6, label %17 [
i32 4, label %7
i32 0, label %19
]
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %1)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = sext i32 %5 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = lshr i8 %13, 4
%15 = zext i8 %14 to i32
%16 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %7, %3
%18 = add nsw i32 %4, 14
br label %19
19: ; preds = %3, %17
%20 = phi i32 [ %18, %17 ], [ %5, %3 ]
%21 = icmp sgt i32 %20, -1
br i1 %21, label %22, label %37
22: ; preds = %19
%23 = zext i32 %20 to i64
br label %24
24: ; preds = %22, %24
%25 = phi i64 [ %23, %22 ], [ %35, %24 ]
%26 = tail call i32 @strlen(i8* %1)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %1, i64 %27
%29 = getelementptr inbounds i8, i8* %0, i64 %25
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = and i32 %31, 15
%33 = lshr i32 %31, 4
%34 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %28, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %33)
%35 = add nsw i64 %25, -1
%36 = icmp eq i64 %25, 0
br i1 %36, label %37, label %24
37: ; preds = %24, %19
%38 = tail call i32 @strlen(i8* %1)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %1, i64 %39
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(10) %40, i8* align 1 dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 10, i1 false)
ret void
}