#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 /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int sa_family;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ abort();
scalar_t__ inet_ntop(int, void *, char *, int);
char *addr2char_r(struct sockaddr *ia, char *buf, int size) {
  void *addr;
  switch (ia->sa_family) {
  case AF_INET:
    addr = &(((struct sockaddr_in *)(ia))->sin_addr);
    break;
  case AF_INET6:
    addr = &(((struct sockaddr_in6 *)(ia))->sin6_addr);
    break;
  default:
    abort();
  }
  return (char *)((void *)inet_ntop(ia->sa_family, addr, buf, size));
}


x86 assembly (clang, -O0):
<addr2char_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x80,%eax
je     116c <addr2char_r+0x4c>
jmp    114c <addr2char_r+0x2c>
mov    -0x24(%rbp),%eax
sub    $0x81,%eax
jne    1179 <addr2char_r+0x59>
jmp    115f <addr2char_r+0x3f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1180 <addr2char_r+0x60>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1180 <addr2char_r+0x60>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1030 <inet_ntop@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addr2char_r>:
push   %rax
mov    %edx,%ecx
mov    %rsi,%rdx
mov    %rdi,%rsi
mov    (%rdi),%edi
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x80,%eax
jne    113d <addr2char_r+0x1d>
pop    %rax
jmp    1030 <inet_ntop@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
define i8* @addr2char_r(%struct.sockaddr* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store %struct.sockaddr* %0, %struct.sockaddr** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%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 %21 [
i32 129, label %11
i32 128, label %16
]
11: ; preds = %3
%12 = load %struct.sockaddr*, %struct.sockaddr** %4
%13 = bitcast %struct.sockaddr* %12 to %struct.sockaddr_in*
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%15 = bitcast i32* %14 to i8*
store i8* %15, i8** %7
br label %23
16: ; preds = %3
%17 = load %struct.sockaddr*, %struct.sockaddr** %4
%18 = bitcast %struct.sockaddr* %17 to %struct.sockaddr_in6*
%19 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %18, i32 0, i32 0
%20 = bitcast i32* %19 to i8*
store i8* %20, i8** %7
br label %23
21: ; preds = %3
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %16, %11
%24 = load %struct.sockaddr*, %struct.sockaddr** %4
%25 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i8*, i8** %7
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = call i64 @inet_ntop(i32 %26, i8* %27, i8* %28, i32 %29)
%31 = inttoptr i64 %30 to i8*
ret i8* %31
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
define i8* @addr2char_r(%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
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %3
%11 = bitcast %struct.sockaddr* %0 to i8*
%12 = tail call i64 @inet_ntop(i32 %5, i8* %11, i8* %1, i32 %2)
%13 = inttoptr i64 %12 to i8*
ret i8* %13
}