#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 addrinfo {
  int /*<<< orphan*/ ai_flags;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned short);
int /*<<< orphan*/ stderr;
struct addrinfo *getLocalAddressInfo(unsigned short port) {
  int addrErr;
  char portString[6];
  struct addrinfo hint, *localInfo = NULL;
  memset(&hint, 0, sizeof(struct addrinfo));
  hint.ai_family = AF_UNSPEC;
  hint.ai_socktype = SOCK_STREAM;
  hint.ai_flags = AI_PASSIVE;
  sprintf(portString, "%d", port);
  addrErr = getaddrinfo(NULL, portString, &hint, &localInfo);
  if (addrErr) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(addrErr));
    return NULL;
  } else {
    return localInfo;
  }
}


x86 assembly (clang, -O0):
<getLocalAddressInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %di,%ax
mov    %ax,-0xa(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    -0x16(%rbp),%rdi
lea    0xe5a(%rip),%rsi
movzwl -0xa(%rbp),%edx
call   1060 <sprintf@plt>
lea    -0x16(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1070 <getaddrinfo@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1204 <getLocalAddressInfo+0xb4>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe11(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    120c <getLocalAddressInfo+0xbc>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLocalAddressInfo>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebp
movq   $0x0,(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xe5c(%rip),%rsi
lea    0x1a(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    %rsp,%rcx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <getaddrinfo@plt>
test   %eax,%eax
je     11ec <getLocalAddressInfo+0x9c>
mov    0x2e02(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe25(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
jmp    11f0 <getLocalAddressInfo+0xa0>
mov    (%rsp),%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
define %struct.addrinfo* @getLocalAddressInfo(i16 zeroext %0) {
%2 = alloca %struct.addrinfo*
%3 = alloca i16
%4 = alloca i32
%5 = alloca [6 x i8]
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
store i16 %0, i16* %3
store %struct.addrinfo* null, %struct.addrinfo** %7
%8 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 12)
%9 = load i32, i32* @AF_UNSPEC
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* @SOCK_STREAM
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @AI_PASSIVE
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 0
store i32 %13, i32* %14
%15 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%16 = load i16, i16* %3
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i16 zeroext %16)
%18 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%19 = call i32 @getaddrinfo(i32* null, i8* %18, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %1
%23 = load i32, i32* @stderr
%24 = load i32, i32* %4
%25 = call i8* @gai_strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store %struct.addrinfo* null, %struct.addrinfo** %2
br label %29
27: ; preds = %1
%28 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %28, %struct.addrinfo** %2
br label %29
29: ; preds = %27, %22
%30 = load %struct.addrinfo*, %struct.addrinfo** %2
ret %struct.addrinfo* %30
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
define %struct.addrinfo* @getLocalAddressInfo(i16 zeroext %0) {
%2 = alloca [6 x i8]
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %4
%8 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 12)
%9 = load i32, i32* @AF_UNSPEC
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* @SOCK_STREAM
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @AI_PASSIVE
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i32 %13, i32* %14
%15 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i16 zeroext %0)
%16 = call i32 @getaddrinfo(i32* null, i8* %5, %struct.addrinfo* %3, %struct.addrinfo** %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %1
%19 = load i32, i32* @stderr
%20 = call i8* @gai_strerror(i32 %16)
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %24
22: ; preds = %1
%23 = load %struct.addrinfo*, %struct.addrinfo** %4
br label %24
24: ; preds = %22, %18
%25 = phi %struct.addrinfo* [ null, %18 ], [ %23, %22 ]
ret %struct.addrinfo* %25
}