#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 ndm_ip_sockaddr_t {
  int dummy;
};

/* Variables and functions */
scalar_t__ AF_INET;
int AF_INET6;
int /*<<< orphan*/ assert(int);
scalar_t__ ndm_ip_sockaddr_family(struct ndm_ip_sockaddr_t const *const);
scalar_t__ ndm_ip_sockaddr_is_v4(struct ndm_ip_sockaddr_t const *const);
scalar_t__ ndm_ip_sockaddr_is_v6(struct ndm_ip_sockaddr_t const *const);
int ndm_ip_sockaddr_domain(const struct ndm_ip_sockaddr_t *const sa) {
  assert(ndm_ip_sockaddr_is_v4(sa) || ndm_ip_sockaddr_is_v6(sa));
  return (ndm_ip_sockaddr_family(sa) == AF_INET) ? AF_INET : AF_INET6;
}


x86 assembly (clang, -O0):
<ndm_ip_sockaddr_domain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ndm_ip_sockaddr_is_v4@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x9(%rbp)
jne    117a <ndm_ip_sockaddr_domain+0x3a>
mov    -0x8(%rbp),%rdi
call   1050 <ndm_ip_sockaddr_is_v6@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ndm_ip_sockaddr_family@plt>
mov    0x2e51(%rip),%rcx
cmp    (%rcx),%rax
jne    11b3 <ndm_ip_sockaddr_domain+0x73>
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11c1 <ndm_ip_sockaddr_domain+0x81>
mov    0x2e26(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ndm_ip_sockaddr_domain>:
push   %rbx
mov    %rdi,%rbx
call   1030 <ndm_ip_sockaddr_is_v4@plt>
mov    $0x1,%edi
test   %rax,%rax
jne    1164 <ndm_ip_sockaddr_domain+0x24>
mov    %rbx,%rdi
call   1050 <ndm_ip_sockaddr_is_v6@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1040 <ndm_ip_sockaddr_family@plt>
mov    %rax,%rcx
mov    0x2e6d(%rip),%rax
mov    (%rax),%rax
cmp    %rax,%rcx
je     118c <ndm_ip_sockaddr_domain+0x4c>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.ndm_ip_sockaddr_t = type { i32 }
@AF_INET = global i64 0
@AF_INET6 = global i32 0
define i32 @ndm_ip_sockaddr_domain(%struct.ndm_ip_sockaddr_t* %0) {
%2 = alloca %struct.ndm_ip_sockaddr_t*
store %struct.ndm_ip_sockaddr_t* %0, %struct.ndm_ip_sockaddr_t** %2
%3 = load %struct.ndm_ip_sockaddr_t*, %struct.ndm_ip_sockaddr_t** %2
%4 = call i64 @ndm_ip_sockaddr_is_v4(%struct.ndm_ip_sockaddr_t* %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load %struct.ndm_ip_sockaddr_t*, %struct.ndm_ip_sockaddr_t** %2
%8 = call i64 @ndm_ip_sockaddr_is_v6(%struct.ndm_ip_sockaddr_t* %7)
%9 = icmp ne i64 %8, 0
br label %10
10: ; preds = %6, %1
%11 = phi i1 [ true, %1 ], [ %9, %6 ]
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load %struct.ndm_ip_sockaddr_t*, %struct.ndm_ip_sockaddr_t** %2
%15 = call i64 @ndm_ip_sockaddr_family(%struct.ndm_ip_sockaddr_t* %14)
%16 = load i64, i64* @AF_INET
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = load i64, i64* @AF_INET
br label %23
20: ; preds = %10
%21 = load i32, i32* @AF_INET6
%22 = sext i32 %21 to i64
br label %23
23: ; preds = %20, %18
%24 = phi i64 [ %19, %18 ], [ %22, %20 ]
%25 = trunc i64 %24 to i32
ret i32 %25
}

LLVM IR (-O2):
%struct.ndm_ip_sockaddr_t = type { i32 }
@AF_INET = global i64 0
@AF_INET6 = global i32 0
define i32 @ndm_ip_sockaddr_domain(%struct.ndm_ip_sockaddr_t* %0) {
%2 = tail call i64 @ndm_ip_sockaddr_is_v4(%struct.ndm_ip_sockaddr_t* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i64 @ndm_ip_sockaddr_is_v6(%struct.ndm_ip_sockaddr_t* %0)
%6 = icmp ne i64 %5, 0
%7 = zext i1 %6 to i32
br label %8
8: ; preds = %4, %1
%9 = phi i32 [ 1, %1 ], [ %7, %4 ]
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i64 @ndm_ip_sockaddr_family(%struct.ndm_ip_sockaddr_t* %0)
%12 = load i64, i64* @AF_INET
%13 = icmp eq i64 %11, %12
%14 = load i32, i32* @AF_INET6
%15 = zext i32 %14 to i64
%16 = select i1 %13, i64 %12, i64 %15
%17 = trunc i64 %16 to i32
ret i32 %17
}