#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int const, int const,
                            int const, int const, int /*<<< orphan*/ const,
                            ...);
void stringify_net(char *buf, const uint8_t *addr, const uint16_t port,
                   const int v6) {
  memset(buf, 0, 45);
  if (v6)
    snprintf(buf, 45, "%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%hu",
             *(uint16_t *)(addr), *(uint16_t *)(addr + 2),
             *(uint16_t *)(addr + 4), *(uint16_t *)(addr + 6),
             *(uint16_t *)(addr + 8), *(uint16_t *)(addr + 10),
             *(uint16_t *)(addr + 12), *(uint16_t *)(addr + 14), port);
  else
    snprintf(buf, 45, "%u.%u.%u.%u:%hu", addr[0], addr[1], addr[2], addr[3],
             port);
}


x86 assembly (clang, -O0):
<stringify_net>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %edx,-0x2c(%rbp)
mov    %ecx,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x2d,%edx
call   1040 <memset@plt>
cmpl   $0x0,-0x30(%rbp)
je     11cc <stringify_net+0xac>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%r9d
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%r15d
mov    -0x28(%rbp),%rax
mov    0x20(%rax),%r14d
mov    -0x28(%rbp),%rax
mov    0x28(%rax),%ebx
mov    -0x28(%rbp),%rax
mov    0x30(%rax),%r11d
mov    -0x28(%rbp),%rax
mov    0x38(%rax),%r10d
mov    -0x2c(%rbp),%eax
mov    $0x2d,%esi
lea    0xe5b(%rip),%rdx
mov    %r15d,(%rsp)
mov    %r14d,0x8(%rsp)
mov    %ebx,0x10(%rsp)
mov    %r11d,0x18(%rsp)
mov    %r10d,0x20(%rsp)
mov    %eax,0x28(%rsp)
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    120c <stringify_net+0xec>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%r10d
mov    -0x2c(%rbp),%eax
mov    $0x2d,%esi
lea    0xe37(%rip),%rdx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1030 <snprintf@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringify_net>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %esi,%esi
mov    $0x2d,%edx
call   1040 <memset@plt>
mov    (%rbx),%ecx
test   %ebp,%ebp
je     1185 <stringify_net+0x65>
mov    0x8(%rbx),%r8d
mov    0x10(%rbx),%r9d
mov    0x18(%rbx),%r10d
mov    0x20(%rbx),%r11d
mov    0x28(%rbx),%r12d
mov    0x30(%rbx),%ebp
mov    0x38(%rbx),%ebx
lea    0xe9a(%rip),%rdx
mov    %r15,%rdi
mov    $0x2d,%esi
xor    %eax,%eax
push   %r14
push   %rbx
push   %rbp
push   %r12
push   %r11
push   %r10
call   1030 <snprintf@plt>
add    $0x30,%rsp
jmp    11ad <stringify_net+0x8d>
mov    0x4(%rbx),%r8d
mov    0x8(%rbx),%r9d
mov    0xc(%rbx),%ebp
lea    0xe9d(%rip),%rdx
mov    %r15,%rdi
mov    $0x2d,%esi
xor    %eax,%eax
push   %r14
push   %rbp
call   1030 <snprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%hu\00"
@.str.1 = [16 x i8] c"%u.%u.%u.%u:%hu\00"
define void @stringify_net(i8* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i8*, i8** %5
%10 = call i32 @memset(i8* %9, i32 0, i32 45)
%11 = load i32, i32* %8
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %40
13: ; preds = %4
%14 = load i8*, i8** %5
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = load i32*, i32** %6
%18 = getelementptr inbounds i32, i32* %17, i64 2
%19 = load i32, i32* %18
%20 = load i32*, i32** %6
%21 = getelementptr inbounds i32, i32* %20, i64 4
%22 = load i32, i32* %21
%23 = load i32*, i32** %6
%24 = getelementptr inbounds i32, i32* %23, i64 6
%25 = load i32, i32* %24
%26 = load i32*, i32** %6
%27 = getelementptr inbounds i32, i32* %26, i64 8
%28 = load i32, i32* %27
%29 = load i32*, i32** %6
%30 = getelementptr inbounds i32, i32* %29, i64 10
%31 = load i32, i32* %30
%32 = load i32*, i32** %6
%33 = getelementptr inbounds i32, i32* %32, i64 12
%34 = load i32, i32* %33
%35 = load i32*, i32** %6
%36 = getelementptr inbounds i32, i32* %35, i64 14
%37 = load i32, i32* %36
%38 = load i32, i32* %7
%39 = call i32 (i8*, i32, i8*, i32, i32, i32, i32, i32, ...) @snprintf(i8* %14, i32 45, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %19, i32 %22, i32 %25, i32 %28, i32 %31, i32 %34, i32 %37, i32 %38)
br label %56
40: ; preds = %4
%41 = load i8*, i8** %5
%42 = load i32*, i32** %6
%43 = getelementptr inbounds i32, i32* %42, i64 0
%44 = load i32, i32* %43
%45 = load i32*, i32** %6
%46 = getelementptr inbounds i32, i32* %45, i64 1
%47 = load i32, i32* %46
%48 = load i32*, i32** %6
%49 = getelementptr inbounds i32, i32* %48, i64 2
%50 = load i32, i32* %49
%51 = load i32*, i32** %6
%52 = getelementptr inbounds i32, i32* %51, i64 3
%53 = load i32, i32* %52
%54 = load i32, i32* %7
%55 = call i32 (i8*, i32, i8*, i32, i32, i32, i32, i32, ...) @snprintf(i8* %41, i32 45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %47, i32 %50, i32 %53, i32 %54)
br label %56
56: ; preds = %40, %13
ret void
}

LLVM IR (-O2):
@.str = [52 x i8] c"%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%hu\00"
@.str.1 = [16 x i8] c"%u.%u.%u.%u:%hu\00"
define void @stringify_net(i8* %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 @memset(i8* %0, i32 0, i32 45)
%6 = icmp eq i32 %3, 0
%7 = load i32, i32* %1
br i1 %6, label %24, label %8
8: ; preds = %4
%9 = getelementptr inbounds i32, i32* %1, i64 2
%10 = load i32, i32* %9
%11 = getelementptr inbounds i32, i32* %1, i64 4
%12 = load i32, i32* %11
%13 = getelementptr inbounds i32, i32* %1, i64 6
%14 = load i32, i32* %13
%15 = getelementptr inbounds i32, i32* %1, i64 8
%16 = load i32, i32* %15
%17 = getelementptr inbounds i32, i32* %1, i64 10
%18 = load i32, i32* %17
%19 = getelementptr inbounds i32, i32* %1, i64 12
%20 = load i32, i32* %19
%21 = getelementptr inbounds i32, i32* %1, i64 14
%22 = load i32, i32* %21
%23 = tail call i32 (i8*, i32, i8*, i32, i32, i32, i32, i32, ...) @snprintf(i8* %0, i32 45, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10, i32 %12, i32 %14, i32 %16, i32 %18, i32 %20, i32 %22, i32 %2)
br label %32
24: ; preds = %4
%25 = getelementptr inbounds i32, i32* %1, i64 1
%26 = load i32, i32* %25
%27 = getelementptr inbounds i32, i32* %1, i64 2
%28 = load i32, i32* %27
%29 = getelementptr inbounds i32, i32* %1, i64 3
%30 = load i32, i32* %29
%31 = tail call i32 (i8*, i32, i8*, i32, i32, i32, i32, i32, ...) @snprintf(i8* %0, i32 45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %26, i32 %28, i32 %30, i32 %2)
br label %32
32: ; preds = %24, %8
ret void
}