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

/* Variables and functions */
scalar_t__ FLT_MAX;
int /*<<< orphan*/ utils_doubleCopy(int /*<<< orphan*/ *, double *);
int /*<<< orphan*/ utils_int32Copy(int /*<<< orphan*/ *, float *);
size_t prv_encodeFloat(double data, uint8_t *data_buffer) {
  size_t length = 0;
  if ((data < 0.0 - (double)FLT_MAX) || (data > (double)FLT_MAX)) {
    length = 8;
    utils_doubleCopy(data_buffer, &data);
  } else {
    float value;
    length = 4;
    value = (float)data;
    utils_int32Copy(data_buffer, &value);
  }
  return length;
}


x86 assembly (clang, -O0):
<prv_encodeFloat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm1
mov    0x2ea3(%rip),%rax
cvtsi2sdq (%rax),%xmm2
xorps  %xmm0,%xmm0
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
ja     1176 <prv_encodeFloat+0x56>
movsd  -0x8(%rbp),%xmm0
mov    0x2e81(%rip),%rax
cvtsi2sdq (%rax),%xmm1
ucomisd %xmm1,%xmm0
jbe    1190 <prv_encodeFloat+0x70>
movq   $0x8,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <utils_doubleCopy@plt>
jmp    11b3 <prv_encodeFloat+0x93>
movq   $0x4,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1030 <utils_int32Copy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prv_encodeFloat>:
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
mov    0x2eb7(%rip),%rax
cvtsi2sdq (%rax),%xmm1
ucomisd %xmm1,%xmm0
ja     1168 <prv_encodeFloat+0x48>
xorpd  %xmm2,%xmm2
subsd  %xmm1,%xmm2
ucomisd %xmm0,%xmm2
ja     1168 <prv_encodeFloat+0x48>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
lea    0xc(%rsp),%rsi
call   1030 <utils_int32Copy@plt>
mov    $0x4,%eax
add    $0x18,%rsp
ret
lea    0x10(%rsp),%rsi
call   1040 <utils_doubleCopy@plt>
mov    $0x8,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@FLT_MAX = global i64 0
define i64 @prv_encodeFloat(double %0, i32* %1) {
%3 = alloca double
%4 = alloca i32*
%5 = alloca i64
%6 = alloca float
store double %0, double* %3
store i32* %1, i32** %4
store i64 0, i64* %5
%7 = load double, double* %3
%8 = load i64, i64* @FLT_MAX
%9 = sitofp i64 %8 to double
%10 = fsub double 0.000000e+00, %9
%11 = fcmp olt double %7, %10
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load double, double* %3
%14 = load i64, i64* @FLT_MAX
%15 = sitofp i64 %14 to double
%16 = fcmp ogt double %13, %15
br i1 %16, label %17, label %20
17: ; preds = %12, %2
store i64 8, i64* %5
%18 = load i32*, i32** %4
%19 = call i32 @utils_doubleCopy(i32* %18, double* %3)
br label %25
20: ; preds = %12
store i64 4, i64* %5
%21 = load double, double* %3
%22 = fptrunc double %21 to float
store float %22, float* %6
%23 = load i32*, i32** %4
%24 = call i32 @utils_int32Copy(i32* %23, float* %6)
br label %25
25: ; preds = %20, %17
%26 = load i64, i64* %5
ret i64 %26
}

LLVM IR (-O2):
@FLT_MAX = global i64 0
define i64 @prv_encodeFloat(double %0, i32* %1) {
%3 = alloca double
%4 = alloca float
store double %0, double* %3
%5 = load i64, i64* @FLT_MAX
%6 = sitofp i64 %5 to double
%7 = fsub double 0.000000e+00, %6
%8 = fcmp ogt double %7, %0
%9 = fcmp olt double %6, %0
%10 = or i1 %9, %8
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @utils_doubleCopy(i32* %1, double* %3)
br label %17
13: ; preds = %2
%14 = bitcast float* %4 to i8*
%15 = fptrunc double %0 to float
store float %15, float* %4
%16 = call i32 @utils_int32Copy(i32* %1, float* %4)
br label %17
17: ; preds = %13, %11
%18 = phi i64 [ 8, %11 ], [ 4, %13 ]
ret i64 %18
}