; LLVM IR from IOsonata/IOsonata :: src/sensors/temp_ntc.ll (ZN7TempNtc10UdpateDataEj)

; 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.Device = type { ptr, i8, i32, ptr, ptr, i64, i8, ptr, i8, i32 }
%class.TempSensor = type { %class.Sensor.base, %struct.__TemperatureSensor_Data, ptr, %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.__TemperatureSensor_Data = type <{ i64, i32 }>
%class.TempNtc = type { %class.TempSensor.base, i32, i32, i32, ptr, i64, %class.Device }
%class.TempSensor.base = type { %class.Sensor.base, %struct.__TemperatureSensor_Data, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @LookupNtcTemp(i32 noundef, ptr noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7TempNtc10UdpateDataEj(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = getelementptr i8, ptr %6, i64 -24
  %8 = load i64, ptr %7, align 8
  %9 = getelementptr inbounds i8, ptr %5, i64 %8
  %10 = getelementptr inbounds %class.Device, ptr %9, i32 0, i32 4
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %27

13:                                               ; preds = %2
  %14 = load ptr, ptr %5, align 8, !tbaa !11
  %15 = getelementptr i8, ptr %14, i64 -24
  %16 = load i64, ptr %15, align 8
  %17 = getelementptr inbounds i8, ptr %5, i64 %16
  %18 = getelementptr inbounds %class.Device, ptr %17, i32 0, i32 4
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds ptr, ptr %20, i64 14
  %22 = load ptr, ptr %21, align 8
  %23 = call noundef i32 %22(ptr noundef nonnull align 8 dereferenceable(140) %19)
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds %class.TempSensor, ptr %5, i32 0, i32 1
  %26 = getelementptr inbounds %struct.__TemperatureSensor_Data, ptr %25, i32 0, i32 0
  store i64 %24, ptr %26, align 1, !tbaa !18
  br label %27

27:                                               ; preds = %13, %2
  %28 = getelementptr inbounds %class.TempNtc, ptr %5, i32 0, i32 4
  %29 = load ptr, ptr %28, align 8, !tbaa !26
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %40

31:                                               ; preds = %27
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = getelementptr inbounds %class.TempNtc, ptr %5, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !26
  %35 = getelementptr inbounds %class.TempNtc, ptr %5, i32 0, i32 5
  %36 = load i64, ptr %35, align 8, !tbaa !28
  %37 = call i32 @LookupNtcTemp(i32 noundef %32, ptr noundef %34, i64 noundef %36)
  %38 = getelementptr inbounds %class.TempSensor, ptr %5, i32 0, i32 1
  %39 = getelementptr inbounds %struct.__TemperatureSensor_Data, ptr %38, i32 0, i32 1
  store i32 %37, ptr %39, align 1, !tbaa !29
  br label %49

40:                                               ; preds = %27
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = getelementptr inbounds %class.TempNtc, ptr %5, i32 0, i32 2
  %43 = load i32, ptr %42, align 4, !tbaa !30
  %44 = getelementptr inbounds %class.TempNtc, ptr %5, i32 0, i32 3
  %45 = load i32, ptr %44, align 8, !tbaa !31
  %46 = call noundef i32 @_ZL11CalcNtcTempjjj(i32 noundef %41, i32 noundef %43, i32 noundef %45)
  %47 = getelementptr inbounds %class.TempSensor, ptr %5, i32 0, i32 1
  %48 = getelementptr inbounds %struct.__TemperatureSensor_Data, ptr %47, i32 0, i32 1
  store i32 %46, ptr %48, align 1, !tbaa !29
  br label %49

49:                                               ; preds = %40, %31
  %50 = getelementptr inbounds %class.TempSensor, ptr %5, i32 0, i32 1
  %51 = getelementptr inbounds %struct.__TemperatureSensor_Data, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 1, !tbaa !29
  ret i32 %52
}

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i32 @_ZL11CalcNtcTempjjj(i32 noundef, i32 noundef, i32 noundef) #2

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 = { mustprogress 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 #2 = { inlinehint mustprogress 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, !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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"_ZTS6Device", !15, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !16, i64 32, !15, i64 40, !6, i64 48, !7, i64 56, !17, i64 60}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTS21__Dev_Data_Byte_Order", !7, i64 0}
!18 = !{!19, !16, i64 73}
!19 = !{!"_ZTS10TempSensor", !20, i64 0, !25, i64 73, !6, i64 88}
!20 = !{!"_ZTS6Sensor", !10, i64 8, !21, i64 12, !22, i64 16, !10, i64 20, !16, i64 24, !15, i64 32, !16, i64 40, !16, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !23, i64 72}
!21 = !{!"_ZTS14__Sensor_State", !7, i64 0}
!22 = !{!"_ZTS15__Sensor_OpMode", !7, i64 0}
!23 = !{!"_ZTSSt11atomic_flag", !24, i64 0}
!24 = !{!"_ZTSSt18__atomic_flag_base", !15, i64 0}
!25 = !{!"_ZTS24__TemperatureSensor_Data", !16, i64 0, !10, i64 8}
!26 = !{!27, !6, i64 112}
!27 = !{!"_ZTS7TempNtc", !19, i64 0, !10, i64 96, !10, i64 100, !10, i64 104, !6, i64 112, !16, i64 120}
!28 = !{!27, !16, i64 120}
!29 = !{!19, !10, i64 81}
!30 = !{!27, !10, i64 100}
!31 = !{!27, !10, i64 104}


; 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 nounwind uwtable
declare dso_local i32 @LookupNtcTemp(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7TempNtc10UdpateDataEj(ptr nocapture noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr i8, ptr %3, i64 -24
  %5 = load i64, ptr %4, align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 %5
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !8
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %16, label %9

9:                                                ; preds = %2
  %10 = load ptr, ptr %8, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 112
  %12 = load ptr, ptr %11, align 8
  %13 = tail call noundef i32 %12(ptr noundef nonnull align 8 dereferenceable(140) %8)
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %0, i64 73
  store i64 %14, ptr %15, align 1, !tbaa !16
  br label %16

16:                                               ; preds = %9, %2
  %17 = getelementptr inbounds i8, ptr %0, i64 112
  %18 = load ptr, ptr %17, align 8, !tbaa !24
  %.not3 = icmp eq ptr %18, null
  br i1 %.not3, label %23, label %19

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %0, i64 120
  %21 = load i64, ptr %20, align 8, !tbaa !26
  %22 = tail call i32 @LookupNtcTemp(i32 noundef %1, ptr noundef nonnull %18, i64 noundef %21)
  br label %29

23:                                               ; preds = %16
  %24 = getelementptr inbounds i8, ptr %0, i64 100
  %25 = load i32, ptr %24, align 4, !tbaa !27
  %26 = getelementptr inbounds i8, ptr %0, i64 104
  %27 = load i32, ptr %26, align 8, !tbaa !28
  %28 = tail call noundef i32 @_ZL11CalcNtcTempjjj(i32 noundef %1, i32 noundef %25, i32 noundef %27)
  br label %29

29:                                               ; preds = %23, %19
  %.sink = phi i32 [ %28, %23 ], [ %22, %19 ]
  %30 = getelementptr inbounds i8, ptr %0, i64 81
  store i32 %.sink, ptr %30, align 1
  ret i32 %.sink
}

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i32 @_ZL11CalcNtcTempjjj(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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 = { mustprogress 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 #2 = { inlinehint mustprogress 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, !6, i64 0}
!6 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !13, i64 24}
!9 = !{!"_ZTS6Device", !10, i64 8, !12, i64 12, !13, i64 16, !13, i64 24, !14, i64 32, !10, i64 40, !13, i64 48, !11, i64 56, !15, i64 60}
!10 = !{!"bool", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"int", !11, i64 0}
!13 = !{!"any pointer", !11, i64 0}
!14 = !{!"long", !11, i64 0}
!15 = !{!"_ZTS21__Dev_Data_Byte_Order", !11, i64 0}
!16 = !{!17, !14, i64 73}
!17 = !{!"_ZTS10TempSensor", !18, i64 0, !23, i64 73, !13, i64 88}
!18 = !{!"_ZTS6Sensor", !12, i64 8, !19, i64 12, !20, i64 16, !12, i64 20, !14, i64 24, !10, i64 32, !14, i64 40, !14, i64 48, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !21, i64 72}
!19 = !{!"_ZTS14__Sensor_State", !11, i64 0}
!20 = !{!"_ZTS15__Sensor_OpMode", !11, i64 0}
!21 = !{!"_ZTSSt11atomic_flag", !22, i64 0}
!22 = !{!"_ZTSSt18__atomic_flag_base", !10, i64 0}
!23 = !{!"_ZTS24__TemperatureSensor_Data", !14, i64 0, !12, i64 8}
!24 = !{!25, !13, i64 112}
!25 = !{!"_ZTS7TempNtc", !17, i64 0, !12, i64 96, !12, i64 100, !12, i64 104, !13, i64 112, !14, i64 120}
!26 = !{!25, !14, i64 120}
!27 = !{!25, !12, i64 100}
!28 = !{!25, !12, i64 104}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass