#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 uint64_t;

/* Variables and functions */
uint8_t uint40_encode(uint64_t value, uint8_t *p_encoded_data) {
  p_encoded_data[0] = (uint8_t)((value & 0x00000000FF) >> 0);
  p_encoded_data[1] = (uint8_t)((value & 0x000000FF00) >> 8);
  p_encoded_data[2] = (uint8_t)((value & 0x0000FF0000) >> 16);
  p_encoded_data[3] = (uint8_t)((value & 0x00FF000000) >> 24);
  p_encoded_data[4] = (uint8_t)((value & 0xFF00000000) >> 32);
  return 5;
}


x86 assembly (clang, -O0):
<uint40_encode>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%ecx
and    $0xff,%ecx
sar    $0x0,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%ecx
and    $0xff00,%ecx
sar    $0x8,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x4(%rbp),%ecx
and    $0xff0000,%ecx
sar    $0x10,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x4(%rbp),%ecx
and    $0xff000000,%ecx
shr    $0x18,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
movslq -0x4(%rbp),%rax
movabs $0xff00000000,%rcx
and    %rcx,%rax
sar    $0x20,%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    $0x5,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<uint40_encode>:
mov    %edi,%eax
movzbl %al,%ecx
mov    %ecx,(%rsi)
movzbl %ah,%ecx
mov    %ecx,0x4(%rsi)
mov    %edi,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ecx,0x8(%rsi)
mov    %edi,%ecx
shr    $0x18,%ecx
mov    %ecx,0xc(%rsi)
sar    $0x1f,%eax
movzbl %al,%eax
mov    %eax,0x10(%rsi)
mov    $0x5,%eax
ret

LLVM IR (-O0):
define i32 @uint40_encode(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
store i32 %0, i32* %3
store i32* %1, i32** %4
%5 = load i32, i32* %3
%6 = and i32 %5, 255
%7 = ashr i32 %6, 0
%8 = load i32*, i32** %4
%9 = getelementptr inbounds i32, i32* %8, i64 0
store i32 %7, i32* %9
%10 = load i32, i32* %3
%11 = and i32 %10, 65280
%12 = ashr i32 %11, 8
%13 = load i32*, i32** %4
%14 = getelementptr inbounds i32, i32* %13, i64 1
store i32 %12, i32* %14
%15 = load i32, i32* %3
%16 = and i32 %15, 16711680
%17 = ashr i32 %16, 16
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i64 2
store i32 %17, i32* %19
%20 = load i32, i32* %3
%21 = and i32 %20, -16777216
%22 = lshr i32 %21, 24
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i64 3
store i32 %22, i32* %24
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = and i64 %26, 1095216660480
%28 = ashr i64 %27, 32
%29 = trunc i64 %28 to i32
%30 = load i32*, i32** %4
%31 = getelementptr inbounds i32, i32* %30, i64 4
store i32 %29, i32* %31
ret i32 5
}

LLVM IR (-O2):
define i32 @uint40_encode(i32 %0, i32* nocapture writeonly %1) {
%3 = and i32 %0, 255
store i32 %3, i32* %1
%4 = lshr i32 %0, 8
%5 = and i32 %4, 255
%6 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %5, i32* %6
%7 = lshr i32 %0, 16
%8 = and i32 %7, 255
%9 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %8, i32* %9
%10 = lshr i32 %0, 24
%11 = getelementptr inbounds i32, i32* %1, i64 3
store i32 %10, i32* %11
%12 = icmp slt i32 %0, 0
%13 = select i1 %12, i32 255, i32 0
%14 = getelementptr inbounds i32, i32* %1, i64 4
store i32 %13, i32* %14
ret i32 5
}