#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 {
  unsigned int *s6_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, struct in6_addr *, char *,
                             int);
char *strdup(char *);
char *printIPv6(unsigned char *ip) {
  char ipStr[INET6_ADDRSTRLEN];
  struct in6_addr ip6;
  int l;
  bzero(ipStr, INET6_ADDRSTRLEN);
  for (l = 0; l < 16; l++)
    ip6.s6_addr[l] = (unsigned int)ip[l];
  inet_ntop(AF_INET6, &ip6, ipStr, INET6_ADDRSTRLEN);
  return strdup(ipStr);
}


x86 assembly (clang, -O0):
<printIPv6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1040 <bzero@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    11ac <printIPv6+0x7c>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117d <printIPv6+0x4d>
mov    -0x30(%rbp),%rdx
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%rsi
call   1030 <inet_ntop@plt>
mov    -0x30(%rbp),%rdi
call   1050 <strdup@plt>
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
%struct.in6_addr = type { i32* }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i32 0
define i8* @printIPv6(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.in6_addr
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i32, i32* @INET6_ADDRSTRLEN
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
%11 = load i32, i32* @INET6_ADDRSTRLEN
%12 = call i32 @bzero(i8* %10, i32 %11)
store i32 0, i32* %6
br label %13
13: ; preds = %28, %1
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 16
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = load i8*, i8** %2
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%24 = load i32*, i32** %23
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
store i32 %22, i32* %27
br label %28
28: ; preds = %16
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %13
31: ; preds = %13
%32 = load i32, i32* @AF_INET6
%33 = load i32, i32* @INET6_ADDRSTRLEN
%34 = call i32 @inet_ntop(i32 %32, %struct.in6_addr* %5, i8* %10, i32 %33)
%35 = call i8* @strdup(i8* %10)
%36 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):