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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i16 @_ZN11AccelSensor5ScaleEt(ptr noundef nonnull align 8 dereferenceable(156) %0, i16 noundef zeroext %1) unnamed_addr #0 align 2 {
  %3 = alloca i16, align 2
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store float 0.000000e+00, ptr %6, align 4, !tbaa !11
  %10 = getelementptr inbounds %class.Sensor, ptr %9, i32 0, i32 13
  %11 = load i32, ptr %10, align 4, !tbaa !13
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store i16 0, ptr %3, align 2
  store i32 1, ptr %7, align 4
  br label %78

14:                                               ; preds = %2
  %15 = getelementptr inbounds %class.AccelSensor, ptr %9, i32 0, i32 4
  %16 = load i16, ptr %15, align 8, !tbaa !22
  %17 = zext i16 %16 to i32
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %26

19:                                               ; preds = %14
  %20 = load i16, ptr %5, align 2, !tbaa !9
  %21 = uitofp i16 %20 to float
  %22 = getelementptr inbounds %class.AccelSensor, ptr %9, i32 0, i32 4
  %23 = load i16, ptr %22, align 8, !tbaa !22
  %24 = uitofp i16 %23 to float
  %25 = fdiv float %21, %24
  store float %25, ptr %6, align 4, !tbaa !11
  br label %33

26:                                               ; preds = %14
  %27 = load i16, ptr %5, align 2, !tbaa !9
  %28 = uitofp i16 %27 to float
  %29 = getelementptr inbounds %class.Sensor, ptr %9, i32 0, i32 13
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = uitofp i32 %30 to float
  %32 = fdiv float %28, %31
  store float %32, ptr %6, align 4, !tbaa !11
  br label %33

33:                                               ; preds = %26, %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !25
  br label %34

34:                                               ; preds = %70, %33
  %35 = load i32, ptr %8, align 4, !tbaa !25
  %36 = icmp slt i32 %35, 3
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %73

38:                                               ; preds = %34
  %39 = load float, ptr %6, align 4, !tbaa !11
  %40 = getelementptr inbounds %class.AccelSensor, ptr %9, i32 0, i32 6
  %41 = getelementptr inbounds [3 x [3 x float]], ptr %40, i64 0, i64 0
  %42 = load i32, ptr %8, align 4, !tbaa !25
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [3 x float], ptr %41, i64 0, i64 %43
  %45 = load float, ptr %44, align 4, !tbaa !11
  %46 = fmul float %45, %39
  store float %46, ptr %44, align 4, !tbaa !11
  %47 = load float, ptr %6, align 4, !tbaa !11
  %48 = getelementptr inbounds %class.AccelSensor, ptr %9, i32 0, i32 6
  %49 = getelementptr inbounds [3 x [3 x float]], ptr %48, i64 0, i64 1
  %50 = load i32, ptr %8, align 4, !tbaa !25
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [3 x float], ptr %49, i64 0, i64 %51
  %53 = load float, ptr %52, align 4, !tbaa !11
  %54 = fmul float %53, %47
  store float %54, ptr %52, align 4, !tbaa !11
  %55 = load float, ptr %6, align 4, !tbaa !11
  %56 = getelementptr inbounds %class.AccelSensor, ptr %9, i32 0, i32 6
  %57 = getelementptr inbounds [3 x [3 x float]], ptr %56, i64 0, i64 2
  %58 = load i32, ptr %8, align 4, !tbaa !25
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [3 x float], ptr %57, i64 0, i64 %59
  %61 = load float, ptr %60, align 4, !tbaa !11
  %62 = fmul float %61, %55
  store float %62, ptr %60, align 4, !tbaa !11
  %63 = load float, ptr %6, align 4, !tbaa !11
  %64 = getelementptr inbounds %class.AccelSensor, ptr %9, i32 0, i32 7
  %65 = load i32, ptr %8, align 4, !tbaa !25
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [3 x float], ptr %64, i64 0, i64 %66
  %68 = load float, ptr %67, align 4, !tbaa !11
  %69 = fmul float %68, %63
  store float %69, ptr %67, align 4, !tbaa !11
  br label %70

70:                                               ; preds = %38
  %71 = load i32, ptr %8, align 4, !tbaa !25
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %8, align 4, !tbaa !25
  br label %34, !llvm.loop !26

73:                                               ; preds = %37
  %74 = load i16, ptr %5, align 2, !tbaa !9
  %75 = getelementptr inbounds %class.AccelSensor, ptr %9, i32 0, i32 4
  store i16 %74, ptr %75, align 8, !tbaa !22
  %76 = getelementptr inbounds %class.AccelSensor, ptr %9, i32 0, i32 4
  %77 = load i16, ptr %76, align 8, !tbaa !22
  store i16 %77, ptr %3, align 2
  store i32 1, ptr %7, align 4
  br label %78

78:                                               ; preds = %73, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %79 = load i16, ptr %3, align 2
  ret i16 %79
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!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}
!13 = !{!14, !15, i64 68}
!14 = !{!"_ZTS6Sensor", !15, i64 8, !16, i64 12, !17, i64 16, !15, i64 20, !18, i64 24, !19, i64 32, !18, i64 40, !18, i64 48, !15, i64 56, !15, i64 60, !15, i64 64, !15, i64 68, !20, i64 72}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTS14__Sensor_State", !7, i64 0}
!17 = !{!"_ZTS15__Sensor_OpMode", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!"bool", !7, i64 0}
!20 = !{!"_ZTSSt11atomic_flag", !21, i64 0}
!21 = !{!"_ZTSSt18__atomic_flag_base", !19, i64 0}
!22 = !{!23, !10, i64 104}
!23 = !{!"_ZTS11AccelSensor", !14, i64 0, !24, i64 73, !6, i64 96, !10, i64 104, !7, i64 108, !7, i64 144}
!24 = !{!"_ZTS22__AccelSensor_Raw_Data", !18, i64 0, !10, i64 8, !10, i64 10, !7, i64 12}
!25 = !{!15, !15, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}


; 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 noundef zeroext i16 @_ZN11AccelSensor5ScaleEt(ptr nocapture noundef nonnull align 8 dereferenceable(156) %0, i16 noundef zeroext %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 68
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %24, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 104
  %8 = load i16, ptr %7, align 8, !tbaa !16
  %.not = icmp eq i16 %8, 0
  %9 = uitofp i16 %1 to float
  %10 = uitofp i32 %4 to float
  %11 = uitofp i16 %8 to float
  %.sink = select i1 %.not, float %10, float %11
  %12 = fdiv float %9, %.sink
  %13 = getelementptr inbounds i8, ptr %0, i64 108
  %14 = getelementptr inbounds i8, ptr %0, i64 124
  %15 = load <4 x float>, ptr %13, align 4, !tbaa !21
  %16 = insertelement <4 x float> poison, float %12, i64 0
  %17 = shufflevector <4 x float> %16, <4 x float> poison, <4 x i32> zeroinitializer
  %18 = fmul <4 x float> %17, %15
  store <4 x float> %18, ptr %13, align 4, !tbaa !21
  %19 = load <4 x float>, ptr %14, align 4, !tbaa !21
  %20 = fmul <4 x float> %17, %19
  store <4 x float> %20, ptr %14, align 4, !tbaa !21
  %21 = getelementptr inbounds i8, ptr %0, i64 140
  %22 = load <4 x float>, ptr %21, align 4, !tbaa !21
  %23 = fmul <4 x float> %17, %22
  store <4 x float> %23, ptr %21, align 4, !tbaa !21
  store i16 %1, ptr %7, align 8, !tbaa !16
  br label %24

24:                                               ; preds = %2, %6
  %.015 = phi i16 [ %1, %6 ], [ 0, %2 ]
  ret i16 %.015
}

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" }

!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, !7, i64 68}
!6 = !{!"_ZTS6Sensor", !7, i64 8, !10, i64 12, !11, i64 16, !7, i64 20, !12, i64 24, !13, i64 32, !12, i64 40, !12, i64 48, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !14, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS14__Sensor_State", !8, i64 0}
!11 = !{!"_ZTS15__Sensor_OpMode", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!"_ZTSSt11atomic_flag", !15, i64 0}
!15 = !{!"_ZTSSt18__atomic_flag_base", !13, i64 0}
!16 = !{!17, !19, i64 104}
!17 = !{!"_ZTS11AccelSensor", !6, i64 0, !18, i64 73, !20, i64 96, !19, i64 104, !8, i64 108, !8, i64 144}
!18 = !{!"_ZTS22__AccelSensor_Raw_Data", !12, i64 0, !19, i64 8, !19, i64 10, !8, i64 12}
!19 = !{!"short", !8, i64 0}
!20 = !{!"any pointer", !8, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"float", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass