; LLVM IR from IOsonata/IOsonata :: src/sensors/ag_icm456x.ll (ZN9AgIcm456x10UpdateDataEv)

; 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.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.GyroSensor = type { %class.Sensor.base, i16, %struct.__GyroSensor_Raw_Data, [3 x [3 x float]], [3 x float], %class.Device }
%struct.__GyroSensor_Raw_Data = type <{ i64, i16, i16, %union.anon.0 }>
%union.anon.0 = type { [3 x i16] }

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN9AgIcm456x10UpdateDataEv(ptr noundef nonnull align 8 dereferenceable(420) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca [16 x i8], align 16
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  store i8 0, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = load ptr, ptr %7, align 8, !tbaa !10
  %9 = getelementptr i8, ptr %8, i64 -24
  %10 = load i64, ptr %9, align 8
  %11 = getelementptr inbounds i8, ptr %7, i64 %10
  %12 = getelementptr inbounds %class.Device, ptr %11, i32 0, i32 4
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = load ptr, ptr %13, align 8, !tbaa !10
  %15 = getelementptr inbounds ptr, ptr %14, i64 14
  %16 = load ptr, ptr %15, align 8
  %17 = call noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(140) %13)
  %18 = zext i32 %17 to i64
  store i64 %18, ptr %5, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %19 = load ptr, ptr %7, align 8, !tbaa !10
  %20 = getelementptr i8, ptr %19, i64 -24
  %21 = load i64, ptr %20, align 8
  %22 = getelementptr inbounds i8, ptr %7, i64 %21
  %23 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 0
  %24 = call noundef i32 @_ZN6Device4ReadEPhiS0_i(ptr noundef nonnull align 8 dereferenceable(64) %22, ptr noundef %3, i32 noundef 1, ptr noundef %23, i32 noundef 14)
  store i32 %24, ptr %6, align 4, !tbaa !19
  %25 = load i32, ptr %6, align 4, !tbaa !19
  %26 = icmp sgt i32 %25, 5
  br i1 %26, label %27, label %48

27:                                               ; preds = %1
  %28 = load i64, ptr %5, align 8, !tbaa !18
  %29 = getelementptr inbounds %class.AccelSensor, ptr %7, i32 0, i32 1
  %30 = getelementptr inbounds %struct.__AccelSensor_Raw_Data, ptr %29, i32 0, i32 0
  store i64 %28, ptr %30, align 1, !tbaa !20
  %31 = getelementptr inbounds %class.AccelSensor, ptr %7, i32 0, i32 1
  %32 = getelementptr inbounds %struct.__AccelSensor_Raw_Data, ptr %31, i32 0, i32 3
  %33 = getelementptr inbounds [3 x i16], ptr %32, i64 0, i64 0
  %34 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %33, ptr align 16 %34, i64 6, i1 false)
  %35 = load i32, ptr %6, align 4, !tbaa !19
  %36 = icmp sgt i32 %35, 10
  br i1 %36, label %37, label %47

37:                                               ; preds = %27
  %38 = load i64, ptr %5, align 8, !tbaa !18
  %39 = getelementptr inbounds i8, ptr %7, i64 160
  %40 = getelementptr inbounds %class.GyroSensor, ptr %39, i32 0, i32 2
  %41 = getelementptr inbounds %struct.__GyroSensor_Raw_Data, ptr %40, i32 0, i32 0
  store i64 %38, ptr %41, align 4, !tbaa !29
  %42 = getelementptr inbounds i8, ptr %7, i64 160
  %43 = getelementptr inbounds %class.GyroSensor, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds %struct.__GyroSensor_Raw_Data, ptr %43, i32 0, i32 3
  %45 = getelementptr inbounds [3 x i16], ptr %44, i64 0, i64 0
  %46 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %45, ptr align 2 %46, i64 6, i1 false)
  br label %47

47:                                               ; preds = %37, %27
  br label %48

48:                                               ; preds = %47, %1
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #4
  ret i1 false
}

declare noundef i32 @_ZN6Device4ReadEPhiS0_i(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef, i32 noundef, ptr noundef, i32 noundef) unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"vtable pointer", !8, i64 0}
!12 = !{!13, !6, i64 24}
!13 = !{!"_ZTS6Device", !14, i64 8, !15, i64 12, !6, i64 16, !6, i64 24, !16, i64 32, !14, i64 40, !6, i64 48, !7, i64 56, !17, i64 60}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTS21__Dev_Data_Byte_Order", !7, i64 0}
!18 = !{!16, !16, i64 0}
!19 = !{!15, !15, i64 0}
!20 = !{!21, !16, i64 73}
!21 = !{!"_ZTS11AccelSensor", !22, i64 0, !27, i64 73, !6, i64 96, !28, i64 104, !7, i64 108, !7, i64 144}
!22 = !{!"_ZTS6Sensor", !15, i64 8, !23, i64 12, !24, i64 16, !15, i64 20, !16, i64 24, !14, i64 32, !16, i64 40, !16, i64 48, !15, i64 56, !15, i64 60, !15, i64 64, !15, i64 68, !25, i64 72}
!23 = !{!"_ZTS14__Sensor_State", !7, i64 0}
!24 = !{!"_ZTS15__Sensor_OpMode", !7, i64 0}
!25 = !{!"_ZTSSt11atomic_flag", !26, i64 0}
!26 = !{!"_ZTSSt18__atomic_flag_base", !14, i64 0}
!27 = !{!"_ZTS22__AccelSensor_Raw_Data", !16, i64 0, !28, i64 8, !28, i64 10, !7, i64 12}
!28 = !{!"short", !7, i64 0}
!29 = !{!30, !16, i64 76}
!30 = !{!"_ZTS10GyroSensor", !22, i64 0, !28, i64 74, !31, i64 76, !7, i64 96, !7, i64 132}
!31 = !{!"_ZTS21__GyroSensor_Raw_Data", !16, i64 0, !28, i64 8, !28, i64 10, !7, i64 12}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN9AgIcm456x10UpdateDataEv(ptr noundef nonnull align 8 dereferenceable(420) %0) unnamed_addr #1 align 2 {
  %2 = alloca i8, align 1
  %3 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #4
  store i8 0, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %4 = load ptr, ptr %0, align 8, !tbaa !8
  %5 = getelementptr i8, ptr %4, i64 -24
  %6 = load i64, ptr %5, align 8
  %7 = getelementptr inbounds i8, ptr %0, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !10
  %10 = load ptr, ptr %9, align 8, !tbaa !8
  %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) %9)
  %14 = zext i32 %13 to i64
  %15 = load ptr, ptr %0, align 8, !tbaa !8
  %16 = getelementptr i8, ptr %15, i64 -24
  %17 = load i64, ptr %16, align 8
  %18 = getelementptr inbounds i8, ptr %0, i64 %17
  %19 = call noundef i32 @_ZN6Device4ReadEPhiS0_i(ptr noundef nonnull align 8 dereferenceable(64) %18, ptr noundef nonnull %2, i32 noundef 1, ptr noundef nonnull %3, i32 noundef 14)
  %20 = icmp sgt i32 %19, 5
  br i1 %20, label %21, label %29

21:                                               ; preds = %1
  %22 = getelementptr inbounds i8, ptr %0, i64 73
  store i64 %14, ptr %22, align 1, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %0, i64 85
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %23, ptr noundef nonnull align 16 dereferenceable(6) %3, i64 6, i1 false)
  %24 = icmp ugt i32 %19, 10
  br i1 %24, label %25, label %29

25:                                               ; preds = %21
  %26 = getelementptr inbounds i8, ptr %0, i64 236
  store i64 %14, ptr %26, align 4, !tbaa !26
  %27 = getelementptr inbounds i8, ptr %0, i64 248
  %28 = getelementptr inbounds i8, ptr %3, i64 6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(6) %27, ptr noundef nonnull align 2 dereferenceable(6) %28, i64 6, i1 false)
  br label %29

29:                                               ; preds = %21, %25, %1
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #4
  ret i1 false
}

declare noundef i32 @_ZN6Device4ReadEPhiS0_i(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef, i32 noundef, ptr noundef, i32 noundef) unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"vtable pointer", !7, i64 0}
!10 = !{!11, !14, i64 24}
!11 = !{!"_ZTS6Device", !12, i64 8, !13, i64 12, !14, i64 16, !14, i64 24, !15, i64 32, !12, i64 40, !14, i64 48, !6, i64 56, !16, i64 60}
!12 = !{!"bool", !6, i64 0}
!13 = !{!"int", !6, i64 0}
!14 = !{!"any pointer", !6, i64 0}
!15 = !{!"long", !6, i64 0}
!16 = !{!"_ZTS21__Dev_Data_Byte_Order", !6, i64 0}
!17 = !{!18, !15, i64 73}
!18 = !{!"_ZTS11AccelSensor", !19, i64 0, !24, i64 73, !14, i64 96, !25, i64 104, !6, i64 108, !6, i64 144}
!19 = !{!"_ZTS6Sensor", !13, i64 8, !20, i64 12, !21, i64 16, !13, i64 20, !15, i64 24, !12, i64 32, !15, i64 40, !15, i64 48, !13, i64 56, !13, i64 60, !13, i64 64, !13, i64 68, !22, i64 72}
!20 = !{!"_ZTS14__Sensor_State", !6, i64 0}
!21 = !{!"_ZTS15__Sensor_OpMode", !6, i64 0}
!22 = !{!"_ZTSSt11atomic_flag", !23, i64 0}
!23 = !{!"_ZTSSt18__atomic_flag_base", !12, i64 0}
!24 = !{!"_ZTS22__AccelSensor_Raw_Data", !15, i64 0, !25, i64 8, !25, i64 10, !6, i64 12}
!25 = !{!"short", !6, i64 0}
!26 = !{!27, !15, i64 76}
!27 = !{!"_ZTS10GyroSensor", !19, i64 0, !25, i64 74, !28, i64 76, !6, i64 96, !6, i64 132}
!28 = !{!"_ZTS21__GyroSensor_Raw_Data", !15, i64 0, !25, i64 8, !25, i64 10, !6, i64 12}


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