#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 */
size_t CHAR_BIT;
bool bit_set(void *data, size_t pos) {
  size_t chunk = pos / CHAR_BIT;
  size_t offset = pos % CHAR_BIT;
  unsigned char *cdata = (unsigned char *)data;
  bool prev = (cdata[chunk] >> offset) & 0x1;
  cdata[chunk] |= (1U << offset);
  return prev;
}


x86 assembly (clang, -O0):
<bit_set>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ec9(%rip),%rcx
xor    %edx,%edx
divq   (%rcx)
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2eb5(%rip),%rcx
xor    %edx,%edx
divq   (%rcx)
mov    %rdx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x20(%rbp),%rcx
sar    %cl,%eax
and    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
or     %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_set>:
mov    %rsi,%rax
mov    0x2ed6(%rip),%rcx
mov    (%rcx),%rcx
mov    %rsi,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1123 <bit_set+0x23>
xor    %edx,%edx
div    %rcx
mov    %rdx,%rcx
jmp    1129 <bit_set+0x29>
xor    %edx,%edx
div    %ecx
mov    %edx,%ecx
movzbl (%rdi,%rax,1),%esi
mov    %esi,%edx
shr    %cl,%edx
and    $0x1,%edx
bts    %ecx,%esi
mov    %sil,(%rdi,%rax,1)
mov    %edx,%eax
ret

LLVM IR (-O0):
@CHAR_BIT = global i64 0
define i32 @bit_set(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%9 = load i64, i64* %4
%10 = load i64, i64* @CHAR_BIT
%11 = udiv i64 %9, %10
store i64 %11, i64* %5
%12 = load i64, i64* %4
%13 = load i64, i64* @CHAR_BIT
%14 = urem i64 %12, %13
store i64 %14, i64* %6
%15 = load i8*, i8** %3
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = load i64, i64* %5
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = load i64, i64* %6
%22 = trunc i64 %21 to i32
%23 = ashr i32 %20, %22
%24 = and i32 %23, 1
store i32 %24, i32* %8
%25 = load i64, i64* %6
%26 = trunc i64 %25 to i32
%27 = shl i32 1, %26
%28 = load i8*, i8** %7
%29 = load i64, i64* %5
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = or i32 %32, %27
%34 = trunc i32 %33 to i8
store i8 %34, i8* %30
%35 = load i32, i32* %8
ret i32 %35
}

LLVM IR (-O2):
@CHAR_BIT = global i64 0
define i32 @bit_set(i8* nocapture %0, i64 %1) {
%3 = load i64, i64* @CHAR_BIT
%4 = udiv i64 %1, %3
%5 = urem i64 %1, %3
%6 = getelementptr inbounds i8, i8* %0, i64 %4
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = trunc i64 %5 to i32
%10 = lshr i32 %8, %9
%11 = and i32 %10, 1
%12 = shl nuw i32 1, %9
%13 = trunc i32 %12 to i8
%14 = or i8 %7, %13
store i8 %14, i8* %6
ret i32 %11
}