#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 */
struct in6_addr {
  int *s6_addr;
};

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
void ipv62escaped(const struct in6_addr *addr, char *escaped) {
  int i;
  for (i = 15; i >= 0; i--) {
    sprintf(escaped, "%x.%x.", addr->s6_addr[i] % 0x10,
            addr->s6_addr[i] / 0x10);
    escaped += strlen(escaped);
  }
  strcpy(escaped, "ip6.arpa.");
}


x86 assembly (clang, -O0):
<ipv62escaped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xf,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11bc <ipv62escaped+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%edx
mov    %eax,%ecx
lea    0xe70(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1147 <ipv62escaped+0x17>
mov    -0x10(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv62escaped>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%r15
mov    $0xf,%ebx
lea    0xeb6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%r15),%rcx
mov    (%rcx,%rbx,4),%edx
lea    0xf(%rdx),%ecx
test   %edx,%edx
cmovns %edx,%ecx
mov    %rax,%r12
mov    %ecx,%eax
and    $0xfffffff0,%eax
sub    %eax,%edx
sar    $0x4,%ecx
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <sprintf@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
add    %r12,%rax
add    $0xffffffffffffffff,%rbx
jb     1150 <ipv62escaped+0x20>
lea    0xe77(%rip),%rsi
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
%struct.in6_addr = type { i32* }
@.str = [7 x i8] c"%x.%x.\00"
@.str.1 = [10 x i8] c"ip6.arpa.\00"
define void @ipv62escaped(%struct.in6_addr* %0, i8* %1) {
%3 = alloca %struct.in6_addr*
%4 = alloca i8*
%5 = alloca i32
store %struct.in6_addr* %0, %struct.in6_addr** %3
store i8* %1, i8** %4
store i32 15, i32* %5
br label %6
6: ; preds = %33, %2
%7 = load i32, i32* %5
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %36
9: ; preds = %6
%10 = load i8*, i8** %4
%11 = load %struct.in6_addr*, %struct.in6_addr** %3
%12 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %11, i32 0, i32 0
%13 = load i32*, i32** %12
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = srem i32 %17, 16
%19 = load %struct.in6_addr*, %struct.in6_addr** %3
%20 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %19, i32 0, i32 0
%21 = load i32*, i32** %20
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = sdiv i32 %25, 16
%27 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %26)
%28 = load i8*, i8** %4
%29 = call i32 @strlen(i8* %28)
%30 = load i8*, i8** %4
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %4
br label %33
33: ; preds = %9
%34 = load i32, i32* %5
%35 = add nsw i32 %34, -1
store i32 %35, i32* %5
br label %6
36: ; preds = %6
%37 = load i8*, i8** %4
%38 = call i32 @strcpy(i8* %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
ret void
}

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