#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 dummy;
};
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int sa_family;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ NI_NUMERICHOST;
int getnameinfo(struct sockaddr const *, int, char *, int, int /*<<< orphan*/ *,
                int /*<<< orphan*/, int /*<<< orphan*/);
int fetch_address(const struct sockaddr *sa, char *s, int size) {
  int inf_size = -1;
  switch (sa->sa_family) {
  case AF_INET:
    inf_size = sizeof(struct sockaddr_in);
    break;
  case AF_INET6:
    inf_size = sizeof(struct sockaddr_in6);
    break;
  }
  return getnameinfo(sa, inf_size, s, size, NULL, 0, NI_NUMERICHOST);
}


x86 assembly (clang, -O0):
<fetch_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x80,%eax
je     1162 <fetch_address+0x52>
jmp    1143 <fetch_address+0x33>
mov    -0x1c(%rbp),%eax
sub    $0x81,%eax
jne    1169 <fetch_address+0x59>
jmp    1156 <fetch_address+0x46>
movl   $0x4,-0x18(%rbp)
jmp    1169 <fetch_address+0x59>
movl   $0x4,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
xor    %r8d,%r8d
xor    %r9d,%r9d
mov    %eax,(%rsp)
call   1030 <getnameinfo@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fetch_address>:
push   %rax
mov    %edx,%ecx
mov    %rsi,%rdx
mov    (%rdi),%eax
and    $0xfffffffe,%eax
xor    %esi,%esi
cmp    $0x80,%eax
sete   %sil
lea    (%rsi,%rsi,4),%esi
add    $0xffffffff,%esi
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <getnameinfo@plt>
pop    %rcx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@NI_NUMERICHOST = global i32 0
define i32 @fetch_address(%struct.sockaddr* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 -1, i32* %7
%8 = load %struct.sockaddr*, %struct.sockaddr** %4
%9 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %8, i32 0, i32 0
%10 = load i32, i32* %9
switch i32 %10, label %13 [
i32 129, label %11
i32 128, label %12
]
11: ; preds = %3
store i32 4, i32* %7
br label %13
12: ; preds = %3
store i32 4, i32* %7
br label %13
13: ; preds = %3, %12, %11
%14 = load %struct.sockaddr*, %struct.sockaddr** %4
%15 = load i32, i32* %7
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = load i32, i32* @NI_NUMERICHOST
%19 = call i32 @getnameinfo(%struct.sockaddr* %14, i32 %15, i8* %16, i32 %17, i32* null, i32 0, i32 %18)
ret i32 %19
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@NI_NUMERICHOST = global i32 0
define i32 @fetch_address(%struct.sockaddr* %0, i8* %1, i32 %2) {
%4 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = and i32 %5, -2
%7 = icmp eq i32 %6, 128
%8 = select i1 %7, i32 4, i32 -1
%9 = load i32, i32* @NI_NUMERICHOST
%10 = tail call i32 @getnameinfo(%struct.sockaddr* %0, i32 %8, i8* %1, i32 %2, i32* null, i32 0, i32 %9)
ret i32 %10
}