#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;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  struct sockaddr *ai_addr;
  int /*<<< orphan*/ *ai_next;
  int /*<<< orphan*/ *ai_canonname;
  int /*<<< orphan*/ ai_flags;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int process_address(struct sockaddr **addr, socklen_t *len, char *hostname,
                    char *port) {
  struct addrinfo hints;
  struct addrinfo *result = NULL;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_protocol = 0;
  hints.ai_flags = AI_PASSIVE;
  hints.ai_canonname = NULL;
  hints.ai_addr = NULL;
  hints.ai_next = NULL;
  int ai = -1;
  if ((ai = getaddrinfo(hostname, port, &hints, &result)) != 0) {
    fprintf(stderr, "Error getting address info: %s\n", gai_strerror(ai));
    exit(2);
  }
  *addr = result->ai_addr;
  *len = result->ai_addrlen;
  return 0;
}


x86 assembly (clang, -O0):
<process_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x60(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0xffffffff,-0x64(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x60(%rbp),%rcx
call   1070 <getaddrinfo@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
je     121c <process_address+0xcc>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    -0x64(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xdf3(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    -0x60(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x60(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_address>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
movq   $0x0,(%rsp)
lea    0x8(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x3c(%rsp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
movq   $0x0,0x30(%rsp)
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <getaddrinfo@plt>
test   %eax,%eax
jne    11fb <process_address+0xab>
mov    (%rsp),%rax
mov    0x8(%rax),%rcx
mov    %rcx,(%r15)
mov    (%rax),%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2dc6(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xdee(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.addrinfo = type { i32, %struct.sockaddr*, i32*, i32*, i32, i64, i32, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Error getting address info: %s\0A\00"
define i32 @process_address(%struct.sockaddr** %0, i32* %1, i8* %2, i8* %3) {
%5 = alloca %struct.sockaddr**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.addrinfo
%10 = alloca %struct.addrinfo*
%11 = alloca i32
store %struct.sockaddr** %0, %struct.sockaddr*** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store %struct.addrinfo* null, %struct.addrinfo** %10
%12 = call i32 @memset(%struct.addrinfo* %9, i32 0, i32 56)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 7
store i32 %13, i32* %14
%15 = load i32, i32* @SOCK_DGRAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 6
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 5
store i64 0, i64* %17
%18 = load i32, i32* @AI_PASSIVE
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 4
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 3
store i32* null, i32** %20
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 1
store %struct.sockaddr* null, %struct.sockaddr** %21
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 2
store i32* null, i32** %22
store i32 -1, i32* %11
%23 = load i8*, i8** %7
%24 = load i8*, i8** %8
%25 = call i32 @getaddrinfo(i8* %23, i8* %24, %struct.addrinfo* %9, %struct.addrinfo** %10)
store i32 %25, i32* %11
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %4
%28 = load i32, i32* @stderr
%29 = load i32, i32* %11
%30 = call i8* @gai_strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %4
%34 = load %struct.addrinfo*, %struct.addrinfo** %10
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 1
%36 = load %struct.sockaddr*, %struct.sockaddr** %35
%37 = load %struct.sockaddr**, %struct.sockaddr*** %5
store %struct.sockaddr* %36, %struct.sockaddr** %37
%38 = load %struct.addrinfo*, %struct.addrinfo** %10
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = load i32*, i32** %6
store i32 %40, i32* %41
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.addrinfo = type { i32, %struct.sockaddr*, i32*, i32*, i32, i64, i32, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Error getting address info: %s\0A\00"
define i32 @process_address(%struct.sockaddr** nocapture writeonly %0, i32* nocapture writeonly %1, i8* %2, i8* %3) {
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = bitcast %struct.addrinfo* %5 to i8*
%8 = bitcast %struct.addrinfo** %6 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %6
%9 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 56)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 7
store i32 %10, i32* %11
%12 = load i32, i32* @SOCK_DGRAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 6
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 5
store i64 0, i64* %14
%15 = load i32, i32* @AI_PASSIVE
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 1
%18 = bitcast %struct.sockaddr** %17 to i8*
%19 = call i32 @getaddrinfo(i8* %2, i8* %3, %struct.addrinfo* %5, %struct.addrinfo** %6)
%20 = icmp eq i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %4
%22 = load i32, i32* @stderr
%23 = call i8* @gai_strerror(i32 %19)
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 2)
unreachable
26: ; preds = %4
%27 = load %struct.addrinfo*, %struct.addrinfo** %6
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i64 0, i32 1
%29 = load %struct.sockaddr*, %struct.sockaddr** %28
store %struct.sockaddr* %29, %struct.sockaddr** %0
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i64 0, i32 0
%31 = load i32, i32* %30
store i32 %31, i32* %1
ret i32 0
}