void CNullUnionOrSelected(const volatile void *p, unsigned int size,
                          int sameFieldSelected, const char *text,
                          const char *file, int line, const char *func) {
  if (!sameFieldSelected) {
    const volatile char *pp = (const volatile char *)p;
    const volatile char *pend = pp + size;
    while (pp < pend) {
      if (!(0 == *pp++) || 0) {
        deputy_fail_mayreturn("null union check", text, file, line, func);
      };
    }
  }
}


x86 assembly (clang, -O0):
<CNullUnionOrSelected>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11a5 <CNullUnionOrSelected+0x95>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    11a0 <CNullUnionOrSelected+0x90>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%al
movsbl %al,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     119b <CNullUnionOrSelected+0x8b>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    0x10(%rbp),%r8
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <deputy_fail_mayreturn@plt>
jmp    1152 <CNullUnionOrSelected+0x42>
jmp    11a5 <CNullUnionOrSelected+0x95>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CNullUnionOrSelected>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     112e <CNullUnionOrSelected+0x1e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %esi,%esi
je     111f <CNullUnionOrSelected+0xf>
mov    %r9d,%r14d
mov    %r8,%r15
mov    %rcx,%rbp
mov    %rdi,%rbx
mov    %esi,%r12d
add    %rdi,%r12
lea    0xeb5(%rip),%r13
jmp    1155 <CNullUnionOrSelected+0x45>
nopl   (%rax)
cmp    %r12,%rbx
jae    111f <CNullUnionOrSelected+0xf>
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
je     1150 <CNullUnionOrSelected+0x40>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    0x40(%rsp),%r8
xor    %eax,%eax
call   1030 <deputy_fail_mayreturn@plt>
jmp    1150 <CNullUnionOrSelected+0x40>

LLVM IR (-O0):
@.str = [17 x i8] c"null union check\00"
define void @CNullUnionOrSelected(i8* %0, i32 %1, i32 %2, i8* %3, i8* %4, i32 %5, i8* %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i32 %5, i32* %13
store i8* %6, i8** %14
%17 = load i32, i32* %10
%18 = icmp ne i32 %17, 0
br i1 %18, label %43, label %19
19: ; preds = %7
%20 = load i8*, i8** %8
store i8* %20, i8** %15
%21 = load i8*, i8** %15
%22 = load i32, i32* %9
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8* %24, i8** %16
br label %25
25: ; preds = %41, %19
%26 = load i8*, i8** %15
%27 = load i8*, i8** %16
%28 = icmp ult i8* %26, %27
br i1 %28, label %29, label %42
29: ; preds = %25
%30 = load i8*, i8** %15
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %15
%32 = load volatile i8, i8* %30
%33 = sext i8 %32 to i32
%34 = icmp eq i32 0, %33
br i1 %34, label %41, label %35
35: ; preds = %29
%36 = load i8*, i8** %11
%37 = load i8*, i8** %12
%38 = load i32, i32* %13
%39 = load i8*, i8** %14
%40 = call i32 (i8*, i8*, i8*, i32, i8*, ...) bitcast (i32 (...)* @deputy_fail_mayreturn to i32 (i8*, i8*, i8*, i32, i8*, ...)*)(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %36, i8* %37, i32 %38, i8* %39)
br label %41
41: ; preds = %35, %29
br label %25
42: ; preds = %25
br label %43
43: ; preds = %42, %7
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"null union check\00"
define void @CNullUnionOrSelected(i8* %0, i32 %1, i32 %2, i8* %3, i8* %4, i32 %5, i8* %6) {
%8 = icmp eq i32 %2, 0
br i1 %8, label %9, label %22
9: ; preds = %7
%10 = zext i32 %1 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = icmp eq i32 %1, 0
br i1 %12, label %22, label %13
13: ; preds = %9, %20
%14 = phi i8* [ %15, %20 ], [ %0, %9 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load volatile i8, i8* %14
%17 = icmp eq i8 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = tail call i32 (i8*, i8*, i8*, i32, i8*, ...) bitcast (i32 (...)* @deputy_fail_mayreturn to i32 (i8*, i8*, i8*, i32, i8*, ...)*)(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %4, i32 %5, i8* %6)
br label %20
20: ; preds = %18, %13
%21 = icmp ult i8* %15, %11
br i1 %21, label %13, label %22
22: ; preds = %20, %9, %7
ret void
}