#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 */

/* Variables and functions */
int bit_array_test(void *array, size_t bit) {
  if (array) {
    size_t *size = (size_t *)array;
    if (bit < *size) {
      unsigned char *ptr = (unsigned char *)(size + 1);
      if (ptr[bit >> 3] & (1U << (bit & 7))) {
        return 1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<bit_array_test>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117e <bit_array_test+0x7e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
jae    1179 <bit_array_test+0x79>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
shr    $0x3,%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
and    $0x7,%rcx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1174 <bit_array_test+0x74>
movl   $0x1,-0x4(%rbp)
jmp    1185 <bit_array_test+0x85>
jmp    1179 <bit_array_test+0x79>
jmp    117e <bit_array_test+0x7e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_array_test>:
xor    %eax,%eax
test   %rdi,%rdi
je     112a <bit_array_test+0x2a>
cmp    %rsi,(%rdi)
jbe    112b <bit_array_test+0x2b>
mov    %rsi,%rax
shr    $0x3,%rax
movzbl 0x8(%rdi,%rax,1),%ecx
and    $0x7,%sil
movzbl %sil,%edx
mov    $0x1,%eax
bt     %edx,%ecx
jae    112b <bit_array_test+0x2b>
ret
xor    %eax,%eax
ret

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

LLVM IR (-O2):
define i32 @bit_array_test(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = bitcast i8* %0 to i64*
%6 = load i64, i64* %5
%7 = icmp ugt i64 %6, %1
br i1 %7, label %8, label %19
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %0, i64 8
%10 = lshr i64 %1, 3
%11 = getelementptr inbounds i8, i8* %9, i64 %10
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = trunc i64 %1 to i32
%15 = and i32 %14, 7
%16 = shl nuw nsw i32 1, %15
%17 = and i32 %16, %13
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %4, %8
br label %20
20: ; preds = %2, %19, %8
%21 = phi i32 [ 1, %8 ], [ 0, %19 ], [ 0, %2 ]
ret i32 %21
}