int getCarrierFrequency(float *const freq,
                        int (*spiTransfer)(unsigned char *const, unsigned int,
                                           void *const customData),
                        void *const customData) {
  unsigned char data[] = {0x07, 0x00, 0x00, 0x00};
  int res = (*spiTransfer)(data, 4, customData);
  if (res < 0) {
    return res;
  }
  *freq = 32.0 / 524288.0 *
          (((unsigned long)data[1] << 16) + ((unsigned long)data[2] << 8) +
           (unsigned long)data[3]);
  return 0;
}


x86 assembly (clang, -O0):
<getCarrierFrequency>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0xeee(%rip),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
lea    -0x24(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x4,%esi
call   *%rax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1148 <getCarrierFrequency+0x48>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <getCarrierFrequency+0x81>
movzbl -0x23(%rbp),%eax
shl    $0x10,%eax
movzbl -0x22(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl -0x21(%rbp),%ecx
or     %ecx,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe96(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCarrierFrequency>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %rdi,%rbx
movl   $0x7,0xc(%rsp)
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   *%rax
test   %eax,%eax
js     1152 <getCarrierFrequency+0x52>
movzbl 0xd(%rsp),%eax
shl    $0x10,%eax
movzbl 0xe(%rsp),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movzbl 0xf(%rsp),%eax
or     %ecx,%eax
cvtsi2sd %eax,%xmm0
mulsd  0xeb8(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.getCarrierFrequency.data = [4 x i8] c"\07\00\00\00"
define i32 @getCarrierFrequency(float* %0, i32 (i8*, i32, i8*)* %1, i8* %2) {
%4 = alloca i32
%5 = alloca float*
%6 = alloca i32 (i8*, i32, i8*)*
%7 = alloca i8*
%8 = alloca [4 x i8]
%9 = alloca i32
store float* %0, float** %5
store i32 (i8*, i32, i8*)* %1, i32 (i8*, i32, i8*)** %6
store i8* %2, i8** %7
%10 = bitcast [4 x i8]* %8 to i8*
%11 = load i32 (i8*, i32, i8*)*, i32 (i8*, i32, i8*)** %6
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%13 = load i8*, i8** %7
%14 = call i32 %11(i8* %12, i32 4, i8* %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = load i32, i32* %9
store i32 %18, i32* %4
br label %37
19: ; preds = %3
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
%21 = load i8, i8* %20
%22 = zext i8 %21 to i64
%23 = shl i64 %22, 16
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
%25 = load i8, i8* %24
%26 = zext i8 %25 to i64
%27 = shl i64 %26, 8
%28 = add i64 %23, %27
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 3
%30 = load i8, i8* %29
%31 = zext i8 %30 to i64
%32 = add i64 %28, %31
%33 = uitofp i64 %32 to double
%34 = fmul double 0x3F10000000000000, %33
%35 = fptrunc double %34 to float
%36 = load float*, float** %5
store float %35, float* %36
store i32 0, i32* %4
br label %37
37: ; preds = %19, %17
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
define i32 @getCarrierFrequency(float* nocapture writeonly %0, i32 (i8*, i32, i8*)* nocapture %1, i8* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to [4 x i8]*
%6 = bitcast i32* %4 to i8*
store i32 7, i32* %4
%7 = call i32 %1(i8* %6, i32 4, i8* %2)
%8 = icmp slt i32 %7, 0
br i1 %8, label %26, label %9
9: ; preds = %3
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
%11 = load i8, i8* %10
%12 = zext i8 %11 to i64
%13 = shl nuw nsw i64 %12, 16
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
%15 = load i8, i8* %14
%16 = zext i8 %15 to i64
%17 = shl nuw nsw i64 %16, 8
%18 = or i64 %17, %13
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
%20 = load i8, i8* %19
%21 = zext i8 %20 to i64
%22 = or i64 %18, %21
%23 = uitofp i64 %22 to double
%24 = fmul double %23, 0x3F10000000000000
%25 = fptrunc double %24 to float
store float %25, float* %0
br label %26
26: ; preds = %3, %9
%27 = phi i32 [ 0, %9 ], [ %7, %3 ]
ret i32 %27
}