#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);
char *gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ printf(char *, ...);
struct addrinfo *createAddressInfo(const char *address, const char *port) {
  printf("Creating address info for %s:%s\n", address, 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) {
    printf("Error creating address for %s: %s", port, gai_strerror(n));
    return NULL;
  }
  printf("Successfully created address info.\n");
  return res;
}


x86 assembly (clang, -O0):
<createAddressInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
call   1050 <bzero@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e21(%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   1060 <getaddrinfo@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11f7 <createAddressInfo+0xb7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    120d <createAddressInfo+0xcd>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
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    0xe9a(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0x10,%esi
call   1060 <bzero@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0x18(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <getaddrinfo@plt>
test   %eax,%eax
je     11ef <createAddressInfo+0x9f>
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xe43(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1200 <createAddressInfo+0xb0>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    0x18(%rsp),%rbx
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32 }
@.str = [33 x i8] c"Creating address info for %s:%s\0A\00"
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [34 x i8] c"Error creating address for %s: %s\00"
@.str.2 = [36 x i8] c"Successfully created address info.\0A\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 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10)
%12 = call i32 @bzero(%struct.addrinfo* %7, i32 16)
%13 = load i32, i32* @AI_PASSIVE
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 3
store i32 %13, i32* %14
%15 = load i32, i32* @AF_UNSPEC
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 2
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_DGRAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @IPPROTO_UDP
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = call i32 @getaddrinfo(i8* %21, i8* %22, %struct.addrinfo* %7, %struct.addrinfo** %8)
store i32 %23, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %2
%26 = load i8*, i8** %5
%27 = load i32, i32* %6
%28 = call i8* @gai_strerror(i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %26, i8* %28)
store %struct.addrinfo* null, %struct.addrinfo** %3
br label %33
30: ; preds = %2
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%32 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %32, %struct.addrinfo** %3
br label %33
33: ; preds = %30, %25
%34 = load %struct.addrinfo*, %struct.addrinfo** %3
ret %struct.addrinfo* %34
}

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