#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 sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ port;
typedef int /*<<< orphan*/ host;

/* Variables and functions */
int NI_MAXHOST;
int NI_MAXSERV;
int NI_NUMERICHOST;
int NI_NUMERICSERV;
scalar_t__ getnameinfo(struct sockaddr const *, int /*<<< orphan*/, char *, int,
                       char *, int, int);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *, char *);
char *_stringify_address2(const struct sockaddr *addr, socklen_t addr_len,
                          char *buffer, size_t buffer_size) {
  char host[NI_MAXHOST];
  char port[NI_MAXSERV];
  if (getnameinfo(addr, addr_len, host, sizeof(host), port, sizeof(port),
                  NI_NUMERICHOST | NI_NUMERICSERV)) {
    return "?.?.?.?:?";
  } else {
    snprintf(buffer, buffer_size, "%s:%s", host, port);
    return buffer;
  }
}


x86 assembly (clang, -O0):
<_stringify_address2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x30(%rbp)
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rdx
sub    %rax,%rdx
mov    %rdx,-0x58(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x38(%rbp)
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%r8
sub    %rsi,%r8
mov    %r8,-0x50(%rbp)
mov    %r8,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    %eax,%r9d
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    0x2e44(%rip),%r10
or     (%r10),%eax
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1040 <getnameinfo@plt>
add    $0x10,%rsp
cmp    $0x0,%rax
je     11d8 <_stringify_address2+0xb8>
lea    0xe38(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1203 <_stringify_address2+0xe3>
mov    -0x50(%rbp),%r8
mov    -0x58(%rbp),%rcx
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    0xe1b(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_stringify_address2>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    0x2e90(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%r12
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2e8b(%rip),%rax
mov    (%rax),%r9d
mov    %rsp,%rbx
mov    %r9,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e5d(%rip),%r8
mov    0x2e6e(%rip),%rdx
mov    (%rdx),%eax
or     (%r8),%eax
sub    $0x8,%rsp
mov    %r12,%rdx
mov    %rbx,%r8
push   %rax
call   1040 <getnameinfo@plt>
add    $0x10,%rsp
test   %rax,%rax
je     11a1 <_stringify_address2+0x81>
lea    0xe61(%rip),%r15
jmp    11b9 <_stringify_address2+0x99>
lea    0xe62(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rcx
mov    %rbx,%r8
call   1030 <snprintf@plt>
mov    %r15,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@.str = [10 x i8] c"?.?.?.?:?\00"
@.str.1 = [6 x i8] c"%s:%s\00"
define i8* @_stringify_address2(%struct.sockaddr* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca %struct.sockaddr*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%14 = load i32, i32* @NI_MAXHOST
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %10
%17 = alloca i8, i64 %15
store i64 %15, i64* %11
%18 = load i32, i32* @NI_MAXSERV
%19 = zext i32 %18 to i64
%20 = alloca i8, i64 %19
store i64 %19, i64* %12
%21 = load %struct.sockaddr*, %struct.sockaddr** %6
%22 = load i32, i32* %7
%23 = trunc i64 %15 to i32
%24 = trunc i64 %19 to i32
%25 = load i32, i32* @NI_NUMERICHOST
%26 = load i32, i32* @NI_NUMERICSERV
%27 = or i32 %25, %26
%28 = call i64 @getnameinfo(%struct.sockaddr* %21, i32 %22, i8* %17, i32 %23, i8* %20, i32 %24, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %4
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %5
store i32 1, i32* %13
br label %36
31: ; preds = %4
%32 = load i8*, i8** %8
%33 = load i64, i64* %9
%34 = call i32 @snprintf(i8* %32, i64 %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %20)
%35 = load i8*, i8** %8
store i8* %35, i8** %5
store i32 1, i32* %13
br label %36
36: ; preds = %31, %30
%37 = load i8*, i8** %10
%38 = load i8*, i8** %5
ret i8* %38
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@.str = [10 x i8] c"?.?.?.?:?\00"
@.str.1 = [6 x i8] c"%s:%s\00"
define i8* @_stringify_address2(%struct.sockaddr* %0, i32 %1, i8* %2, i64 %3) {
%5 = load i32, i32* @NI_MAXHOST
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = load i32, i32* @NI_MAXSERV
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = load i32, i32* @NI_NUMERICHOST
%12 = load i32, i32* @NI_NUMERICSERV
%13 = or i32 %12, %11
%14 = call i64 @getnameinfo(%struct.sockaddr* %0, i32 %1, i8* %7, i32 %5, i8* %10, i32 %8, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = call i32 @snprintf(i8* %2, i64 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %10)
br label %18
18: ; preds = %4, %16
%19 = phi i8* [ %2, %16 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %4 ]
ret i8* %19
}