#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 /*<<< orphan*/ uint8_t;
typedef unsigned char uint32_t;
typedef int uint16_t;
typedef int /*<<< orphan*/ checksum;

/* Variables and functions */
int /*<<< orphan*/ FifoProtocol_memcpy(int /*<<< orphan*/ *, unsigned char *,
                                       int);
uint16_t inv_fifo_protocol_helper_encode_firmware(uint8_t major, uint8_t minor,
                                                  uint8_t patch,
                                                  unsigned char *hash,
                                                  uint32_t checksum,
                                                  uint8_t *out) {
  out[0] = major;
  out[1] = minor;
  out[2] = patch;
  FifoProtocol_memcpy((&out[3]), (hash), (8));
  checksum = checksum;
  FifoProtocol_memcpy((&out[11]), (&checksum), (sizeof(checksum)));
  return 15;
}


x86 assembly (clang, -O0):
<inv_fifo_protocol_helper_encode_firmware>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8b,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x28(%rbp),%rdi
add    $0xc,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1030 <FifoProtocol_memcpy@plt>
mov    -0x19(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x2c,%rdi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <FifoProtocol_memcpy@plt>
mov    $0xf,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inv_fifo_protocol_helper_encode_firmware>:
push   %rbx
sub    $0x10,%rsp
mov    %r9,%rbx
mov    %r8b,0xf(%rsp)
mov    %edi,(%r9)
mov    %esi,0x4(%r9)
mov    %edx,0x8(%r9)
lea    0xc(%r9),%rdi
mov    %rcx,%rsi
mov    $0x8,%edx
call   1030 <FifoProtocol_memcpy@plt>
add    $0x2c,%rbx
lea    0xf(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1030 <FifoProtocol_memcpy@plt>
mov    $0xf,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @inv_fifo_protocol_helper_encode_firmware(i32 %0, i32 %1, i32 %2, i8* %3, i8 zeroext %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8
%12 = alloca i32*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i8 %4, i8* %11
store i32* %5, i32** %12
%13 = load i32, i32* %7
%14 = load i32*, i32** %12
%15 = getelementptr inbounds i32, i32* %14, i64 0
store i32 %13, i32* %15
%16 = load i32, i32* %8
%17 = load i32*, i32** %12
%18 = getelementptr inbounds i32, i32* %17, i64 1
store i32 %16, i32* %18
%19 = load i32, i32* %9
%20 = load i32*, i32** %12
%21 = getelementptr inbounds i32, i32* %20, i64 2
store i32 %19, i32* %21
%22 = load i32*, i32** %12
%23 = getelementptr inbounds i32, i32* %22, i64 3
%24 = load i8*, i8** %10
%25 = call i32 @FifoProtocol_memcpy(i32* %23, i8* %24, i32 8)
%26 = load i8, i8* %11
store i8 %26, i8* %11
%27 = load i32*, i32** %12
%28 = getelementptr inbounds i32, i32* %27, i64 11
%29 = call i32 @FifoProtocol_memcpy(i32* %28, i8* %11, i32 1)
ret i32 15
}

LLVM IR (-O2):
define i32 @inv_fifo_protocol_helper_encode_firmware(i32 %0, i32 %1, i32 %2, i8* %3, i8 zeroext %4, i32* %5) {
%7 = alloca i8
store i8 %4, i8* %7
store i32 %0, i32* %5
%8 = getelementptr inbounds i32, i32* %5, i64 1
store i32 %1, i32* %8
%9 = getelementptr inbounds i32, i32* %5, i64 2
store i32 %2, i32* %9
%10 = getelementptr inbounds i32, i32* %5, i64 3
%11 = tail call i32 @FifoProtocol_memcpy(i32* %10, i8* %3, i32 8)
%12 = getelementptr inbounds i32, i32* %5, i64 11
%13 = call i32 @FifoProtocol_memcpy(i32* %12, i8* %7, i32 1)
ret i32 15
}