#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 ndm_ip_sockaddr_t {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ AF_INET;
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);
socklen_t ndm_ip_sockaddr_size(const struct ndm_ip_sockaddr_t *const sa) {
  assert(ndm_ip_sockaddr_is_v4(sa) || ndm_ip_sockaddr_is_v6(sa));
  return (socklen_t)(ndm_ip_sockaddr_family(sa) == AF_INET
                         ? sizeof(struct sockaddr_in)
                         : sizeof(struct sockaddr_in6));
}


x86 assembly (clang, -O0):
<ndm_ip_sockaddr_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%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_size+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    %rax,%rcx
mov    0x2e4e(%rip),%rax
mov    (%rax),%rdx
mov    $0x4,%eax
cmp    %rdx,%rcx
cmove  %rax,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ndm_ip_sockaddr_size>:
push   %rbx
mov    %rdi,%rbx
call   1030 <ndm_ip_sockaddr_is_v4@plt>
mov    $0x1,%edi
test   %rax,%rax
jne    1164 <ndm_ip_sockaddr_size+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    $0x4,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.ndm_ip_sockaddr_t = type { i32 }
@AF_INET = global i64 0
define i32 @ndm_ip_sockaddr_size(%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
%18 = zext i1 %17 to i64
%19 = select i1 %17, i64 4, i64 4
%20 = trunc i64 %19 to i32
ret i32 %20
}

LLVM IR (-O2):
%struct.ndm_ip_sockaddr_t = type { i32 }
@AF_INET = global i64 0
define i32 @ndm_ip_sockaddr_size(%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)
ret i32 4
}