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

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

@__const._ZN10ImuMpu92504RateEj.cfg = external hidden unnamed_addr constant [12 x i8], align 1

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

11:                                               ; preds = %2
  store i32 200, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %11, %2
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp ule i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %15, %12
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #4
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = udiv i32 200, %17
  %19 = sub i32 %18, 1
  %20 = trunc i32 %19 to i16
  store i16 %20, ptr %7, align 2, !tbaa !11
  %21 = load i16, ptr %7, align 2, !tbaa !11
  %22 = zext i16 %21 to i32
  %23 = ashr i32 %22, 8
  %24 = trunc i32 %23 to i8
  %25 = getelementptr inbounds [2 x i8], ptr %6, i64 0, i64 0
  store i8 %24, ptr %25, align 1, !tbaa !13
  %26 = load i16, ptr %7, align 2, !tbaa !11
  %27 = zext i16 %26 to i32
  %28 = and i32 %27, 255
  %29 = trunc i32 %28 to i8
  %30 = getelementptr inbounds [2 x i8], ptr %6, i64 0, i64 1
  store i8 %29, ptr %30, align 1, !tbaa !13
  %31 = getelementptr inbounds [2 x i8], ptr %6, i64 0, i64 0
  %32 = load ptr, ptr %8, align 8, !tbaa !14
  %33 = getelementptr inbounds ptr, ptr %32, i64 30
  %34 = load ptr, ptr %33, align 8
  %35 = call noundef i32 %34(ptr noundef nonnull align 8 dereferenceable(108) %8, i16 noundef zeroext 534, ptr noundef %31, i32 noundef 2)
  %36 = getelementptr inbounds [12 x i8], ptr %5, i64 0, i64 0
  %37 = load ptr, ptr %8, align 8, !tbaa !14
  %38 = getelementptr inbounds ptr, ptr %37, i64 30
  %39 = load ptr, ptr %38, align 8
  %40 = call noundef i32 %39(ptr noundef nonnull align 8 dereferenceable(108) %8, i16 noundef zeroext 2753, ptr noundef %36, i32 noundef 12)
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = mul i32 %41, 1000
  %43 = call noundef i32 @_ZN3Imu4RateEj(ptr noundef nonnull align 8 dereferenceable(92) %8, i32 noundef %42)
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %5) #4
  ret i32 %43
}

; 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) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3Imu4RateEj(ptr noundef nonnull align 8 dereferenceable(92), i32 noundef) unnamed_addr #3 align 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !8, 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"

@__const._ZN10ImuMpu92504RateEj.cfg = external hidden unnamed_addr constant [12 x i8], align 1

; 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 @_ZN10ImuMpu92504RateEj(ptr noundef nonnull align 8 dereferenceable(108) %0, i32 noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca [12 x i8], align 1
  %4 = alloca [2 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(12) %3, ptr noundef nonnull align 1 dereferenceable(12) @__const._ZN10ImuMpu92504RateEj.cfg, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %4) #5
  %spec.store.select = tail call i32 @llvm.umin.i32(i32 %1, i32 200)
  %spec.store.select1 = tail call i32 @llvm.umax.i32(i32 %spec.store.select, i32 1)
  %.rhs.trunc = trunc nuw i32 %spec.store.select1 to i8
  %5 = udiv i8 -56, %.rhs.trunc
  %6 = add i8 %5, -1
  store i8 0, ptr %4, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %4, i64 1
  store i8 %6, ptr %7, align 1, !tbaa !5
  %8 = load ptr, ptr %0, align 8, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %8, i64 240
  %10 = load ptr, ptr %9, align 8
  %11 = call noundef i32 %10(ptr noundef nonnull align 8 dereferenceable(108) %0, i16 noundef zeroext 534, ptr noundef nonnull %4, i32 noundef 2)
  %12 = load ptr, ptr %0, align 8, !tbaa !8
  %13 = getelementptr inbounds i8, ptr %12, i64 240
  %14 = load ptr, ptr %13, align 8
  %15 = call noundef i32 %14(ptr noundef nonnull align 8 dereferenceable(108) %0, i16 noundef zeroext 2753, ptr noundef nonnull %3, i32 noundef 12)
  %16 = mul nuw nsw i32 %spec.store.select1, 1000
  %17 = call noundef i32 @_ZN3Imu4RateEj(ptr noundef nonnull align 8 dereferenceable(92) %0, i32 noundef %16)
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #5
  ret i32 %17
}

; 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) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3Imu4RateEj(ptr noundef nonnull align 8 dereferenceable(92), i32 noundef) unnamed_addr #3 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #4

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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: CorrelatedValuePropagationPass,EarlyCSEPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass