#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 /*<<< orphan*/ *s6_addr;
};
typedef int /*<<< orphan*/ sa_family_t;

/* Variables and functions */
int /*<<< orphan*/ INET6_ADDRSTRLEN;
char *calloc(int, int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, struct in6_addr *, char *,
                             int /*<<< orphan*/);
int sscanf(char *, char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
char *ipHexToPres(sa_family_t fam, char *ipHex) {
  struct in6_addr ip;
  char *ipPres = NULL;
  int n = sscanf(ipHex,
                 "%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%"
                 "2hhx%2hhx%2hhx%2hhx",
                 &ip.s6_addr[3], &ip.s6_addr[2], &ip.s6_addr[1], &ip.s6_addr[0],
                 &ip.s6_addr[7], &ip.s6_addr[6], &ip.s6_addr[5], &ip.s6_addr[4],
                 &ip.s6_addr[11], &ip.s6_addr[10], &ip.s6_addr[9],
                 &ip.s6_addr[8], &ip.s6_addr[15], &ip.s6_addr[14],
                 &ip.s6_addr[13], &ip.s6_addr[12]);
  if (n == 4 || n == 16) {
    ipPres = calloc(1, INET6_ADDRSTRLEN);
    inet_ntop(fam, &ip, ipPres, INET6_ADDRSTRLEN);
  }
  return ipPres;
}


x86 assembly (clang, -O0):
<ipHexToPres>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %edi,-0x2c(%rbp)
mov    %rsi,-0x38(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rdx
add    $0xc,%rdx
mov    -0x40(%rbp),%rcx
add    $0x8,%rcx
mov    -0x40(%rbp),%r8
add    $0x4,%r8
mov    -0x40(%rbp),%r9
mov    -0x40(%rbp),%rax
add    $0x1c,%rax
mov    -0x40(%rbp),%rsi
add    $0x18,%rsi
mov    %rsi,-0x70(%rbp)
mov    -0x40(%rbp),%rsi
add    $0x14,%rsi
mov    %rsi,-0x68(%rbp)
mov    -0x40(%rbp),%rsi
add    $0x10,%rsi
mov    %rsi,-0x60(%rbp)
mov    -0x40(%rbp),%r13
add    $0x2c,%r13
mov    -0x40(%rbp),%r12
add    $0x28,%r12
mov    -0x40(%rbp),%r15
add    $0x24,%r15
mov    -0x40(%rbp),%r14
add    $0x20,%r14
mov    -0x40(%rbp),%rbx
add    $0x3c,%rbx
mov    -0x40(%rbp),%r11
add    $0x38,%r11
mov    -0x40(%rbp),%r10
add    $0x34,%r10
mov    -0x40(%rbp),%rsi
add    $0x30,%rsi
mov    %rsi,-0x58(%rbp)
lea    0xe16(%rip),%rsi
mov    %rax,(%rsp)
mov    -0x70(%rbp),%rax
mov    %rax,0x8(%rsp)
mov    -0x68(%rbp),%rax
mov    %rax,0x10(%rsp)
mov    -0x60(%rbp),%rax
mov    %rax,0x18(%rsp)
mov    -0x58(%rbp),%rax
mov    %r13,0x20(%rsp)
mov    %r12,0x28(%rsp)
mov    %r15,0x30(%rsp)
mov    %r14,0x38(%rsp)
mov    %rbx,0x40(%rsp)
mov    %r11,0x48(%rsp)
mov    %r10,0x50(%rsp)
mov    %rax,0x58(%rsp)
call   1050 <sscanf@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x4,-0x4c(%rbp)
je     1251 <ipHexToPres+0x121>
cmpl   $0x10,-0x4c(%rbp)
jne    1281 <ipHexToPres+0x151>
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    0x2d72(%rip),%rax
mov    (%rax),%ecx
lea    -0x40(%rbp),%rsi
call   1030 <inet_ntop@plt>
mov    -0x48(%rbp),%rax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipHexToPres>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%rax
mov    %edi,%r14d
lea    0xebb(%rip),%rsi
mov    %rax,%rdi
call   1050 <sscanf@plt>
cmp    $0x10,%eax
je     1157 <ipHexToPres+0x27>
cmp    $0x4,%eax
jne    1183 <ipHexToPres+0x53>
mov    0x2e8a(%rip),%rax
mov    (%rax),%ebp
mov    $0x1,%edi
mov    %ebp,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
lea    0x68(%rsp),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
mov    %ebp,%ecx
call   1030 <inet_ntop@plt>
jmp    1185 <ipHexToPres+0x55>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32* }
@.str = [81 x i8] c"%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx\00"
@INET6_ADDRSTRLEN = global i32 0
define i8* @ipHexToPres(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.in6_addr
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i8* null, i8** %6
%8 = load i8*, i8** %4
%9 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%10 = load i32*, i32** %9
%11 = getelementptr inbounds i32, i32* %10, i64 3
%12 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%13 = load i32*, i32** %12
%14 = getelementptr inbounds i32, i32* %13, i64 2
%15 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%16 = load i32*, i32** %15
%17 = getelementptr inbounds i32, i32* %16, i64 1
%18 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%19 = load i32*, i32** %18
%20 = getelementptr inbounds i32, i32* %19, i64 0
%21 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%22 = load i32*, i32** %21
%23 = getelementptr inbounds i32, i32* %22, i64 7
%24 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 6
%27 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%28 = load i32*, i32** %27
%29 = getelementptr inbounds i32, i32* %28, i64 5
%30 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%31 = load i32*, i32** %30
%32 = getelementptr inbounds i32, i32* %31, i64 4
%33 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%34 = load i32*, i32** %33
%35 = getelementptr inbounds i32, i32* %34, i64 11
%36 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%37 = load i32*, i32** %36
%38 = getelementptr inbounds i32, i32* %37, i64 10
%39 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%40 = load i32*, i32** %39
%41 = getelementptr inbounds i32, i32* %40, i64 9
%42 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%43 = load i32*, i32** %42
%44 = getelementptr inbounds i32, i32* %43, i64 8
%45 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%46 = load i32*, i32** %45
%47 = getelementptr inbounds i32, i32* %46, i64 15
%48 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%49 = load i32*, i32** %48
%50 = getelementptr inbounds i32, i32* %49, i64 14
%51 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%52 = load i32*, i32** %51
%53 = getelementptr inbounds i32, i32* %52, i64 13
%54 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%55 = load i32*, i32** %54
%56 = getelementptr inbounds i32, i32* %55, i64 12
%57 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0), i32* %11, i32* %14, i32* %17, i32* %20, i32* %23, i32* %26, i32* %29, i32* %32, i32* %35, i32* %38, i32* %41, i32* %44, i32* %47, i32* %50, i32* %53, i32* %56)
store i32 %57, i32* %7
%58 = load i32, i32* %7
%59 = icmp eq i32 %58, 4
br i1 %59, label %63, label %60
60: ; preds = %2
%61 = load i32, i32* %7
%62 = icmp eq i32 %61, 16
br i1 %62, label %63, label %70
63: ; preds = %60, %2
%64 = load i32, i32* @INET6_ADDRSTRLEN
%65 = call i8* @calloc(i32 1, i32 %64)
store i8* %65, i8** %6
%66 = load i32, i32* %3
%67 = load i8*, i8** %6
%68 = load i32, i32* @INET6_ADDRSTRLEN
%69 = call i32 @inet_ntop(i32 %66, %struct.in6_addr* %5, i8* %67, i32 %68)
br label %70
70: ; preds = %63, %60
%71 = load i8*, i8** %6
ret i8* %71
}

LLVM IR (-O2):
%struct.in6_addr = type { i32* }
@.str = [81 x i8] c"%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx\00"
@INET6_ADDRSTRLEN = global i32 0
define i8* @ipHexToPres(i32 %0, i8* nocapture %1) {
%3 = alloca %struct.in6_addr
%4 = bitcast %struct.in6_addr* %3 to i8*
%5 = tail call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0), i32* poison, i32* poison, i32* poison, i32* undef, i32* poison, i32* poison, i32* poison, i32* poison, i32* poison, i32* poison, i32* poison, i32* poison, i32* poison, i32* poison, i32* poison, i32* poison)
switch i32 %5, label %10 [
i32 16, label %6
i32 4, label %6
]
6: ; preds = %2, %2
%7 = load i32, i32* @INET6_ADDRSTRLEN
%8 = tail call i8* @calloc(i32 1, i32 %7)
%9 = call i32 @inet_ntop(i32 %0, %struct.in6_addr* %3, i8* %8, i32 %7)
br label %10
10: ; preds = %2, %6
%11 = phi i8* [ %8, %6 ], [ null, %2 ]
ret i8* %11
}