float read_float32(char **p_base, char *p_end) {
  if (p_end < (*p_base + sizeof(float))) {
    msg2(322,
         "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
         "2022-01-22/02-19-57/repos/felixe/ccsVermont/refs/heads/"
         "http-aggregation/src/common/ipfixlolib/encoding.c",
         __PRETTY_FUNCTION__, __func__, 2,
         "error in read_float32: buffer too small!");
    return -1;
  }
  float f = 2.1;
  char *p_float = (char *)&f;
  char *p_pos = *p_base;
  p_float[3] = *p_pos;
  p_float[2] = *(p_pos + 1);
  p_float[1] = *(p_pos + 2);
  p_float[0] = *(p_pos + 3);
  return f;
}


x86 assembly (clang, -O0):
<read_float32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
add    $0x4,%rcx
cmp    %rcx,%rax
jae    1178 <read_float32+0x68>
mov    $0x142,%edi
lea    0xec4(%rip),%rsi
lea    0xf66(%rip),%rdx
lea    0xf83(%rip),%rcx
mov    $0x2,%r8d
lea    0xf83(%rip),%r9
mov    $0x0,%al
call   1030 <msg2@plt>
movss  0xe96(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11d8 <read_float32+0xc8>
movss  0xe80(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
lea    -0x1c(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x30(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x30(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x30(%rbp),%rax
mov    0x3(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_float32>:
push   %rax
mov    (%rdi),%rax
lea    0x4(%rax),%rcx
cmp    %rsi,%rcx
jbe    1155 <read_float32+0x45>
lea    0xee0(%rip),%rsi
lea    0xf82(%rip),%rdx
lea    0xf9f(%rip),%rcx
lea    0xfa5(%rip),%r9
mov    $0x142,%edi
mov    $0x2,%r8d
xor    %eax,%eax
call   1030 <msg2@plt>
movss  0xead(%rip),%xmm0
pop    %rax
ret
mov    (%rax),%eax
bswap  %eax
movd   %eax,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [169 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/felixe/ccsVermont/refs/heads/http-aggregation/src/common/ipfixlolib/encoding.c\00"
@__PRETTY_FUNCTION__.read_float32 = [36 x i8] c"float read_float32(char **, char *)\00"
@__func__.read_float32 = [13 x i8] c"read_float32\00"
@.str.1 = [41 x i8] c"error in read_float32: buffer too small!\00"
define float @read_float32(i8** %0, i8* %1) {
%3 = alloca float
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca float
%7 = alloca i8*
%8 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = load i8**, i8*** %4
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8, i8* %11, i64 4
%13 = icmp ult i8* %9, %12
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i32, i8*, i8*, i8*, i32, i8*, ...) bitcast (i32 (...)* @msg2 to i32 (i32, i8*, i8*, i8*, i32, i8*, ...)*)(i32 322, i8* getelementptr inbounds ([169 x i8], [169 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @__PRETTY_FUNCTION__.read_float32, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__func__.read_float32, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store float -1.000000e+00, float* %3
br label %40
16: ; preds = %2
store float 0x4000CCCCC0000000, float* %6
%17 = bitcast float* %6 to i8*
store i8* %17, i8** %7
%18 = load i8**, i8*** %4
%19 = load i8*, i8** %18
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i64 3
store i8 %21, i8* %23
%24 = load i8*, i8** %8
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = load i8*, i8** %7
%28 = getelementptr inbounds i8, i8* %27, i64 2
store i8 %26, i8* %28
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 2
%31 = load i8, i8* %30
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8 %31, i8* %33
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i64 3
%36 = load i8, i8* %35
%37 = load i8*, i8** %7
%38 = getelementptr inbounds i8, i8* %37, i64 0
store i8 %36, i8* %38
%39 = load float, float* %6
store float %39, float* %3
br label %40
40: ; preds = %16, %14
%41 = load float, float* %3
ret float %41
}

LLVM IR (-O2):
@.str = [169 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/felixe/ccsVermont/refs/heads/http-aggregation/src/common/ipfixlolib/encoding.c\00"
@__PRETTY_FUNCTION__.read_float32 = [36 x i8] c"float read_float32(char **, char *)\00"
@__func__.read_float32 = [13 x i8] c"read_float32\00"
@.str.1 = [41 x i8] c"error in read_float32: buffer too small!\00"
define float @read_float32(i8** nocapture %0, i8* readnone %1) {
%3 = load i8*, i8** %0
%4 = getelementptr inbounds i8, i8* %3, i64 4
%5 = icmp ugt i8* %4, %1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i32, i8*, i8*, i8*, i32, i8*, ...) bitcast (i32 (...)* @msg2 to i32 (i32, i8*, i8*, i8*, i32, i8*, ...)*)(i32 322, i8* getelementptr inbounds ([169 x i8], [169 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @__PRETTY_FUNCTION__.read_float32, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__func__.read_float32, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %27
8: ; preds = %2
%9 = load i8, i8* %3
%10 = zext i8 %9 to i32
%11 = shl nuw i32 %10, 24
%12 = getelementptr inbounds i8, i8* %3, i64 1
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = shl nuw nsw i32 %14, 16
%16 = or i32 %15, %11
%17 = getelementptr inbounds i8, i8* %3, i64 2
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = shl nuw nsw i32 %19, 8
%21 = or i32 %16, %20
%22 = getelementptr inbounds i8, i8* %3, i64 3
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = or i32 %21, %24
%26 = bitcast i32 %25 to float
br label %27
27: ; preds = %8, %6
%28 = phi float [ -1.000000e+00, %6 ], [ %26, %8 ]
ret float %28
}