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

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

; 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 i32 @_ZN10ImuMpu92504ReadEtPhi(ptr noundef nonnull align 8 dereferenceable(108) %0, i16 noundef zeroext %1, ptr noundef %2, i32 noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca [2 x i8], align 1
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i16 %1, ptr %6, align 2, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !11
  %14 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %62, %4
  %16 = load i32, ptr %8, align 4, !tbaa !11
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %63

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %19 = load i32, ptr %8, align 4, !tbaa !11
  %20 = call noundef i32 @_ZL3minii(i32 noundef %19, i32 noundef 256)
  store i32 %20, ptr %12, align 4, !tbaa !11
  store i8 109, ptr %9, align 1, !tbaa !13
  %21 = load i16, ptr %6, align 2, !tbaa !9
  %22 = zext i16 %21 to i32
  %23 = ashr i32 %22, 8
  %24 = trunc i32 %23 to i8
  %25 = getelementptr inbounds [2 x i8], ptr %10, i64 0, i64 0
  store i8 %24, ptr %25, align 1, !tbaa !13
  %26 = load i16, ptr %6, align 2, !tbaa !9
  %27 = zext i16 %26 to i32
  %28 = and i32 %27, 255
  %29 = trunc i32 %28 to i8
  %30 = getelementptr inbounds [2 x i8], ptr %10, i64 0, i64 1
  store i8 %29, ptr %30, align 1, !tbaa !13
  %31 = getelementptr inbounds [2 x i8], ptr %10, i64 0, i64 0
  %32 = load ptr, ptr %14, align 8, !tbaa !14
  %33 = getelementptr inbounds ptr, ptr %32, i64 28
  %34 = load ptr, ptr %33, align 8
  %35 = call noundef i32 %34(ptr noundef nonnull align 8 dereferenceable(108) %14, ptr noundef %9, i32 noundef 1, ptr noundef %31, i32 noundef 2)
  %36 = icmp slt i32 %35, 2
  br i1 %36, label %37, label %38

37:                                               ; preds = %18
  store i32 3, ptr %13, align 4
  br label %60

38:                                               ; preds = %18
  store i8 111, ptr %9, align 1, !tbaa !13
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !11
  %41 = load ptr, ptr %14, align 8, !tbaa !14
  %42 = getelementptr inbounds ptr, ptr %41, i64 27
  %43 = load ptr, ptr %42, align 8
  %44 = call noundef i32 %43(ptr noundef nonnull align 8 dereferenceable(108) %14, ptr noundef %9, i32 noundef 1, ptr noundef %39, i32 noundef %40)
  store i32 %44, ptr %12, align 4, !tbaa !11
  %45 = load i32, ptr %12, align 4, !tbaa !11
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = sext i32 %45 to i64
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  store ptr %48, ptr %7, align 8, !tbaa !5
  %49 = load i32, ptr %12, align 4, !tbaa !11
  %50 = load i16, ptr %6, align 2, !tbaa !9
  %51 = zext i16 %50 to i32
  %52 = add nsw i32 %51, %49
  %53 = trunc i32 %52 to i16
  store i16 %53, ptr %6, align 2, !tbaa !9
  %54 = load i32, ptr %12, align 4, !tbaa !11
  %55 = load i32, ptr %8, align 4, !tbaa !11
  %56 = sub nsw i32 %55, %54
  store i32 %56, ptr %8, align 4, !tbaa !11
  %57 = load i32, ptr %12, align 4, !tbaa !11
  %58 = load i32, ptr %11, align 4, !tbaa !11
  %59 = add nsw i32 %58, %57
  store i32 %59, ptr %11, align 4, !tbaa !11
  store i32 0, ptr %13, align 4
  br label %60

60:                                               ; preds = %38, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %61 = load i32, ptr %13, align 4
  switch i32 %61, label %65 [
    i32 0, label %62
    i32 3, label %63
  ]

62:                                               ; preds = %60
  br label %15, !llvm.loop !16

63:                                               ; preds = %60, %15
  %64 = load i32, ptr %11, align 4, !tbaa !11
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  ret i32 %64

65:                                               ; preds = %60
  unreachable
}

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

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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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 i32 @_ZN10ImuMpu92504ReadEtPhi(ptr noundef nonnull align 8 dereferenceable(108) %0, i16 noundef zeroext %1, ptr noundef %2, i32 noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca i8, align 1
  %6 = alloca [2 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %6) #3
  %7 = icmp sgt i32 %3, 0
  br i1 %7, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %4
  %8 = getelementptr inbounds i8, ptr %6, i64 1
  br label %9

9:                                                ; preds = %.lr.ph, %19
  %.01632 = phi i32 [ 0, %.lr.ph ], [ %29, %19 ]
  %.01731 = phi i32 [ %3, %.lr.ph ], [ %28, %19 ]
  %.01930 = phi ptr [ %2, %.lr.ph ], [ %25, %19 ]
  %.02129 = phi i16 [ %1, %.lr.ph ], [ %27, %19 ]
  %10 = call noundef i32 @_ZL3minii(i32 noundef %.01731, i32 noundef 256)
  store i8 109, ptr %5, align 1, !tbaa !5
  %11 = lshr i16 %.02129, 8
  %12 = trunc nuw i16 %11 to i8
  store i8 %12, ptr %6, align 1, !tbaa !5
  %13 = trunc i16 %.02129 to i8
  store i8 %13, ptr %8, align 1, !tbaa !5
  %14 = load ptr, ptr %0, align 8, !tbaa !8
  %15 = getelementptr inbounds i8, ptr %14, i64 224
  %16 = load ptr, ptr %15, align 8
  %17 = call noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(108) %0, ptr noundef nonnull %5, i32 noundef 1, ptr noundef nonnull %6, i32 noundef 2)
  %18 = icmp slt i32 %17, 2
  br i1 %18, label %.thread, label %19

19:                                               ; preds = %9
  store i8 111, ptr %5, align 1, !tbaa !5
  %20 = load ptr, ptr %0, align 8, !tbaa !8
  %21 = getelementptr inbounds i8, ptr %20, i64 216
  %22 = load ptr, ptr %21, align 8
  %23 = call noundef i32 %22(ptr noundef nonnull align 8 dereferenceable(108) %0, ptr noundef nonnull %5, i32 noundef 1, ptr noundef %.01930, i32 noundef %10)
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %.01930, i64 %24
  %26 = trunc i32 %23 to i16
  %27 = add i16 %.02129, %26
  %28 = sub nsw i32 %.01731, %23
  %29 = add nsw i32 %23, %.01632
  %30 = icmp sgt i32 %28, 0
  br i1 %30, label %9, label %.thread

.thread:                                          ; preds = %19, %9, %4
  %.016.lcssa = phi i32 [ 0, %4 ], [ %.01632, %9 ], [ %29, %19 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #3
  ret i32 %.016.lcssa
}

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

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 = { 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 #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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass