#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_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  scalar_t__ ai_family;
  scalar_t__ ai_addr;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ *inet_ntop(scalar_t__, void const *, char *, size_t);
char *socket_str_address_info(char *buffer, size_t n,
                              const struct addrinfo *info) {
  const void *addr;
  if (info->ai_family == AF_INET)
    addr = &((const struct sockaddr_in *)info->ai_addr)->sin_addr;
  else
    addr = &((const struct sockaddr_in6 *)info->ai_addr)->sin6_addr;
  if (inet_ntop(info->ai_family, addr, buffer, n) == NULL)
    return (NULL);
  return (buffer);
}


x86 assembly (clang, -O0):
<socket_str_address_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2eb6(%rip),%rcx
cmp    (%rcx),%rax
jne    114c <socket_str_address_info+0x3c>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1158 <socket_str_address_info+0x48>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    1187 <socket_str_address_info+0x77>
movq   $0x0,-0x8(%rbp)
jmp    118f <socket_str_address_info+0x7f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_str_address_info>:
push   %rbx
mov    %rsi,%rcx
mov    %rdi,%rbx
mov    (%rdx),%rdi
mov    0x8(%rdx),%rsi
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
test   %rax,%rax
cmovne %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, i64 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET = global i64 0
define i8* @socket_str_address_info(i8* %0, i64 %1, %struct.addrinfo* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.addrinfo*
%8 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store %struct.addrinfo* %2, %struct.addrinfo** %7
%9 = load %struct.addrinfo*, %struct.addrinfo** %7
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @AF_INET
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %21
14: ; preds = %3
%15 = load %struct.addrinfo*, %struct.addrinfo** %7
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to %struct.sockaddr_in*
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
%20 = bitcast i32* %19 to i8*
store i8* %20, i8** %8
br label %28
21: ; preds = %3
%22 = load %struct.addrinfo*, %struct.addrinfo** %7
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i32 0, i32 1
%24 = load i64, i64* %23
%25 = inttoptr i64 %24 to %struct.sockaddr_in6*
%26 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %25, i32 0, i32 0
%27 = bitcast i32* %26 to i8*
store i8* %27, i8** %8
br label %28
28: ; preds = %21, %14
%29 = load %struct.addrinfo*, %struct.addrinfo** %7
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i32 0, i32 0
%31 = load i64, i64* %30
%32 = load i8*, i8** %8
%33 = load i8*, i8** %5
%34 = load i64, i64* %6
%35 = call i32* @inet_ntop(i64 %31, i8* %32, i8* %33, i64 %34)
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %38
37: ; preds = %28
store i8* null, i8** %4
br label %40
38: ; preds = %28
%39 = load i8*, i8** %5
store i8* %39, i8** %4
br label %40
40: ; preds = %38, %37
%41 = load i8*, i8** %4
ret i8* %41
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i64 }
@AF_INET = global i64 0
define i8* @socket_str_address_info(i8* %0, i64 %1, %struct.addrinfo* nocapture %2) {
%4 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 0
%5 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 1
%6 = load i64, i64* %5
%7 = inttoptr i64 %6 to i8*
%8 = load i64, i64* %4
%9 = tail call i32* @inet_ntop(i64 %8, i8* %7, i8* %0, i64 %1)
%10 = icmp eq i32* %9, null
%11 = select i1 %10, i8* null, i8* %0
ret i8* %11
}