; LLVM IR from marcinlos/iga-ads :: src/ads/simulation/dimension.ll (ZN3ads9dimension7fix_dofEi)

; 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.ads::dimension" = type { i32, i32, double, double, %"struct.ads::bspline::basis", %"class.ads::lin::band_matrix", %"struct.ads::basis_data", %"struct.ads::lin::solver_ctx" }
%"struct.ads::bspline::basis" = type { %"class.std::vector", i32, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.ads::lin::band_matrix" = type <{ %"class.std::vector", i32, i32, i32, i32, i32, [4 x i8] }>
%"struct.ads::basis_data" = type { %"class.std::vector.0", %"class.std::vector.5", i32, i32, i32, i32, i32, i32, %"class.std::vector", %"struct.ads::bspline::basis", ptr, ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.5" = type { %"struct.std::_Vector_base.6" }
%"struct.std::_Vector_base.6" = type { %"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.ads::lin::solver_ctx" = type { %"class.std::vector.0", i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3ads9dimension7fix_dofEi(ptr noundef nonnull align 8 dereferenceable(344) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %8 = call noundef i32 @_ZNK3ads9dimension4dofsEv(ptr noundef nonnull align 8 dereferenceable(344) %7)
  %9 = sub nsw i32 %8, 1
  store i32 %9, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = getelementptr inbounds %"class.ads::dimension", ptr %7, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = sub nsw i32 %10, %12
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = call noundef i32 @_ZN3ads5clampIiiiEEDaT_T0_T1_(i32 noundef %13, i32 noundef 0, i32 noundef %14)
  store i32 %15, ptr %6, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %31, %2
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = getelementptr inbounds %"class.ads::dimension", ptr %7, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = add nsw i32 %18, %20
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = call noundef i32 @_ZN3ads5clampIiiiEEDaT_T0_T1_(i32 noundef %21, i32 noundef 0, i32 noundef %22)
  %24 = icmp sle i32 %17, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %34

26:                                               ; preds = %16
  %27 = getelementptr inbounds %"class.ads::dimension", ptr %7, i32 0, i32 5
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN3ads3lin11band_matrixclEii(ptr noundef nonnull align 8 dereferenceable(44) %27, i32 noundef %28, i32 noundef %29)
  store double 0.000000e+00, ptr %30, align 8, !tbaa !30
  br label %31

31:                                               ; preds = %26
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %6, align 4, !tbaa !9
  br label %16, !llvm.loop !31

34:                                               ; preds = %25
  %35 = getelementptr inbounds %"class.ads::dimension", ptr %7, i32 0, i32 5
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN3ads3lin11band_matrixclEii(ptr noundef nonnull align 8 dereferenceable(44) %35, i32 noundef %36, i32 noundef %37)
  store double 1.000000e+00, ptr %38, align 8, !tbaa !30
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3ads9dimension4dofsEv(ptr noundef nonnull align 8 dereferenceable(344)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3ads5clampIiiiEEDaT_T0_T1_(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN3ads3lin11band_matrixclEii(ptr noundef nonnull align 8 dereferenceable(44), i32 noundef, i32 noundef) #0 align 2

; 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN3ads9dimensionE", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 16, !14, i64 24, !19, i64 80, !20, i64 128, !29, i64 312}
!13 = !{!"double", !7, i64 0}
!14 = !{!"_ZTSN3ads7bspline5basisE", !15, i64 0, !10, i64 24, !15, i64 32}
!15 = !{!"_ZTSSt6vectorIdSaIdEE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!"_ZTSN3ads3lin11band_matrixE", !15, i64 0, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40}
!20 = !{!"_ZTSN3ads10basis_dataE", !21, i64 0, !25, i64 24, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !15, i64 72, !14, i64 96, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176}
!21 = !{!"_ZTSSt6vectorIiSaIiEE", !22, i64 0}
!22 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !23, i64 0}
!23 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!25 = !{!"_ZTSSt6vectorISt4pairIiiESaIS1_EE", !26, i64 0}
!26 = !{!"_ZTSSt12_Vector_baseISt4pairIiiESaIS1_EE", !27, i64 0}
!27 = !{!"_ZTSNSt12_Vector_baseISt4pairIiiESaIS1_EE12_Vector_implE", !28, i64 0}
!28 = !{!"_ZTSNSt12_Vector_baseISt4pairIiiESaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!29 = !{!"_ZTSN3ads3lin10solver_ctxE", !21, i64 0, !10, i64 24, !10, i64 28}
!30 = !{!13, !13, i64 0}
!31 = distinct !{!31, !32}
!32 = !{!"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 uwtable
define dso_local void @_ZN3ads9dimension7fix_dofEi(ptr noundef nonnull align 8 dereferenceable(344) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i32 @_ZNK3ads9dimension4dofsEv(ptr noundef nonnull align 8 dereferenceable(344) %0)
  %4 = add nsw i32 %3, -1
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = sub nsw i32 %1, %5
  %7 = tail call noundef i32 @_ZN3ads5clampIiiiEEDaT_T0_T1_(i32 noundef %6, i32 noundef 0, i32 noundef %4)
  %8 = load i32, ptr %0, align 8, !tbaa !5
  %9 = add nsw i32 %8, %1
  %10 = tail call noundef i32 @_ZN3ads5clampIiiiEEDaT_T0_T1_(i32 noundef %9, i32 noundef 0, i32 noundef %4)
  %.not10 = icmp sgt i32 %7, %10
  br i1 %.not10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 80
  br label %14

._crit_edge:                                      ; preds = %14, %2
  %12 = getelementptr inbounds i8, ptr %0, i64 80
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN3ads3lin11band_matrixclEii(ptr noundef nonnull align 8 dereferenceable(44) %12, i32 noundef %1, i32 noundef %1)
  store double 1.000000e+00, ptr %13, align 8, !tbaa !28
  ret void

14:                                               ; preds = %.lr.ph, %14
  %.011 = phi i32 [ %7, %.lr.ph ], [ %16, %14 ]
  %15 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN3ads3lin11band_matrixclEii(ptr noundef nonnull align 8 dereferenceable(44) %11, i32 noundef %1, i32 noundef %.011)
  store double 0.000000e+00, ptr %15, align 8, !tbaa !28
  %16 = add nsw i32 %.011, 1
  %17 = load i32, ptr %0, align 8, !tbaa !5
  %18 = add nsw i32 %17, %1
  %19 = tail call noundef i32 @_ZN3ads5clampIiiiEEDaT_T0_T1_(i32 noundef %18, i32 noundef 0, i32 noundef %4)
  %.not.not = icmp slt i32 %.011, %19
  br i1 %.not.not, label %14, label %._crit_edge, !llvm.loop !29
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3ads9dimension4dofsEv(ptr noundef nonnull align 8 dereferenceable(344)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3ads5clampIiiiEEDaT_T0_T1_(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN3ads3lin11band_matrixclEii(ptr noundef nonnull align 8 dereferenceable(44), i32 noundef, i32 noundef) local_unnamed_addr #0 align 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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN3ads9dimensionE", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !11, i64 24, !17, i64 80, !18, i64 128, !27, i64 312}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"_ZTSN3ads7bspline5basisE", !12, i64 0, !7, i64 24, !12, i64 32}
!12 = !{!"_ZTSSt6vectorIdSaIdEE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !16, i64 0, !16, i64 8, !16, i64 16}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"_ZTSN3ads3lin11band_matrixE", !12, i64 0, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40}
!18 = !{!"_ZTSN3ads10basis_dataE", !19, i64 0, !23, i64 24, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !12, i64 72, !11, i64 96, !16, i64 152, !16, i64 160, !16, i64 168, !16, i64 176}
!19 = !{!"_ZTSSt6vectorIiSaIiEE", !20, i64 0}
!20 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !16, i64 0, !16, i64 8, !16, i64 16}
!23 = !{!"_ZTSSt6vectorISt4pairIiiESaIS1_EE", !24, i64 0}
!24 = !{!"_ZTSSt12_Vector_baseISt4pairIiiESaIS1_EE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseISt4pairIiiESaIS1_EE12_Vector_implE", !26, i64 0}
!26 = !{!"_ZTSNSt12_Vector_baseISt4pairIiiESaIS1_EE17_Vector_impl_dataE", !16, i64 0, !16, i64 8, !16, i64 16}
!27 = !{!"_ZTSN3ads3lin10solver_ctxE", !19, i64 0, !7, i64 24, !7, i64 28}
!28 = !{!10, !10, i64 0}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}


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