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

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct addrinfo *, int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ perror(char *);
struct addrinfo *createAddressInfo(const char *address, const char *port) {
  int n;
  struct addrinfo hints, *res;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_flags = AI_PASSIVE;
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_protocol = IPPROTO_UDP;
  if ((n = getaddrinfo(address, port, &hints, &res)) != 0) {
    perror("Error creating address");
    return NULL;
  }
  return res;
}


x86 assembly (clang, -O0):
<createAddressInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
call   1040 <bzero@plt>
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1050 <getaddrinfo@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11b8 <createAddressInfo+0x88>
lea    0xe5a(%rip),%rdi
call   1030 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c0 <createAddressInfo+0x90>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createAddressInfo>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0x10,%esi
call   1040 <bzero@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0x18(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <getaddrinfo@plt>
test   %eax,%eax
jne    11ab <createAddressInfo+0x7b>
mov    0x18(%rsp),%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe4e(%rip),%rdi
call   1030 <perror@plt>
xor    %eax,%eax
jmp    11a1 <createAddressInfo+0x71>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [23 x i8] c"Error creating address\00"
define %struct.addrinfo* @createAddressInfo(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.addrinfo
%8 = alloca %struct.addrinfo*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = call i32 @bzero(%struct.addrinfo* %7, i32 16)
%10 = load i32, i32* @AI_PASSIVE
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 3
store i32 %10, i32* %11
%12 = load i32, i32* @AF_UNSPEC
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 2
store i32 %12, i32* %13
%14 = load i32, i32* @SOCK_DGRAM
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* @IPPROTO_UDP
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i8*, i8** %4
%19 = load i8*, i8** %5
%20 = call i32 @getaddrinfo(i8* %18, i8* %19, %struct.addrinfo* %7, %struct.addrinfo** %8)
store i32 %20, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store %struct.addrinfo* null, %struct.addrinfo** %3
br label %26
24: ; preds = %2
%25 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %25, %struct.addrinfo** %3
br label %26
26: ; preds = %24, %22
%27 = load %struct.addrinfo*, %struct.addrinfo** %3
ret %struct.addrinfo* %27
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [23 x i8] c"Error creating address\00"
define %struct.addrinfo* @createAddressInfo(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = call i32 @bzero(%struct.addrinfo* %3, i32 16)
%8 = load i32, i32* @AI_PASSIVE
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %8, i32* %9
%10 = load i32, i32* @AF_UNSPEC
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @SOCK_DGRAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @IPPROTO_UDP
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i32 %14, i32* %15
%16 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %3, %struct.addrinfo** %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %22
20: ; preds = %2
%21 = load %struct.addrinfo*, %struct.addrinfo** %4
br label %22
22: ; preds = %20, %18
%23 = phi %struct.addrinfo* [ null, %18 ], [ %21, %20 ]
ret %struct.addrinfo* %23
}