#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 doRevDnsAddress(char *src, char *dst) {
  int i = 0;
  dst[0] = 0;
  for (i = 15; 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):
<doRevDnsAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0xf,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11a9 <doRevDnsAddress+0x89>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
and    $0xf,%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
and    $0xf0,%ecx
sar    $0x4,%ecx
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1145 <doRevDnsAddress+0x25>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doRevDnsAddress>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
movb   $0x0,(%rsi)
mov    $0x10,%ebx
lea    0xec3(%rip),%r15
nopl   (%rax)
mov    %r12,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %r12,%rdi
movzbl -0x1(%r14,%rbx,1),%ecx
mov    %ecx,%edx
and    $0xf,%edx
shr    $0x4,%ecx
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
add    $0xffffffffffffffff,%rbx
jne    1140 <doRevDnsAddress+0x20>
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
movabs $0x617072612e367069,%rcx
72 70 61
mov    %rcx,(%r12,%rax,1)
movw   $0x2e,0x8(%r12,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%x.%x.\00"
@.str.1 = [10 x i8] c"ip6.arpa.\00"
define void @doRevDnsAddress(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%6 = load i8*, i8** %4
%7 = getelementptr inbounds i8, i8* %6, i64 0
store i8 0, i8* %7
store i32 15, i32* %5
br label %8
8: ; preds = %33, %2
%9 = load i32, i32* %5
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %36
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = and i32 %22, 15
%24 = load i8*, i8** %3
%25 = load i32, i32* %5
%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* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %31)
br label %33
33: ; preds = %11
%34 = load i32, i32* %5
%35 = add nsw i32 %34, -1
store i32 %35, i32* %5
br label %8
36: ; preds = %8
%37 = load i8*, i8** %4
%38 = load i8*, i8** %4
%39 = call i32 @strlen(i8* %38)
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%x.%x.\00"
@.str.1 = [10 x i8] c"ip6.arpa.\00"
define void @doRevDnsAddress(i8* nocapture %0, i8* %1) {
store i8 0, i8* %1
br label %3
3: ; preds = %2, %3
%4 = phi i64 [ 15, %2 ], [ %14, %3 ]
%5 = tail call i32 @strlen(i8* %1)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %1, i64 %6
%8 = getelementptr inbounds i8, i8* %0, i64 %4
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = and i32 %10, 15
%12 = lshr i32 %10, 4
%13 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = add nsw i64 %4, -1
%15 = icmp eq i64 %4, 0
br i1 %15, label %16, label %3
16: ; preds = %3
%17 = tail call i32 @strlen(i8* %1)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(10) %19, i8* align 1 dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 10, i1 false)
ret void
}