#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 */
typedef int uint8_t;

/* Variables and functions */
void set_bits_from_byte(uint8_t *dest, int address, const uint8_t value) {
  int i;
  for (i = 0; i < 8; i++) {
    dest[address + i] = (value & (1 << i)) ? 1 : 0;
  }
}


x86 assembly (clang, -O0):
<set_bits_from_byte>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    115f <set_bits_from_byte+0x5f>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x18(%rbp),%ecx
and    %eax,%ecx
xor    %edx,%edx
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1115 <set_bits_from_byte+0x15>
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_bits_from_byte>:
movslq %esi,%rax
mov    %edx,%ecx
and    $0x1,%ecx
mov    %ecx,(%rdi,%rax,4)
mov    %edx,%ecx
shr    %ecx
and    $0x1,%ecx
mov    %ecx,0x4(%rdi,%rax,4)
mov    %edx,%ecx
shr    $0x2,%ecx
and    $0x1,%ecx
mov    %ecx,0x8(%rdi,%rax,4)
mov    %edx,%ecx
shr    $0x3,%ecx
and    $0x1,%ecx
mov    %ecx,0xc(%rdi,%rax,4)
mov    %edx,%ecx
shr    $0x4,%ecx
and    $0x1,%ecx
mov    %ecx,0x10(%rdi,%rax,4)
mov    %edx,%ecx
shr    $0x5,%ecx
and    $0x1,%ecx
mov    %ecx,0x14(%rdi,%rax,4)
mov    %edx,%ecx
shr    $0x6,%ecx
and    $0x1,%ecx
mov    %ecx,0x18(%rdi,%rax,4)
shr    $0x7,%edx
and    $0x1,%edx
mov    %edx,0x1c(%rdi,%rax,4)
ret

LLVM IR (-O0):
define void @set_bits_from_byte(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %25, %3
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 8
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = shl i32 1, %13
%15 = and i32 %12, %14
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 1, i32 0
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = add nsw i32 %20, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %19, i64 %23
store i32 %18, i32* %24
br label %25
25: ; preds = %11
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %8
28: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @set_bits_from_byte(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = sext i32 %1 to i64
%5 = and i32 %2, 1
%6 = getelementptr inbounds i32, i32* %0, i64 %4
store i32 %5, i32* %6
%7 = lshr i32 %2, 1
%8 = and i32 %7, 1
%9 = add nsw i64 %4, 1
%10 = getelementptr inbounds i32, i32* %0, i64 %9
store i32 %8, i32* %10
%11 = lshr i32 %2, 2
%12 = and i32 %11, 1
%13 = add nsw i64 %4, 2
%14 = getelementptr inbounds i32, i32* %0, i64 %13
store i32 %12, i32* %14
%15 = lshr i32 %2, 3
%16 = and i32 %15, 1
%17 = add nsw i64 %4, 3
%18 = getelementptr inbounds i32, i32* %0, i64 %17
store i32 %16, i32* %18
%19 = lshr i32 %2, 4
%20 = and i32 %19, 1
%21 = add nsw i64 %4, 4
%22 = getelementptr inbounds i32, i32* %0, i64 %21
store i32 %20, i32* %22
%23 = lshr i32 %2, 5
%24 = and i32 %23, 1
%25 = add nsw i64 %4, 5
%26 = getelementptr inbounds i32, i32* %0, i64 %25
store i32 %24, i32* %26
%27 = lshr i32 %2, 6
%28 = and i32 %27, 1
%29 = add nsw i64 %4, 6
%30 = getelementptr inbounds i32, i32* %0, i64 %29
store i32 %28, i32* %30
%31 = lshr i32 %2, 7
%32 = and i32 %31, 1
%33 = add nsw i64 %4, 7
%34 = getelementptr inbounds i32, i32* %0, i64 %33
store i32 %32, i32* %34
ret void
}