void set_member(ref, i, val) void *ref;
unsigned int i;
void *val;
{
  if (*((unsigned int *)((unsigned char *)(ref) + sizeof(void *) +
                         sizeof(unsigned int) + sizeof(void *))) == 0) {
    *((void **)((unsigned char *)(ref) + sizeof(int) + sizeof(void *) +
                sizeof(unsigned int) + sizeof(void *) + sizeof(unsigned int)) +
      (i)) = ((void *)(val));
  } else {
    *((void **)((unsigned char *)(ref) + sizeof(int) + sizeof(void *) +
                sizeof(unsigned int) + sizeof(void *) + sizeof(unsigned int) +
                ((*((unsigned int *)((unsigned char *)(ref) + sizeof(void *) +
                                     sizeof(unsigned int) + sizeof(void *)))) *
                 sizeof(unsigned int))) +
      (i)) = ((void *)(val));
  }
}


x86 assembly (clang, -O0):
<set_member>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x0,0x14(%rax)
jne    1132 <set_member+0x32>
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %rdx,0x1c(%rax,%rcx,8)
jmp    1163 <set_member+0x63>
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
add    $0x4,%rax
add    $0x8,%rax
add    $0x4,%rax
add    $0x8,%rax
add    $0x4,%rax
mov    -0x8(%rbp),%rcx
mov    0x14(%rcx),%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    -0xc(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_member>:
mov    0x14(%rdi),%eax
lea    0x0(,%rax,4),%rcx
test   %rax,%rax
cmove  %rax,%rcx
add    %rdi,%rcx
mov    %esi,%eax
mov    %rdx,0x1c(%rcx,%rax,8)
ret

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

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