; LLVM IR from IOsonata/IOsonata :: src/imu (imu_mpu9250)

; 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.ImuMpu9250 = type <{ %class.Imu.base, [4 x i8], ptr, i32, [4 x i8], %class.Device }>
%class.Imu.base = type <{ ptr, ptr, ptr, ptr, i32, [4 x i8], %struct.__Imu_Quat, %struct.__Imu_Euler, i32 }>
%struct.__Imu_Quat = type { i64, %union.anon }
%union.anon = type { [4 x float] }
%struct.__Imu_Euler = type { i64, float, float, float }
%class.Device = type { ptr, i8, i32, ptr, ptr, i64, i8, ptr, i8, i32 }
%struct.__Imu_Config = type { ptr }
%class.Imu = type <{ ptr, ptr, ptr, ptr, i32, [4 x i8], %struct.__Imu_Quat, %struct.__Imu_Euler, i32, [4 x i8], %class.Device }>

@_ZL10s_DMPImage = external hidden constant [3062 x i8], align 16

; 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 @_ZN10ImuMpu92504InitERK12__Imu_ConfigP11AccelSensorP10GyroSensorP9MagSensor(ptr noundef nonnull align 8 dereferenceable(108) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) unnamed_addr #1 align 2 {
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %5
  store i1 false, ptr %6, align 1
  br label %93

18:                                               ; preds = %5
  %19 = getelementptr inbounds %class.ImuMpu9250, ptr %14, i32 0, i32 3
  store i32 0, ptr %19, align 8, !tbaa !9
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.ImuMpu9250, ptr %14, i32 0, i32 2
  store ptr %20, ptr %21, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #4
  %22 = getelementptr inbounds %class.ImuMpu9250, ptr %14, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %24 = call noundef zeroext i1 @_ZN10AgmMpu92507InitDMPEjPhi(ptr noundef nonnull align 8 dereferenceable(580) %23, i32 noundef 1024, ptr noundef @_ZL10s_DMPImage, i32 noundef 3062)
  %25 = zext i1 %24 to i8
  store i8 %25, ptr %12, align 1, !tbaa !18
  %26 = load i8, ptr %12, align 1, !tbaa !18, !range !20, !noundef !21
  %27 = trunc i8 %26 to i1
  %28 = zext i1 %27 to i32
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %59

30:                                               ; preds = %18
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = call noundef zeroext i1 @_ZN3Imu4InitERK12__Imu_ConfigP11AccelSensorP10GyroSensorP9MagSensor(ptr noundef nonnull align 8 dereferenceable(92) %14, ptr noundef nonnull align 8 dereferenceable(8) %31, ptr noundef %32, ptr noundef %33, ptr noundef %34)
  %36 = zext i1 %35 to i8
  store i8 %36, ptr %12, align 1, !tbaa !18
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.__Imu_Config, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !22
  %40 = load ptr, ptr %14, align 8, !tbaa !24
  %41 = getelementptr i8, ptr %40, i64 -24
  %42 = load i64, ptr %41, align 8
  %43 = getelementptr inbounds i8, ptr %14, i64 %42
  %44 = getelementptr inbounds %class.Device, ptr %43, i32 0, i32 7
  store ptr %39, ptr %44, align 8, !tbaa !26
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %51

47:                                               ; preds = %30
  %48 = getelementptr inbounds %class.ImuMpu9250, ptr %14, i32 0, i32 3
  %49 = load i32, ptr %48, align 8, !tbaa !9
  %50 = add nsw i32 %49, 8
  store i32 %50, ptr %48, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %47, %30
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %58

54:                                               ; preds = %51
  %55 = getelementptr inbounds %class.ImuMpu9250, ptr %14, i32 0, i32 3
  %56 = load i32, ptr %55, align 8, !tbaa !9
  %57 = add nsw i32 %56, 6
  store i32 %57, ptr %55, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %54, %51
  br label %59

59:                                               ; preds = %58, %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 1, ptr %13, align 4, !tbaa !29
  %60 = getelementptr inbounds %class.Imu, ptr %14, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !30
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %72

63:                                               ; preds = %59
  %64 = getelementptr inbounds %class.Imu, ptr %14, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !30
  %66 = load ptr, ptr %65, align 8, !tbaa !24
  %67 = getelementptr inbounds ptr, ptr %66, i64 6
  %68 = load ptr, ptr %67, align 8
  %69 = call noundef i32 %68(ptr noundef nonnull align 8 dereferenceable(73) %65)
  %70 = load i32, ptr %13, align 4, !tbaa !29
  %71 = call noundef i32 @_ZL3maxii(i32 noundef %69, i32 noundef %70)
  store i32 %71, ptr %13, align 4, !tbaa !29
  br label %72

72:                                               ; preds = %63, %59
  %73 = getelementptr inbounds %class.Imu, ptr %14, i32 0, i32 2
  %74 = load ptr, ptr %73, align 8, !tbaa !31
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %85

76:                                               ; preds = %72
  %77 = getelementptr inbounds %class.Imu, ptr %14, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !31
  %79 = load ptr, ptr %78, align 8, !tbaa !24
  %80 = getelementptr inbounds ptr, ptr %79, i64 6
  %81 = load ptr, ptr %80, align 8
  %82 = call noundef i32 %81(ptr noundef nonnull align 8 dereferenceable(73) %78)
  %83 = load i32, ptr %13, align 4, !tbaa !29
  %84 = call noundef i32 @_ZL3maxii(i32 noundef %82, i32 noundef %83)
  store i32 %84, ptr %13, align 4, !tbaa !29
  br label %85

85:                                               ; preds = %76, %72
  %86 = load i32, ptr %13, align 4, !tbaa !29
  %87 = load ptr, ptr %14, align 8, !tbaa !24
  %88 = getelementptr inbounds ptr, ptr %87, i64 20
  %89 = load ptr, ptr %88, align 8
  %90 = call noundef i32 %89(ptr noundef nonnull align 8 dereferenceable(108) %14, i32 noundef %86)
  %91 = load i8, ptr %12, align 1, !tbaa !18, !range !20, !noundef !21
  %92 = trunc i8 %91 to i1
  store i1 %92, ptr %6, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #4
  br label %93

93:                                               ; preds = %85, %17
  %94 = load i1, ptr %6, align 1
  ret i1 %94
}

declare noundef zeroext i1 @_ZN10AgmMpu92507InitDMPEjPhi(ptr noundef nonnull align 8 dereferenceable(580), i32 noundef, ptr noundef, i32 noundef) #2

declare noundef zeroext i1 @_ZN3Imu4InitERK12__Imu_ConfigP11AccelSensorP10GyroSensorP9MagSensor(ptr noundef nonnull align 8 dereferenceable(92), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, ptr noundef, ptr noundef) unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL3maxii(i32 noundef, i32 noundef) #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 = { inlinehint 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 #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 = !{!10, !12, i64 104}
!10 = !{!"_ZTS10ImuMpu9250", !11, i64 0, !6, i64 96, !12, i64 104}
!11 = !{!"_ZTS3Imu", !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !13, i64 40, !15, i64 64, !12, i64 88}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS10__Imu_Quat", !14, i64 0, !7, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTS11__Imu_Euler", !14, i64 0, !16, i64 8, !16, i64 12, !16, i64 16}
!16 = !{!"float", !7, i64 0}
!17 = !{!10, !6, i64 96}
!18 = !{!19, !19, i64 0}
!19 = !{!"bool", !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!23, !6, i64 0}
!23 = !{!"_ZTS12__Imu_Config", !6, i64 0}
!24 = !{!25, !25, i64 0}
!25 = !{!"vtable pointer", !8, i64 0}
!26 = !{!27, !6, i64 48}
!27 = !{!"_ZTS6Device", !19, i64 8, !12, i64 12, !6, i64 16, !6, i64 24, !14, i64 32, !19, i64 40, !6, i64 48, !7, i64 56, !28, i64 60}
!28 = !{!"_ZTS21__Dev_Data_Byte_Order", !7, i64 0}
!29 = !{!12, !12, i64 0}
!30 = !{!11, !6, i64 8}
!31 = !{!11, !6, i64 16}


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

@_ZL10s_DMPImage = external hidden constant [3062 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10ImuMpu92504InitERK12__Imu_ConfigP11AccelSensorP10GyroSensorP9MagSensor(ptr noundef nonnull align 8 dereferenceable(108) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) unnamed_addr #0 align 2 {
  %6 = icmp eq ptr %2, null
  br i1 %6, label %46, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 104
  store i32 0, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 96
  store ptr %2, ptr %9, align 8, !tbaa !16
  %10 = tail call noundef zeroext i1 @_ZN10AgmMpu92507InitDMPEjPhi(ptr noundef nonnull align 8 dereferenceable(580) %2, i32 noundef 1024, ptr noundef nonnull @_ZL10s_DMPImage, i32 noundef 3062)
  br i1 %10, label %11, label %23

11:                                               ; preds = %7
  %12 = tail call noundef zeroext i1 @_ZN3Imu4InitERK12__Imu_ConfigP11AccelSensorP10GyroSensorP9MagSensor(ptr noundef nonnull align 8 dereferenceable(92) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %2, ptr noundef %3, ptr noundef %4)
  %13 = load ptr, ptr %1, align 8, !tbaa !17
  %14 = load ptr, ptr %0, align 8, !tbaa !19
  %15 = getelementptr i8, ptr %14, i64 -24
  %16 = load i64, ptr %15, align 8
  %17 = getelementptr inbounds i8, ptr %0, i64 %16
  %18 = getelementptr inbounds i8, ptr %17, i64 48
  store ptr %13, ptr %18, align 8, !tbaa !21
  %19 = load i32, ptr %8, align 8, !tbaa !5
  %20 = add nsw i32 %19, 8
  store i32 %20, ptr %8, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %23, label %21

21:                                               ; preds = %11
  %22 = add nsw i32 %19, 14
  store i32 %22, ptr %8, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %11, %21, %7
  %.015.in = phi i1 [ %12, %21 ], [ %12, %11 ], [ false, %7 ]
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !25
  %.not20 = icmp eq ptr %25, null
  br i1 %.not20, label %32, label %26

26:                                               ; preds = %23
  %27 = load ptr, ptr %25, align 8, !tbaa !19
  %28 = getelementptr inbounds i8, ptr %27, i64 48
  %29 = load ptr, ptr %28, align 8
  %30 = tail call noundef i32 %29(ptr noundef nonnull align 8 dereferenceable(73) %25)
  %31 = tail call noundef i32 @_ZL3maxii(i32 noundef %30, i32 noundef 1)
  br label %32

32:                                               ; preds = %26, %23
  %.0 = phi i32 [ %31, %26 ], [ 1, %23 ]
  %33 = getelementptr inbounds i8, ptr %0, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !26
  %.not21 = icmp eq ptr %34, null
  br i1 %.not21, label %41, label %35

35:                                               ; preds = %32
  %36 = load ptr, ptr %34, align 8, !tbaa !19
  %37 = getelementptr inbounds i8, ptr %36, i64 48
  %38 = load ptr, ptr %37, align 8
  %39 = tail call noundef i32 %38(ptr noundef nonnull align 8 dereferenceable(73) %34)
  %40 = tail call noundef i32 @_ZL3maxii(i32 noundef %39, i32 noundef %.0)
  br label %41

41:                                               ; preds = %35, %32
  %.1 = phi i32 [ %40, %35 ], [ %.0, %32 ]
  %42 = load ptr, ptr %0, align 8, !tbaa !19
  %43 = getelementptr inbounds i8, ptr %42, i64 160
  %44 = load ptr, ptr %43, align 8
  %45 = tail call noundef i32 %44(ptr noundef nonnull align 8 dereferenceable(108) %0, i32 noundef %.1)
  br label %46

46:                                               ; preds = %5, %41
  %.016 = phi i1 [ %.015.in, %41 ], [ false, %5 ]
  ret i1 %.016
}

declare noundef zeroext i1 @_ZN10AgmMpu92507InitDMPEjPhi(ptr noundef nonnull align 8 dereferenceable(580), i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare noundef zeroext i1 @_ZN3Imu4InitERK12__Imu_ConfigP11AccelSensorP10GyroSensorP9MagSensor(ptr noundef nonnull align 8 dereferenceable(92), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, ptr noundef, ptr noundef) unnamed_addr #1

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

attributes #0 = { 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 #1 = { "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 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" }

!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, !11, i64 104}
!6 = !{!"_ZTS10ImuMpu9250", !7, i64 0, !8, i64 96, !11, i64 104}
!7 = !{!"_ZTS3Imu", !8, i64 8, !8, i64 16, !8, i64 24, !11, i64 32, !12, i64 40, !14, i64 64, !11, i64 88}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"_ZTS10__Imu_Quat", !13, i64 0, !9, i64 8}
!13 = !{!"long", !9, i64 0}
!14 = !{!"_ZTS11__Imu_Euler", !13, i64 0, !15, i64 8, !15, i64 12, !15, i64 16}
!15 = !{!"float", !9, i64 0}
!16 = !{!6, !8, i64 96}
!17 = !{!18, !8, i64 0}
!18 = !{!"_ZTS12__Imu_Config", !8, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !10, i64 0}
!21 = !{!22, !8, i64 48}
!22 = !{!"_ZTS6Device", !23, i64 8, !11, i64 12, !8, i64 16, !8, i64 24, !13, i64 32, !23, i64 40, !8, i64 48, !9, i64 56, !24, i64 60}
!23 = !{!"bool", !9, i64 0}
!24 = !{!"_ZTS21__Dev_Data_Byte_Order", !9, i64 0}
!25 = !{!7, !8, i64 8}
!26 = !{!7, !8, i64 16}


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