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

; 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.Imu = type <{ ptr, ptr, ptr, ptr, i32, [4 x i8], %struct.__Imu_Quat, %struct.__Imu_Euler, i32, [4 x i8], %class.Device }>
%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: mustprogress uwtable
define dso_local noundef i32 @_ZN3Imu7FeatureEjb(ptr noundef nonnull align 8 dereferenceable(92) %0, i32 noundef %1, i1 noundef zeroext %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = zext i1 %2 to i8
  store i8 %8, ptr %6, align 1, !tbaa !11
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 32768, ptr %7, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %31, %3
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %34

13:                                               ; preds = %10
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = and i32 %14, %15
  switch i32 %16, label %31 [
    i32 1, label %17
    i32 2, label %31
    i32 4, label %24
    i32 8, label %31
    i32 16, label %31
    i32 32, label %31
    i32 64, label %31
    i32 128, label %31
    i32 256, label %31
    i32 512, label %31
  ]

17:                                               ; preds = %13
  %18 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %19 = trunc i8 %18 to i1
  %20 = load ptr, ptr %9, align 8, !tbaa !15
  %21 = getelementptr inbounds ptr, ptr %20, i64 5
  %22 = load ptr, ptr %21, align 8
  %23 = call noundef zeroext i1 %22(ptr noundef nonnull align 8 dereferenceable(92) %9, i1 noundef zeroext %19)
  br label %31

24:                                               ; preds = %13
  %25 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %26 = trunc i8 %25 to i1
  %27 = load ptr, ptr %9, align 8, !tbaa !15
  %28 = getelementptr inbounds ptr, ptr %27, i64 6
  %29 = load ptr, ptr %28, align 8
  %30 = call noundef zeroext i1 %29(ptr noundef nonnull align 8 dereferenceable(92) %9, i1 noundef zeroext %26)
  br label %31

31:                                               ; preds = %24, %17, %13, %13, %13, %13, %13, %13, %13, %13, %13
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = lshr i32 %32, 1
  store i32 %33, ptr %7, align 4, !tbaa !9
  br label %10, !llvm.loop !17

34:                                               ; preds = %10
  %35 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %36 = trunc i8 %35 to i1
  %37 = zext i1 %36 to i32
  %38 = icmp eq i32 %37, 1
  br i1 %38, label %39, label %44

39:                                               ; preds = %34
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = getelementptr inbounds %class.Imu, ptr %9, i32 0, i32 4
  %42 = load i32, ptr %41, align 8, !tbaa !19
  %43 = or i32 %42, %40
  store i32 %43, ptr %41, align 8, !tbaa !19
  br label %50

44:                                               ; preds = %34
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = xor i32 %45, -1
  %47 = getelementptr inbounds %class.Imu, ptr %9, i32 0, i32 4
  %48 = load i32, ptr %47, align 8, !tbaa !19
  %49 = and i32 %48, %46
  store i32 %49, ptr %47, align 8, !tbaa !19
  br label %50

50:                                               ; preds = %44, %39
  %51 = getelementptr inbounds %class.Imu, ptr %9, i32 0, i32 4
  %52 = load i32, ptr %51, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %52
}

; 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 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !10, i64 32}
!20 = !{!"_ZTS3Imu", !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !21, i64 40, !23, i64 64, !10, 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 uwtable
define dso_local noundef i32 @_ZN3Imu7FeatureEjb(ptr noundef nonnull align 8 dereferenceable(92) %0, i32 noundef %1, i1 noundef zeroext %2) unnamed_addr #0 align 2 {
  %trunc.1352 = and i32 %1, 4
  %cond51.not = icmp eq i32 %trunc.1352, 0
  br i1 %cond51.not, label %8, label %.sink.split48

.sink.split48:                                    ; preds = %3
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 48
  %6 = load ptr, ptr %5, align 8
  %7 = tail call noundef zeroext i1 %6(ptr noundef nonnull align 8 dereferenceable(92) %0, i1 noundef zeroext %2)
  br label %8

8:                                                ; preds = %.sink.split48, %3
  %9 = trunc i32 %1 to i1
  br i1 %9, label %10, label %15

10:                                               ; preds = %8
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 40
  %13 = load ptr, ptr %12, align 8
  %14 = tail call noundef zeroext i1 %13(ptr noundef nonnull align 8 dereferenceable(92) %0, i1 noundef zeroext %2)
  br label %15

15:                                               ; preds = %8, %10
  br i1 %2, label %16, label %20

16:                                               ; preds = %15
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  %18 = load i32, ptr %17, align 8, !tbaa !8
  %19 = or i32 %18, %1
  store i32 %19, ptr %17, align 8, !tbaa !8
  br label %25

20:                                               ; preds = %15
  %21 = xor i32 %1, -1
  %22 = getelementptr inbounds i8, ptr %0, i64 32
  %23 = load i32, ptr %22, align 8, !tbaa !8
  %24 = and i32 %23, %21
  store i32 %24, ptr %22, align 8, !tbaa !8
  br label %25

25:                                               ; preds = %20, %16
  %26 = phi i32 [ %24, %20 ], [ %19, %16 ]
  ret i32 %26
}

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

!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, !12, i64 32}
!9 = !{!"_ZTS3Imu", !10, i64 8, !10, i64 16, !10, i64 24, !12, i64 32, !13, i64 40, !15, i64 64, !12, i64 88}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"int", !11, i64 0}
!13 = !{!"_ZTS10__Imu_Quat", !14, i64 0, !11, i64 8}
!14 = !{!"long", !11, i64 0}
!15 = !{!"_ZTS11__Imu_Euler", !14, i64 0, !16, i64 8, !16, i64 12, !16, i64 16}
!16 = !{!"float", !11, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass