#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 {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
unsigned int sockaddr_size(const void *x) {
  if (x == NULL)
    return 0;
  if (((struct sockaddr *)(x))->sa_family == AF_INET) {
    return sizeof(struct sockaddr_in);
  } else if (((struct sockaddr *)(x))->sa_family == AF_INET6) {
    return sizeof(struct sockaddr_in6);
  }
  return 0;
}


x86 assembly (clang, -O0):
<sockaddr_size>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    111f <sockaddr_size+0x1f>
movl   $0x0,-0x4(%rbp)
jmp    1171 <sockaddr_size+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2ebb(%rip),%rcx
cmp    (%rcx),%rax
jne    1142 <sockaddr_size+0x42>
movl   $0x4,-0x4(%rbp)
jmp    1171 <sockaddr_size+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e90(%rip),%rcx
cmp    (%rcx),%rax
jne    1165 <sockaddr_size+0x65>
movl   $0x4,-0x4(%rbp)
jmp    1171 <sockaddr_size+0x71>
jmp    116a <sockaddr_size+0x6a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockaddr_size>:
test   %rdi,%rdi
je     112c <sockaddr_size+0x2c>
mov    (%rdi),%rcx
mov    0x2ed9(%rip),%rdx
mov    $0x4,%eax
cmp    (%rdx),%rcx
je     112b <sockaddr_size+0x2b>
mov    0x2ec0(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
sete   %al
shl    $0x2,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
@AF_INET6 = global i64 0
define i32 @sockaddr_size(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 0, i32* %2
br label %25
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to %struct.sockaddr*
%10 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @AF_INET
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %7
store i32 4, i32* %2
br label %25
15: ; preds = %7
%16 = load i8*, i8** %3
%17 = bitcast i8* %16 to %struct.sockaddr*
%18 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = load i64, i64* @AF_INET6
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 4, i32* %2
br label %25
23: ; preds = %15
br label %24
24: ; preds = %23
store i32 0, i32* %2
br label %25
25: ; preds = %24, %22, %14, %6
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@AF_INET = global i64 0
@AF_INET6 = global i64 0
define i32 @sockaddr_size(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = bitcast i8* %0 to i64*
%5 = load i64, i64* %4
%6 = load i64, i64* @AF_INET
%7 = icmp eq i64 %5, %6
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = load i64, i64* @AF_INET6
%10 = icmp eq i64 %5, %9
%11 = select i1 %10, i32 4, i32 0
br label %12
12: ; preds = %8, %3, %1
%13 = phi i32 [ 0, %1 ], [ 4, %3 ], [ %11, %8 ]
ret i32 %13
}