#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 *, unsigned char, unsigned char);
int sprintip6(char *dest, unsigned char *ip) {
  int i, len = 0;
  for (i = 0; i < 16; i += 2) {
    if (i > 0)
      dest[len++] = ':';
    sprintf(dest + len, "%02X%02X", ip[i], ip[i + 1]);
    len += 4;
  }
  dest[len] = '\0';
  return len;
}


x86 assembly (clang, -O0):
<sprintip6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    11a5 <sprintip6+0x95>
cmpl   $0x0,-0x14(%rbp)
jle    1158 <sprintip6+0x48>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0x3a,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
lea    0xe7e(%rip),%rsi
movzbl %dl,%edx
movzbl (%rax,%rcx,1),%ecx
call   1030 <sprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    112e <sprintip6+0x1e>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprintip6>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
movzbl (%rsi),%edx
movzbl 0x1(%rsi),%ecx
lea    0xed7(%rip),%r15
mov    %r15,%rsi
call   1030 <sprintf@plt>
movb   $0x3a,0x4(%r14)
lea    0x5(%r14),%rdi
movzbl 0x2(%rbx),%edx
movzbl 0x3(%rbx),%ecx
mov    %r15,%rsi
call   1030 <sprintf@plt>
movb   $0x3a,0x9(%r14)
lea    0xa(%r14),%rdi
movzbl 0x4(%rbx),%edx
movzbl 0x5(%rbx),%ecx
mov    %r15,%rsi
call   1030 <sprintf@plt>
movb   $0x3a,0xe(%r14)
lea    0xf(%r14),%rdi
movzbl 0x6(%rbx),%edx
movzbl 0x7(%rbx),%ecx
mov    %r15,%rsi
call   1030 <sprintf@plt>
movb   $0x3a,0x13(%r14)
lea    0x14(%r14),%rdi
movzbl 0x8(%rbx),%edx
movzbl 0x9(%rbx),%ecx
mov    %r15,%rsi
call   1030 <sprintf@plt>
movb   $0x3a,0x18(%r14)
lea    0x19(%r14),%rdi
movzbl 0xa(%rbx),%edx
movzbl 0xb(%rbx),%ecx
mov    %r15,%rsi
call   1030 <sprintf@plt>
movb   $0x3a,0x1d(%r14)
lea    0x1e(%r14),%rdi
movzbl 0xc(%rbx),%edx
movzbl 0xd(%rbx),%ecx
mov    %r15,%rsi
call   1030 <sprintf@plt>
movb   $0x3a,0x22(%r14)
lea    0x23(%r14),%rdi
movzbl 0xe(%rbx),%edx
movzbl 0xf(%rbx),%ecx
mov    %r15,%rsi
call   1030 <sprintf@plt>
movb   $0x0,0x27(%r14)
mov    $0x27,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%02X%02X\00"
define i32 @sprintip6(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %7
7: ; preds = %38, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 16
br i1 %9, label %10, label %41
10: ; preds = %7
%11 = load i32, i32* %5
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = load i32, i32* %6
%16 = add nsw i32 %15, 1
store i32 %16, i32* %6
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
store i8 58, i8* %18
br label %19
19: ; preds = %13, %10
%20 = load i8*, i8** %3
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8*, i8** %4
%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 = load i8*, i8** %4
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 zeroext %28, i8 zeroext %34)
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 4
store i32 %37, i32* %6
br label %38
38: ; preds = %19
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 2
store i32 %40, i32* %5
br label %7
41: ; preds = %7
%42 = load i8*, i8** %3
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
@.str = [9 x i8] c"%02X%02X\00"
define i32 @sprintip6(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = getelementptr inbounds i8, i8* %1, i64 1
%5 = load i8, i8* %4
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 zeroext %3, i8 zeroext %5)
%7 = getelementptr inbounds i8, i8* %0, i64 4
store i8 58, i8* %7
%8 = getelementptr inbounds i8, i8* %0, i64 5
%9 = getelementptr inbounds i8, i8* %1, i64 2
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %1, i64 3
%12 = load i8, i8* %11
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 zeroext %10, i8 zeroext %12)
%14 = getelementptr inbounds i8, i8* %0, i64 9
store i8 58, i8* %14
%15 = getelementptr inbounds i8, i8* %0, i64 10
%16 = getelementptr inbounds i8, i8* %1, i64 4
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %1, i64 5
%19 = load i8, i8* %18
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 zeroext %17, i8 zeroext %19)
%21 = getelementptr inbounds i8, i8* %0, i64 14
store i8 58, i8* %21
%22 = getelementptr inbounds i8, i8* %0, i64 15
%23 = getelementptr inbounds i8, i8* %1, i64 6
%24 = load i8, i8* %23
%25 = getelementptr inbounds i8, i8* %1, i64 7
%26 = load i8, i8* %25
%27 = tail call i32 @sprintf(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 zeroext %24, i8 zeroext %26)
%28 = getelementptr inbounds i8, i8* %0, i64 19
store i8 58, i8* %28
%29 = getelementptr inbounds i8, i8* %0, i64 20
%30 = getelementptr inbounds i8, i8* %1, i64 8
%31 = load i8, i8* %30
%32 = getelementptr inbounds i8, i8* %1, i64 9
%33 = load i8, i8* %32
%34 = tail call i32 @sprintf(i8* dereferenceable(1) %29, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 zeroext %31, i8 zeroext %33)
%35 = getelementptr inbounds i8, i8* %0, i64 24
store i8 58, i8* %35
%36 = getelementptr inbounds i8, i8* %0, i64 25
%37 = getelementptr inbounds i8, i8* %1, i64 10
%38 = load i8, i8* %37
%39 = getelementptr inbounds i8, i8* %1, i64 11
%40 = load i8, i8* %39
%41 = tail call i32 @sprintf(i8* dereferenceable(1) %36, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 zeroext %38, i8 zeroext %40)
%42 = getelementptr inbounds i8, i8* %0, i64 29
store i8 58, i8* %42
%43 = getelementptr inbounds i8, i8* %0, i64 30
%44 = getelementptr inbounds i8, i8* %1, i64 12
%45 = load i8, i8* %44
%46 = getelementptr inbounds i8, i8* %1, i64 13
%47 = load i8, i8* %46
%48 = tail call i32 @sprintf(i8* dereferenceable(1) %43, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 zeroext %45, i8 zeroext %47)
%49 = getelementptr inbounds i8, i8* %0, i64 34
store i8 58, i8* %49
%50 = getelementptr inbounds i8, i8* %0, i64 35
%51 = getelementptr inbounds i8, i8* %1, i64 14
%52 = load i8, i8* %51
%53 = getelementptr inbounds i8, i8* %1, i64 15
%54 = load i8, i8* %53
%55 = tail call i32 @sprintf(i8* dereferenceable(1) %50, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 zeroext %52, i8 zeroext %54)
%56 = getelementptr inbounds i8, i8* %0, i64 39
store i8 0, i8* %56
ret i32 39
}