; LLVM IR from IOsonata/IOsonata :: src/sensors/accel_sensor.ll (ZN11AccelSensor16ClearCalibrationEv)

; 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.AccelSensor = type <{ %class.Sensor.base, %struct.__AccelSensor_Raw_Data, [5 x i8], ptr, i16, [2 x i8], [3 x [3 x float]], [3 x float], [4 x i8], %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.__AccelSensor_Raw_Data = type <{ i64, i16, i16, %union.anon }>
%union.anon = type { [3 x i16] }
%class.Device = type { ptr, i8, i32, ptr, ptr, i64, i8, ptr, i8, i32 }
%class.Sensor = type <{ ptr, i32, i32, i32, i32, i64, i8, [7 x i8], i64, i64, i32, i32, i32, i32, %"struct.std::atomic_flag", [7 x i8], %class.Device }>

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN11AccelSensor16ClearCalibrationEv(ptr noundef nonnull align 8 dereferenceable(156) %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.AccelSensor, ptr %3, i32 0, i32 7
  %5 = getelementptr inbounds [3 x float], ptr %4, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %5, i8 0, i64 12, i1 false)
  %6 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 6
  %7 = getelementptr inbounds [3 x [3 x float]], ptr %6, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 4 %7, i8 0, i64 36, i1 false)
  %8 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 4
  %9 = load i16, ptr %8, align 8, !tbaa !9
  %10 = zext i16 %9 to i32
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %16, label %12

12:                                               ; preds = %1
  %13 = getelementptr inbounds %class.Sensor, ptr %3, i32 0, i32 13
  %14 = load i32, ptr %13, align 4, !tbaa !21
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %34

16:                                               ; preds = %12, %1
  %17 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 6
  %18 = getelementptr inbounds [3 x [3 x float]], ptr %17, i64 0, i64 0
  %19 = getelementptr inbounds [3 x float], ptr %18, i64 0, i64 0
  store float 1.000000e+00, ptr %19, align 4, !tbaa !22
  %20 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 6
  %21 = getelementptr inbounds [3 x [3 x float]], ptr %20, i64 0, i64 0
  %22 = getelementptr inbounds [3 x float], ptr %21, i64 0, i64 0
  %23 = load float, ptr %22, align 4, !tbaa !22
  %24 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 6
  %25 = getelementptr inbounds [3 x [3 x float]], ptr %24, i64 0, i64 1
  %26 = getelementptr inbounds [3 x float], ptr %25, i64 0, i64 1
  store float %23, ptr %26, align 4, !tbaa !22
  %27 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 6
  %28 = getelementptr inbounds [3 x [3 x float]], ptr %27, i64 0, i64 0
  %29 = getelementptr inbounds [3 x float], ptr %28, i64 0, i64 0
  %30 = load float, ptr %29, align 4, !tbaa !22
  %31 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 6
  %32 = getelementptr inbounds [3 x [3 x float]], ptr %31, i64 0, i64 2
  %33 = getelementptr inbounds [3 x float], ptr %32, i64 0, i64 2
  store float %30, ptr %33, align 4, !tbaa !22
  br label %59

34:                                               ; preds = %12
  %35 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 4
  %36 = load i16, ptr %35, align 8, !tbaa !9
  %37 = uitofp i16 %36 to float
  %38 = getelementptr inbounds %class.Sensor, ptr %3, i32 0, i32 13
  %39 = load i32, ptr %38, align 4, !tbaa !21
  %40 = uitofp i32 %39 to float
  %41 = fdiv float %37, %40
  %42 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 6
  %43 = getelementptr inbounds [3 x [3 x float]], ptr %42, i64 0, i64 0
  %44 = getelementptr inbounds [3 x float], ptr %43, i64 0, i64 0
  store float %41, ptr %44, align 4, !tbaa !22
  %45 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 6
  %46 = getelementptr inbounds [3 x [3 x float]], ptr %45, i64 0, i64 0
  %47 = getelementptr inbounds [3 x float], ptr %46, i64 0, i64 0
  %48 = load float, ptr %47, align 4, !tbaa !22
  %49 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 6
  %50 = getelementptr inbounds [3 x [3 x float]], ptr %49, i64 0, i64 1
  %51 = getelementptr inbounds [3 x float], ptr %50, i64 0, i64 1
  store float %48, ptr %51, align 4, !tbaa !22
  %52 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 6
  %53 = getelementptr inbounds [3 x [3 x float]], ptr %52, i64 0, i64 0
  %54 = getelementptr inbounds [3 x float], ptr %53, i64 0, i64 0
  %55 = load float, ptr %54, align 4, !tbaa !22
  %56 = getelementptr inbounds %class.AccelSensor, ptr %3, i32 0, i32 6
  %57 = getelementptr inbounds [3 x [3 x float]], ptr %56, i64 0, i64 2
  %58 = getelementptr inbounds [3 x float], ptr %57, i64 0, i64 2
  store float %55, ptr %58, align 4, !tbaa !22
  br label %59

59:                                               ; preds = %34, %16
  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, !20, i64 104}
!10 = !{!"_ZTS11AccelSensor", !11, i64 0, !19, i64 73, !6, i64 96, !20, i64 104, !7, i64 108, !7, i64 144}
!11 = !{!"_ZTS6Sensor", !12, i64 8, !13, i64 12, !14, i64 16, !12, i64 20, !15, i64 24, !16, i64 32, !15, i64 40, !15, i64 48, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !17, i64 72}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS14__Sensor_State", !7, i64 0}
!14 = !{!"_ZTS15__Sensor_OpMode", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"_ZTSSt11atomic_flag", !18, i64 0}
!18 = !{!"_ZTSSt18__atomic_flag_base", !16, i64 0}
!19 = !{!"_ZTS22__AccelSensor_Raw_Data", !15, i64 0, !20, i64 8, !20, i64 10, !7, i64 12}
!20 = !{!"short", !7, i64 0}
!21 = !{!11, !12, i64 68}
!22 = !{!23, !23, i64 0}
!23 = !{!"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 @_ZN11AccelSensor16ClearCalibrationEv(ptr nocapture noundef nonnull align 8 dereferenceable(156) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 108
  %3 = getelementptr inbounds i8, ptr %0, i64 104
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(48) %2, i8 0, i64 48, i1 false)
  %4 = load i16, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i16 %4, 0
  br i1 %5, label %14, label %6

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 68
  %8 = load i32, ptr %7, align 4, !tbaa !20
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %14, label %10

10:                                               ; preds = %6
  %11 = uitofp i16 %4 to float
  %12 = uitofp i32 %8 to float
  %13 = fdiv float %11, %12
  br label %14

14:                                               ; preds = %1, %6, %10
  %.sink4 = phi float [ %13, %10 ], [ 1.000000e+00, %6 ], [ 1.000000e+00, %1 ]
  store float %.sink4, ptr %2, align 4, !tbaa !21
  %15 = getelementptr inbounds i8, ptr %0, i64 124
  store float %.sink4, ptr %15, align 4, !tbaa !21
  %16 = getelementptr inbounds i8, ptr %0, i64 140
  store float %.sink4, ptr %16, align 4, !tbaa !21
  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, !18, i64 104}
!6 = !{!"_ZTS11AccelSensor", !7, i64 0, !17, i64 73, !19, i64 96, !18, i64 104, !9, i64 108, !9, i64 144}
!7 = !{!"_ZTS6Sensor", !8, i64 8, !11, i64 12, !12, i64 16, !8, i64 20, !13, i64 24, !14, i64 32, !13, i64 40, !13, i64 48, !8, i64 56, !8, i64 60, !8, i64 64, !8, i64 68, !15, i64 72}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTS14__Sensor_State", !9, i64 0}
!12 = !{!"_ZTS15__Sensor_OpMode", !9, i64 0}
!13 = !{!"long", !9, i64 0}
!14 = !{!"bool", !9, i64 0}
!15 = !{!"_ZTSSt11atomic_flag", !16, i64 0}
!16 = !{!"_ZTSSt18__atomic_flag_base", !14, i64 0}
!17 = !{!"_ZTS22__AccelSensor_Raw_Data", !13, i64 0, !18, i64 8, !18, i64 10, !9, i64 12}
!18 = !{!"short", !9, i64 0}
!19 = !{!"any pointer", !9, i64 0}
!20 = !{!7, !8, i64 68}
!21 = !{!22, !22, i64 0}
!22 = !{!"float", !9, i64 0}


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