#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 scalar_t__ uint8_t;
typedef int uint64_t;

/* Variables and functions */
void cast_uint64_to_uint8_array_len(uint8_t *dst, uint64_t src, int len) {
  for (int i = 0; i < len; i++) {
    dst[i] = (uint8_t)((src & (0x00000000000000ffULL << (8 * i))) >> (8 * i));
  }
}


x86 assembly (clang, -O0):
<cast_uint64_to_uint8_array_len>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1161 <cast_uint64_to_uint8_array_len+0x61>
movslq -0xc(%rbp),%rdx
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
mov    %eax,%eax
mov    %eax,%ecx
mov    $0xff,%eax
shl    %cl,%rax
and    %rax,%rdx
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
mov    %eax,%eax
mov    %eax,%ecx
shr    %cl,%rdx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1115 <cast_uint64_to_uint8_array_len+0x15>
pop    %rbp
ret

x86 assembly (clang, -O2):
<cast_uint64_to_uint8_array_len>:
test   %edx,%edx
jle    1241 <cast_uint64_to_uint8_array_len+0x141>
movslq %esi,%r8
mov    %edx,%esi
cmp    $0x4,%edx
jae    1119 <cast_uint64_to_uint8_array_len+0x19>
xor    %edx,%edx
jmp    120e <cast_uint64_to_uint8_array_len+0x10e>
mov    %esi,%edx
and    $0xfffffffc,%edx
movq   %r8,%xmm0
pshufd $0x44,%xmm0,%xmm11
lea    0x0(,%rsi,8),%rcx
and    $0xffffffffffffffe0,%rcx
movdqa 0xec3(%rip),%xmm1
xor    %eax,%eax
movdqa 0xec8(%rip),%xmm8
movdqa 0xecf(%rip),%xmm10
movdqa 0xed6(%rip),%xmm12
movdqa 0xedd(%rip),%xmm9
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqa %xmm1,%xmm6
psllq  $0x3,%xmm6
movdqa %xmm6,%xmm7
paddq  %xmm8,%xmm7
pand   %xmm10,%xmm6
movdqa %xmm12,%xmm4
psllq  %xmm6,%xmm4
pand   %xmm10,%xmm7
pshufd $0xee,%xmm6,%xmm5
movdqa %xmm12,%xmm2
psllq  %xmm5,%xmm2
movsd  %xmm4,%xmm2
movdqa %xmm12,%xmm4
psllq  %xmm7,%xmm4
pshufd $0xee,%xmm7,%xmm0
movdqa %xmm12,%xmm3
psllq  %xmm0,%xmm3
movsd  %xmm4,%xmm3
andpd  %xmm11,%xmm2
movapd %xmm2,%xmm4
psrlq  %xmm6,%xmm4
psrlq  %xmm5,%xmm2
andpd  %xmm11,%xmm3
movsd  %xmm4,%xmm2
movapd %xmm3,%xmm4
psrlq  %xmm7,%xmm4
psrlq  %xmm0,%xmm3
movsd  %xmm4,%xmm3
movupd %xmm2,(%rdi,%rax,1)
movupd %xmm3,0x10(%rdi,%rax,1)
paddq  %xmm9,%xmm1
add    $0x20,%rax
cmp    %rax,%rcx
jne    1170 <cast_uint64_to_uint8_array_len+0x70>
cmp    %rsi,%rdx
je     1241 <cast_uint64_to_uint8_array_len+0x141>
sub    %rdx,%rsi
shl    $0x3,%rdx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %edx,%ecx
and    $0xf8,%cl
mov    $0xff,%eax
shl    %cl,%rax
and    %r8,%rax
shr    %cl,%rax
mov    %rax,(%rdi,%rdx,1)
add    $0x8,%rdx
add    $0xffffffffffffffff,%rsi
jne    1220 <cast_uint64_to_uint8_array_len+0x120>
ret

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

LLVM IR (-O2):
define void @cast_uint64_to_uint8_array_len(i64* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %40
5: ; preds = %3
%6 = sext i32 %1 to i64
%7 = zext i32 %2 to i64
%8 = icmp ult i32 %2, 4
br i1 %8, label %38, label %9
9: ; preds = %5
%10 = and i64 %7, 4294967292
%11 = insertelement <2 x i64> poison, i64 %6, i64 0
%12 = shufflevector <2 x i64> %11, <2 x i64> poison, <2 x i32> zeroinitializer
%13 = insertelement <2 x i64> poison, i64 %6, i64 0
%14 = shufflevector <2 x i64> %13, <2 x i64> poison, <2 x i32> zeroinitializer
br label %15
15: ; preds = %15, %9
%16 = phi i64 [ 0, %9 ], [ %33, %15 ]
%17 = phi <2 x i64> [ <i64 0, i64 1>, %9 ], [ %34, %15 ]
%18 = shl <2 x i64> %17, <i64 3, i64 3>
%19 = shl <2 x i64> %17, <i64 3, i64 3>
%20 = add <2 x i64> %19, <i64 16, i64 16>
%21 = and <2 x i64> %18, <i64 4294967288, i64 4294967288>
%22 = and <2 x i64> %20, <i64 4294967288, i64 4294967288>
%23 = shl <2 x i64> <i64 255, i64 255>, %21
%24 = shl <2 x i64> <i64 255, i64 255>, %22
%25 = and <2 x i64> %23, %12
%26 = and <2 x i64> %24, %14
%27 = lshr <2 x i64> %25, %21
%28 = lshr <2 x i64> %26, %22
%29 = getelementptr inbounds i64, i64* %0, i64 %16
%30 = bitcast i64* %29 to <2 x i64>*
store <2 x i64> %27, <2 x i64>* %30
%31 = getelementptr inbounds i64, i64* %29, i64 2
%32 = bitcast i64* %31 to <2 x i64>*
store <2 x i64> %28, <2 x i64>* %32
%33 = add nuw i64 %16, 4
%34 = add <2 x i64> %17, <i64 4, i64 4>
%35 = icmp eq i64 %33, %10
br i1 %35, label %36, label %15
36: ; preds = %15
%37 = icmp eq i64 %10, %7
br i1 %37, label %40, label %38
38: ; preds = %5, %36
%39 = phi i64 [ 0, %5 ], [ %10, %36 ]
br label %41
40: ; preds = %41, %36, %3
ret void
41: ; preds = %38, %41
%42 = phi i64 [ %49, %41 ], [ %39, %38 ]
%43 = shl i64 %42, 3
%44 = and i64 %43, 4294967288
%45 = shl i64 255, %44
%46 = and i64 %45, %6
%47 = lshr i64 %46, %44
%48 = getelementptr inbounds i64, i64* %0, i64 %42
store i64 %47, i64* %48
%49 = add nuw nsw i64 %42, 1
%50 = icmp eq i64 %49, %7
br i1 %50, label %40, label %41
}