#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 */
typedef int /*<<< orphan*/ u_char;
struct in_addr {
  scalar_t__ s_addr;
};
struct in6_addr {
  int dummy;
};

/* Variables and functions */
int AF_INET;
int AF_INET6;
scalar_t__ INADDR_NONE;
int /*<<< orphan*/ errx(int, char *);
scalar_t__ inet_addr(char const *);
int /*<<< orphan*/ inet_pton(int, char const *, struct in6_addr *);
int packadrinfo(int af, u_char *adrspace, const char *str) {
  union {
    struct in6_addr *in6;
    struct in_addr *in;
  } adu;
  if (af == AF_INET6) {
    adu.in6 = (struct in6_addr *)adrspace;
    inet_pton(AF_INET6, str, adu.in6);
  }
  if (af == AF_INET) {
    adu.in = (struct in_addr *)adrspace;
    adu.in->s_addr = inet_addr(str);
    if (adu.in->s_addr == INADDR_NONE)
      errx(1, "invalid address specification");
  }
  return (0);
}


x86 assembly (clang, -O0):
<packadrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e8b(%rip),%rcx
cmp    (%rcx),%eax
jne    1173 <packadrinfo+0x43>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <inet_pton@plt>
mov    -0x4(%rbp),%eax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%eax
jne    11cd <packadrinfo+0x9d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
jne    11c8 <packadrinfo+0x98>
mov    $0x1,%edi
lea    0xe3d(%rip),%rsi
call   1030 <errx@plt>
jmp    11cd <packadrinfo+0x9d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packadrinfo>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e95(%rip),%rax
cmp    %edi,(%rax)
jne    1154 <packadrinfo+0x24>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <inet_pton@plt>
mov    0x2e8d(%rip),%rax
cmp    %ebp,(%rax)
jne    1187 <packadrinfo+0x57>
mov    %rbx,%rdi
call   1040 <inet_addr@plt>
mov    %rax,(%r14)
mov    0x2e6f(%rip),%rcx
cmp    (%rcx),%rax
jne    1187 <packadrinfo+0x57>
lea    0xe83(%rip),%rsi
mov    $0x1,%edi
call   1030 <errx@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%union.anon = type { %struct.in6_addr* }
%struct.in6_addr = type { i32 }
%struct.in_addr = type { i64 }
@AF_INET6 = global i32 0
@AF_INET = global i32 0
@INADDR_NONE = global i64 0
@.str = [30 x i8] c"invalid address specification\00"
define i32 @packadrinfo(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca %union.anon
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%8 = load i32, i32* %4
%9 = load i32, i32* @AF_INET6
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %20
11: ; preds = %3
%12 = load i32*, i32** %5
%13 = bitcast i32* %12 to %struct.in6_addr*
%14 = bitcast %union.anon* %7 to %struct.in6_addr**
store %struct.in6_addr* %13, %struct.in6_addr** %14
%15 = load i32, i32* @AF_INET6
%16 = load i8*, i8** %6
%17 = bitcast %union.anon* %7 to %struct.in6_addr**
%18 = load %struct.in6_addr*, %struct.in6_addr** %17
%19 = call i32 @inet_pton(i32 %15, i8* %16, %struct.in6_addr* %18)
br label %20
20: ; preds = %11, %3
%21 = load i32, i32* %4
%22 = load i32, i32* @AF_INET
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %42
24: ; preds = %20
%25 = load i32*, i32** %5
%26 = bitcast i32* %25 to %struct.in_addr*
%27 = bitcast %union.anon* %7 to %struct.in_addr**
store %struct.in_addr* %26, %struct.in_addr** %27
%28 = load i8*, i8** %6
%29 = call i64 @inet_addr(i8* %28)
%30 = bitcast %union.anon* %7 to %struct.in_addr**
%31 = load %struct.in_addr*, %struct.in_addr** %30
%32 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %31, i32 0, i32 0
store i64 %29, i64* %32
%33 = bitcast %union.anon* %7 to %struct.in_addr**
%34 = load %struct.in_addr*, %struct.in_addr** %33
%35 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %34, i32 0, i32 0
%36 = load i64, i64* %35
%37 = load i64, i64* @INADDR_NONE
%38 = icmp eq i64 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %24
%40 = call i32 @errx(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %39, %24
br label %42
42: ; preds = %41, %20
ret i32 0
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
@AF_INET6 = global i32 0
@AF_INET = global i32 0
@INADDR_NONE = global i64 0
@.str = [30 x i8] c"invalid address specification\00"
define i32 @packadrinfo(i32 %0, i32* %1, i8* %2) {
%4 = load i32, i32* @AF_INET6
%5 = icmp eq i32 %4, %0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = bitcast i32* %1 to %struct.in6_addr*
%8 = tail call i32 @inet_pton(i32 %0, i8* %2, %struct.in6_addr* %7)
br label %9
9: ; preds = %6, %3
%10 = load i32, i32* @AF_INET
%11 = icmp eq i32 %10, %0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = tail call i64 @inet_addr(i8* %2)
%14 = bitcast i32* %1 to i64*
store i64 %13, i64* %14
%15 = load i64, i64* @INADDR_NONE
%16 = icmp eq i64 %13, %15
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %12, %17, %9
ret i32 0
}