unsigned int get_num_of_members(ref) void *ref;
{
  if (*((unsigned int *)((unsigned char *)(ref) + sizeof(void *) +
                         sizeof(unsigned int) + sizeof(void *))) == 0) {
    return *((unsigned int *)((unsigned char *)(ref) + sizeof(void *) +
                              sizeof(unsigned int) + sizeof(void *) +
                              sizeof(int)));
  } else {
    return *(
        (unsigned int
             *)((unsigned char *)(ref) + sizeof(void *) + sizeof(unsigned int) +
                sizeof(void *) + sizeof(int) +
                ((*((unsigned int *)((unsigned char *)(ref) + sizeof(void *) +
                                     sizeof(unsigned int) + sizeof(void *)))) *
                 sizeof(unsigned int))));
  }
}


x86 assembly (clang, -O0):
<get_num_of_members>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,0x14(%rax)
jne    1125 <get_num_of_members+0x25>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    113b <get_num_of_members+0x3b>
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    0x14(%rcx),%ecx
shl    $0x2,%rcx
mov    0x18(%rax,%rcx,1),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_num_of_members>:
mov    0x14(%rdi),%eax
lea    0x0(,%rax,4),%rcx
test   %rax,%rax
cmove  %rax,%rcx
mov    0x18(%rdi,%rcx,1),%eax
ret

LLVM IR (-O0):
define i32 @get_num_of_members(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i64 8
%6 = getelementptr inbounds i8, i8* %5, i64 4
%7 = getelementptr inbounds i8, i8* %6, i64 8
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 8
%14 = getelementptr inbounds i8, i8* %13, i64 4
%15 = getelementptr inbounds i8, i8* %14, i64 8
%16 = getelementptr inbounds i8, i8* %15, i64 4
%17 = bitcast i8* %16 to i32*
%18 = load i32, i32* %17
store i32 %18, i32* %2
br label %36
19: ; preds = %1
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 8
%22 = getelementptr inbounds i8, i8* %21, i64 4
%23 = getelementptr inbounds i8, i8* %22, i64 8
%24 = getelementptr inbounds i8, i8* %23, i64 4
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 8
%27 = getelementptr inbounds i8, i8* %26, i64 4
%28 = getelementptr inbounds i8, i8* %27, i64 8
%29 = bitcast i8* %28 to i32*
%30 = load i32, i32* %29
%31 = zext i32 %30 to i64
%32 = mul i64 %31, 4
%33 = getelementptr inbounds i8, i8* %24, i64 %32
%34 = bitcast i8* %33 to i32*
%35 = load i32, i32* %34
store i32 %35, i32* %2
br label %36
36: ; preds = %19, %11
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
define i32 @get_num_of_members(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 20
%3 = bitcast i8* %2 to i32*
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 0
%6 = getelementptr inbounds i8, i8* %0, i64 24
%7 = zext i32 %4 to i64
%8 = shl nuw nsw i64 %7, 2
%9 = select i1 %5, i64 0, i64 %8
%10 = getelementptr i8, i8* %6, i64 %9
%11 = bitcast i8* %10 to i32*
%12 = load i32, i32* %11
ret i32 %12
}