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

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

; 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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10ImuMpu925010QuaternionEbi(ptr noundef nonnull align 8 dereferenceable(108) %0, i1 noundef zeroext %1, i32 noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca [4 x i8], align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  %8 = zext i1 %1 to i8
  store i8 %8, ptr %5, align 1, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %10 = load i32, ptr %6, align 4, !tbaa !11
  %11 = icmp sle i32 %10, 3
  br i1 %11, label %12, label %30

12:                                               ; preds = %3
  %13 = load i8, ptr %5, align 1, !tbaa !9, !range !13, !noundef !14
  %14 = trunc i8 %13 to i1
  %15 = zext i1 %14 to i32
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %22

17:                                               ; preds = %12
  %18 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  store i8 -64, ptr %18, align 1, !tbaa !15
  %19 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 1
  store i8 -62, ptr %19, align 1, !tbaa !15
  %20 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 2
  store i8 -60, ptr %20, align 1, !tbaa !15
  %21 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 3
  store i8 -58, ptr %21, align 1, !tbaa !15
  br label %24

22:                                               ; preds = %12
  %23 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %23, i8 -117, i64 4, i1 false)
  br label %24

24:                                               ; preds = %22, %17
  %25 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  %26 = load ptr, ptr %9, align 8, !tbaa !16
  %27 = getelementptr inbounds ptr, ptr %26, i64 30
  %28 = load ptr, ptr %27, align 8
  %29 = call noundef i32 %28(ptr noundef nonnull align 8 dereferenceable(108) %9, i16 noundef zeroext 2712, ptr noundef %25, i32 noundef 4)
  br label %48

30:                                               ; preds = %3
  %31 = load i8, ptr %5, align 1, !tbaa !9, !range !13, !noundef !14
  %32 = trunc i8 %31 to i1
  %33 = zext i1 %32 to i32
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %40

35:                                               ; preds = %30
  %36 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  store i8 32, ptr %36, align 1, !tbaa !15
  %37 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 1
  store i8 40, ptr %37, align 1, !tbaa !15
  %38 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 2
  store i8 48, ptr %38, align 1, !tbaa !15
  %39 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 3
  store i8 56, ptr %39, align 1, !tbaa !15
  br label %42

40:                                               ; preds = %30
  %41 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %41, i8 -93, i64 4, i1 false)
  br label %42

42:                                               ; preds = %40, %35
  %43 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  %44 = load ptr, ptr %9, align 8, !tbaa !16
  %45 = getelementptr inbounds ptr, ptr %44, i64 30
  %46 = load ptr, ptr %45, align 8
  %47 = call noundef i32 %46(ptr noundef nonnull align 8 dereferenceable(108) %9, i16 noundef zeroext 2718, ptr noundef %43, i32 noundef 4)
  br label %48

48:                                               ; preds = %42, %24
  %49 = getelementptr inbounds %class.ImuMpu9250, ptr %9, i32 0, i32 3
  %50 = load i32, ptr %49, align 8, !tbaa !18
  %51 = add nsw i32 %50, 16
  store i32 %51, ptr %49, align 8, !tbaa !18
  %52 = load i8, ptr %5, align 1, !tbaa !9, !range !13, !noundef !14
  %53 = trunc i8 %52 to i1
  %54 = call noundef i32 @_ZN3Imu7FeatureEjb(ptr noundef nonnull align 8 dereferenceable(92) %9, i32 noundef 2, i1 noundef zeroext %53)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i1 true
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !8, i64 0}
!18 = !{!19, !12, i64 104}
!19 = !{!"_ZTS10ImuMpu9250", !20, i64 0, !6, i64 96, !12, i64 104}
!20 = !{!"_ZTS3Imu", !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !21, i64 40, !23, i64 64, !12, i64 88}
!21 = !{!"_ZTS10__Imu_Quat", !22, i64 0, !7, i64 8}
!22 = !{!"long", !7, i64 0}
!23 = !{!"_ZTS11__Imu_Euler", !22, i64 0, !24, i64 8, !24, i64 12, !24, i64 16}
!24 = !{!"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 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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10ImuMpu925010QuaternionEbi(ptr noundef nonnull align 8 dereferenceable(108) %0, i1 noundef zeroext %1, i32 noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca [4 x i8], align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %5 = icmp slt i32 %2, 4
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  br i1 %1, label %7, label %8

7:                                                ; preds = %6
  store <4 x i8> <i8 -64, i8 -62, i8 -60, i8 -58>, ptr %4, align 4, !tbaa !5
  br label %12

8:                                                ; preds = %6
  store i32 -1953789045, ptr %4, align 4
  br label %12

9:                                                ; preds = %3
  br i1 %1, label %10, label %11

10:                                               ; preds = %9
  store <4 x i8> <i8 32, i8 40, i8 48, i8 56>, ptr %4, align 4, !tbaa !5
  br label %12

11:                                               ; preds = %9
  store i32 -1549556829, ptr %4, align 4
  br label %12

12:                                               ; preds = %10, %11, %7, %8
  %.sink = phi i16 [ 2712, %8 ], [ 2712, %7 ], [ 2718, %11 ], [ 2718, %10 ]
  %13 = load ptr, ptr %0, align 8, !tbaa !8
  %14 = getelementptr inbounds i8, ptr %13, i64 240
  %15 = load ptr, ptr %14, align 8
  %16 = call noundef i32 %15(ptr noundef nonnull align 8 dereferenceable(108) %0, i16 noundef zeroext %.sink, ptr noundef nonnull %4, i32 noundef 4)
  %17 = getelementptr inbounds i8, ptr %0, i64 104
  %18 = load i32, ptr %17, align 8, !tbaa !10
  %19 = add nsw i32 %18, 16
  store i32 %19, ptr %17, align 8, !tbaa !10
  %20 = call noundef i32 @_ZN3Imu7FeatureEjb(ptr noundef nonnull align 8 dereferenceable(92) %0, i32 noundef 2, i1 noundef zeroext %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  ret i1 true
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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 104}
!11 = !{!"_ZTS10ImuMpu9250", !12, i64 0, !13, i64 96, !14, i64 104}
!12 = !{!"_ZTS3Imu", !13, i64 8, !13, i64 16, !13, i64 24, !14, i64 32, !15, i64 40, !17, i64 64, !14, i64 88}
!13 = !{!"any pointer", !6, i64 0}
!14 = !{!"int", !6, i64 0}
!15 = !{!"_ZTS10__Imu_Quat", !16, i64 0, !6, i64 8}
!16 = !{!"long", !6, i64 0}
!17 = !{!"_ZTS11__Imu_Euler", !16, i64 0, !18, i64 8, !18, i64 12, !18, i64 16}
!18 = !{!"float", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass