#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;
typedef int uint32_t;

/* Variables and functions */
void BuildKeyCache(uint32_t *cache, int cache_len) {
  static const uint8_t key[] = {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
                                0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
                                0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
                                0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
                                0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05};
  uint32_t result = (((uint32_t)key[0]) << 24) | (((uint32_t)key[1]) << 16) |
                    (((uint32_t)key[2]) << 8) | ((uint32_t)key[3]);
  uint32_t idx = 32;
  int i;
  for (i = 0; i < cache_len; i++, idx++) {
    uint8_t shift = (idx % 8);
    uint32_t bit;
    cache[i] = result;
    bit = ((key[idx / 8] << shift) & 0x80) ? 1 : 0;
    result = ((result << 1) | bit);
  }
}


x86 assembly (clang, -O0):
<BuildKeyCache>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeef(%rip),%eax
shl    $0x18,%eax
mov    0xeea(%rip),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    0xee3(%rip),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     0xedc(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x20,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bf <BuildKeyCache+0xbf>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
movslq %eax,%rcx
lea    0xe82(%rip),%rax
mov    (%rax,%rcx,4),%edx
mov    -0x1c(%rbp),%ecx
shl    %cl,%edx
and    $0x80,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <BuildKeyCache+0x41>
pop    %rbp
ret

x86 assembly (clang, -O2):
<BuildKeyCache>:
test   %esi,%esi
jle    1147 <BuildKeyCache+0x47>
mov    %esi,%r9d
mov    $0x5050505,%edx
xor    %esi,%esi
lea    0xeeb(%rip),%r8
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x20(%rsi),%rcx
mov    %edx,(%rdi,%rsi,4)
mov    %ecx,%eax
shr    $0x3,%eax
mov    (%r8,%rax,4),%eax
and    $0x7,%cl
shl    %cl,%eax
movzbl %al,%eax
shr    $0x7,%eax
lea    (%rax,%rdx,2),%edx
add    $0x1,%rsi
cmp    %rsi,%r9
jne    1120 <BuildKeyCache+0x20>
ret

LLVM IR (-O0):
@BuildKeyCache.key = internal constant [40 x i32] [i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5]
define void @BuildKeyCache(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%10 = load i32, i32* getelementptr inbounds ([40 x i32], [40 x i32]* @BuildKeyCache.key, i64 0, i64 0)
%11 = shl i32 %10, 24
%12 = load i32, i32* getelementptr inbounds ([40 x i32], [40 x i32]* @BuildKeyCache.key, i64 0, i64 1)
%13 = shl i32 %12, 16
%14 = or i32 %11, %13
%15 = load i32, i32* getelementptr inbounds ([40 x i32], [40 x i32]* @BuildKeyCache.key, i64 0, i64 2)
%16 = shl i32 %15, 8
%17 = or i32 %14, %16
%18 = load i32, i32* getelementptr inbounds ([40 x i32], [40 x i32]* @BuildKeyCache.key, i64 0, i64 3)
%19 = or i32 %17, %18
store i32 %19, i32* %5
store i32 32, i32* %6
store i32 0, i32* %7
br label %20
20: ; preds = %47, %2
%21 = load i32, i32* %7
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %52
24: ; preds = %20
%25 = load i32, i32* %6
%26 = srem i32 %25, 8
store i32 %26, i32* %8
%27 = load i32, i32* %5
%28 = load i32*, i32** %3
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %27, i32* %31
%32 = load i32, i32* %6
%33 = sdiv i32 %32, 8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [40 x i32], [40 x i32]* @BuildKeyCache.key, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %8
%38 = shl i32 %36, %37
%39 = and i32 %38, 128
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 1, i32 0
store i32 %42, i32* %9
%43 = load i32, i32* %5
%44 = shl i32 %43, 1
%45 = load i32, i32* %9
%46 = or i32 %44, %45
store i32 %46, i32* %5
br label %47
47: ; preds = %24
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %20
52: ; preds = %20
ret void
}

LLVM IR (-O2):
@BuildKeyCache.key = internal unnamed_addr constant [40 x i32] [i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5]
define void @BuildKeyCache(i32* nocapture writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %25
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %22, %6 ]
%8 = phi i32 [ 84215045, %4 ], [ %21, %6 ]
%9 = phi i32 [ 32, %4 ], [ %23, %6 ]
%10 = and i32 %9, 7
%11 = getelementptr inbounds i32, i32* %0, i64 %7
store i32 %8, i32* %11
%12 = lshr i32 %9, 3
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [40 x i32], [40 x i32]* @BuildKeyCache.key, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = lshr i32 128, %10
%17 = and i32 %15, %16
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
%20 = shl i32 %8, 1
%21 = or i32 %20, %19
%22 = add nuw nsw i64 %7, 1
%23 = add nuw nsw i32 %9, 1
%24 = icmp eq i64 %22, %5
br i1 %24, label %25, label %6
25: ; preds = %6, %2
ret void
}