; LLVM IR from IOsonata/IOsonata :: src/sensors/mag_sensor.ll (ZN9MagSensor16ClearCalibrationEv)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%class.MagSensor = type { %class.Sensor.base, [3 x i16], i32, %struct.__MagSensor_Raw_Data, [3 x [3 x float]], [3 x float], %class.Device }
%class.Sensor.base = type <{ ptr, i32, i32, i32, i32, i64, i8, [7 x i8], i64, i64, i32, i32, i32, i32, %"struct.std::atomic_flag" }>
%"struct.std::atomic_flag" = type { %"struct.std::__atomic_flag_base" }
%"struct.std::__atomic_flag_base" = type { i8 }
%struct.__MagSensor_Raw_Data = type <{ i64, [3 x i16], %union.anon }>
%union.anon = type { [3 x i32] }
%class.Device = type { ptr, i8, i32, ptr, ptr, i64, i8, ptr, i8, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9MagSensor16ClearCalibrationEv(ptr noundef nonnull align 8 dereferenceable(160) %0) unnamed_addr #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %class.MagSensor, ptr %3, i32 0, i32 5
  %5 = getelementptr inbounds [3 x float], ptr %4, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 4 %5, i8 0, i64 12, i1 false)
  %6 = getelementptr inbounds %class.MagSensor, ptr %3, i32 0, i32 4
  %7 = getelementptr inbounds [3 x [3 x float]], ptr %6, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %7, i8 0, i64 36, i1 false)
  %8 = getelementptr inbounds %class.MagSensor, ptr %3, i32 0, i32 1
  %9 = getelementptr inbounds [3 x i16], ptr %8, i64 0, i64 0
  %10 = load i16, ptr %9, align 2, !tbaa !9
  %11 = zext i16 %10 to i32
  %12 = sitofp i32 %11 to double
  %13 = fdiv double %12, 1.000000e+03
  %14 = fptrunc double %13 to float
  %15 = getelementptr inbounds %class.MagSensor, ptr %3, i32 0, i32 4
  %16 = getelementptr inbounds [3 x [3 x float]], ptr %15, i64 0, i64 0
  %17 = getelementptr inbounds [3 x float], ptr %16, i64 0, i64 0
  store float %14, ptr %17, align 8, !tbaa !11
  %18 = getelementptr inbounds %class.MagSensor, ptr %3, i32 0, i32 1
  %19 = getelementptr inbounds [3 x i16], ptr %18, i64 0, i64 1
  %20 = load i16, ptr %19, align 2, !tbaa !9
  %21 = zext i16 %20 to i32
  %22 = sitofp i32 %21 to double
  %23 = fdiv double %22, 1.000000e+03
  %24 = fptrunc double %23 to float
  %25 = getelementptr inbounds %class.MagSensor, ptr %3, i32 0, i32 4
  %26 = getelementptr inbounds [3 x [3 x float]], ptr %25, i64 0, i64 1
  %27 = getelementptr inbounds [3 x float], ptr %26, i64 0, i64 1
  store float %24, ptr %27, align 4, !tbaa !11
  %28 = getelementptr inbounds %class.MagSensor, ptr %3, i32 0, i32 1
  %29 = getelementptr inbounds [3 x i16], ptr %28, i64 0, i64 2
  %30 = load i16, ptr %29, align 2, !tbaa !9
  %31 = zext i16 %30 to i32
  %32 = sitofp i32 %31 to double
  %33 = fdiv double %32, 1.000000e+03
  %34 = fptrunc double %33 to float
  %35 = getelementptr inbounds %class.MagSensor, ptr %3, i32 0, i32 4
  %36 = getelementptr inbounds [3 x [3 x float]], ptr %35, i64 0, i64 2
  %37 = getelementptr inbounds [3 x float], ptr %36, i64 0, i64 2
  store float %34, ptr %37, align 8, !tbaa !11
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN9MagSensor16ClearCalibrationEv(ptr nocapture noundef nonnull align 8 dereferenceable(160) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 112
  %3 = getelementptr inbounds i8, ptr %0, i64 74
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %2, i8 0, i64 48, i1 false)
  %4 = load i16, ptr %3, align 2, !tbaa !5
  %5 = uitofp i16 %4 to double
  %6 = fdiv double %5, 1.000000e+03
  %7 = fptrunc double %6 to float
  store float %7, ptr %2, align 8, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %0, i64 76
  %9 = load i16, ptr %8, align 4, !tbaa !5
  %10 = uitofp i16 %9 to double
  %11 = fdiv double %10, 1.000000e+03
  %12 = fptrunc double %11 to float
  %13 = getelementptr inbounds i8, ptr %0, i64 128
  store float %12, ptr %13, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %0, i64 78
  %15 = load i16, ptr %14, align 2, !tbaa !5
  %16 = uitofp i16 %15 to double
  %17 = fdiv double %16, 1.000000e+03
  %18 = fptrunc double %17 to float
  %19 = getelementptr inbounds i8, ptr %0, i64 144
  store float %18, ptr %19, align 8, !tbaa !9
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass