int setFifoData(const unsigned char *const data, unsigned int length,
                int (*spiTransfer)(unsigned char *const, unsigned int,
                                   void *const customData),
                void *const customData) {
  unsigned int spiLength = length + 1;
  unsigned char spiData[spiLength];
  spiData[0] = 0x80;
  for (unsigned int cntr = 0; cntr < length; cntr++) {
    spiData[cntr + 1] = data[cntr];
  }
  return (*spiTransfer)(spiData, spiLength, customData);
}


x86 assembly (clang, -O0):
<setFifoData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x30(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x48(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x38(%rbp)
movb   $0x80,(%rax)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1185 <setFifoData+0x85>
mov    -0x48(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x3c(%rbp),%edx
mov    (%rcx,%rdx,1),%dl
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1152 <setFifoData+0x52>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   *%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setFifoData>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
lea    0x1(%rsi),%r12d
mov    %rsp,%rcx
lea    0xf(%r12),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rcx,%rbx
sub    %rdx,%rbx
mov    %rbx,%rsp
neg    %rdx
movb   $0x80,(%rcx,%rdx,1)
test   %esi,%esi
je     1156 <setFifoData+0x46>
mov    %rdi,%rax
lea    0x1(%rbx),%rdi
mov    %esi,%edx
mov    %rax,%rsi
call   1030 <memcpy@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r14,%rdx
call   *%r15
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @setFifoData(i8* %0, i32 %1, i32 (i8*, i32, i8*)* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32 (i8*, i32, i8*)*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 (i8*, i32, i8*)* %2, i32 (i8*, i32, i8*)** %7
store i8* %3, i8** %8
%13 = load i32, i32* %6
%14 = add i32 %13, 1
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %10
%18 = alloca i8, i64 %16
store i64 %16, i64* %11
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 -128, i8* %19
store i32 0, i32* %12
br label %20
20: ; preds = %34, %4
%21 = load i32, i32* %12
%22 = load i32, i32* %6
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %37
24: ; preds = %20
%25 = load i8*, i8** %5
%26 = load i32, i32* %12
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = load i32, i32* %12
%31 = add i32 %30, 1
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %18, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %24
%35 = load i32, i32* %12
%36 = add i32 %35, 1
store i32 %36, i32* %12
br label %20
37: ; preds = %20
%38 = load i32 (i8*, i32, i8*)*, i32 (i8*, i32, i8*)** %7
%39 = load i32, i32* %9
%40 = load i8*, i8** %8
%41 = call i32 %38(i8* %18, i32 %39, i8* %40)
%42 = load i8*, i8** %10
ret i32 %41
}

LLVM IR (-O2):
define i32 @setFifoData(i8* nocapture %0, i32 %1, i32 (i8*, i32, i8*)* nocapture %2, i8* %3) {
%5 = add i32 %1, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
store i8 -128, i8* %7
%8 = icmp eq i32 %1, 0
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %9, %4
%13 = call i32 %2(i8* %7, i32 %5, i8* %3)
ret i32 %13
}