; LLVM IR from sp-nitech/SPTK :: src/math/matrix.ll (ZNK4sptk6Matrix12GetSubmatrixEiiiiPS0_)

; 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.sptk::Matrix" = type { ptr, i32, i32, %"class.std::vector", %"class.std::vector.0" }
%"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.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = 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 }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPdSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; 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
declare dso_local void @_ZN4sptk6Matrix6ResizeEii(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef, i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPdSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk6Matrix12GetSubmatrixEiiiiPS0_(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #2 align 2 {
  %7 = alloca i1, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %49, label %20

20:                                               ; preds = %6
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = icmp sle i32 %21, 0
  br i1 %22, label %49, label %23

23:                                               ; preds = %20
  %24 = getelementptr inbounds %"class.sptk::Matrix", ptr %17, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = add nsw i32 %26, %27
  %29 = icmp slt i32 %25, %28
  br i1 %29, label %49, label %30

30:                                               ; preds = %23
  %31 = load i32, ptr %11, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %49, label %33

33:                                               ; preds = %30
  %34 = load i32, ptr %12, align 4, !tbaa !9
  %35 = icmp sle i32 %34, 0
  br i1 %35, label %49, label %36

36:                                               ; preds = %33
  %37 = getelementptr inbounds %"class.sptk::Matrix", ptr %17, i32 0, i32 2
  %38 = load i32, ptr %37, align 4, !tbaa !21
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = add nsw i32 %39, %40
  %42 = icmp slt i32 %38, %41
  br i1 %42, label %49, label %43

43:                                               ; preds = %36
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = icmp eq ptr null, %44
  br i1 %45, label %49, label %46

46:                                               ; preds = %43
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = icmp eq ptr %17, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %46, %43, %36, %33, %30, %23, %20, %6
  store i1 false, ptr %7, align 1
  br label %109

50:                                               ; preds = %46
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = getelementptr inbounds %"class.sptk::Matrix", ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = icmp ne i32 %53, %54
  br i1 %55, label %62, label %56

56:                                               ; preds = %50
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = getelementptr inbounds %"class.sptk::Matrix", ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !21
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = icmp ne i32 %59, %60
  br i1 %61, label %62, label %66

62:                                               ; preds = %56, %50
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = load i32, ptr %12, align 4, !tbaa !9
  call void @_ZN4sptk6Matrix6ResizeEii(ptr noundef nonnull align 8 dereferenceable(64) %63, i32 noundef %64, i32 noundef %65)
  br label %66

66:                                               ; preds = %62, %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %105, %66
  %68 = load i32, ptr %14, align 4, !tbaa !9
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = icmp slt i32 %68, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %67
  store i32 2, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %108

72:                                               ; preds = %67
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %73

73:                                               ; preds = %101, %72
  %74 = load i32, ptr %16, align 4, !tbaa !9
  %75 = load i32, ptr %12, align 4, !tbaa !9
  %76 = icmp slt i32 %74, %75
  br i1 %76, label %78, label %77

77:                                               ; preds = %73
  store i32 5, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %104

78:                                               ; preds = %73
  %79 = getelementptr inbounds %"class.sptk::Matrix", ptr %17, i32 0, i32 4
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = load i32, ptr %14, align 4, !tbaa !9
  %82 = add nsw i32 %80, %81
  %83 = sext i32 %82 to i64
  %84 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPdSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %79, i64 noundef %83) #3
  %85 = load ptr, ptr %84, align 8, !tbaa !5
  %86 = load i32, ptr %11, align 4, !tbaa !9
  %87 = load i32, ptr %16, align 4, !tbaa !9
  %88 = add nsw i32 %86, %87
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds double, ptr %85, i64 %89
  %91 = load double, ptr %90, align 8, !tbaa !22
  %92 = load ptr, ptr %13, align 8, !tbaa !5
  %93 = getelementptr inbounds %"class.sptk::Matrix", ptr %92, i32 0, i32 4
  %94 = load i32, ptr %14, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPdSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %93, i64 noundef %95) #3
  %97 = load ptr, ptr %96, align 8, !tbaa !5
  %98 = load i32, ptr %16, align 4, !tbaa !9
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds double, ptr %97, i64 %99
  store double %91, ptr %100, align 8, !tbaa !22
  br label %101

101:                                              ; preds = %78
  %102 = load i32, ptr %16, align 4, !tbaa !9
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %16, align 4, !tbaa !9
  br label %73, !llvm.loop !24

104:                                              ; preds = %77
  br label %105

105:                                              ; preds = %104
  %106 = load i32, ptr %14, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %14, align 4, !tbaa !9
  br label %67, !llvm.loop !26

108:                                              ; preds = %71
  store i1 true, ptr %7, align 1
  br label %109

109:                                              ; preds = %108, %49
  %110 = load i1, ptr %7, align 1
  ret i1 %110
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"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 8}
!12 = !{!"_ZTSN4sptk6MatrixE", !10, i64 8, !10, i64 12, !13, i64 16, !17, i64 40}
!13 = !{!"_ZTSSt6vectorIdSaIdEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"_ZTSSt6vectorIPdSaIS0_EE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseIPdSaIS0_EE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIPdSaIS0_EE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIPdSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!12, !10, i64 12}
!22 = !{!23, !23, i64 0}
!23 = !{!"double", !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}


; 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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPdSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4sptk6Matrix6ResizeEii(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPdSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk6Matrix12GetSubmatrixEiiiiPS0_(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) local_unnamed_addr #1 align 2 {
  %7 = icmp slt i32 %1, 0
  %8 = icmp slt i32 %2, 1
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %.loopexit, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %12 = add nuw nsw i32 %2, %1
  %13 = icmp slt i32 %11, %12
  %14 = icmp slt i32 %3, 0
  %or.cond3 = or i1 %14, %13
  %15 = icmp slt i32 %4, 1
  %or.cond5 = or i1 %15, %or.cond3
  br i1 %or.cond5, label %.loopexit, label %16

16:                                               ; preds = %9
  %17 = getelementptr inbounds i8, ptr %0, i64 12
  %18 = load i32, ptr %17, align 4, !tbaa !19
  %19 = add nuw nsw i32 %4, %3
  %20 = icmp slt i32 %18, %19
  %21 = icmp eq ptr %5, null
  %or.cond7 = or i1 %21, %20
  %22 = icmp eq ptr %0, %5
  %or.cond9 = or i1 %22, %or.cond7
  br i1 %or.cond9, label %.loopexit, label %23

23:                                               ; preds = %16
  %24 = getelementptr inbounds i8, ptr %5, i64 8
  %25 = load i32, ptr %24, align 8, !tbaa !5
  %.not = icmp eq i32 %25, %2
  br i1 %.not, label %26, label %29

26:                                               ; preds = %23
  %27 = getelementptr inbounds i8, ptr %5, i64 12
  %28 = load i32, ptr %27, align 4, !tbaa !19
  %.not48 = icmp eq i32 %28, %4
  br i1 %.not48, label %.preheader.us.preheader, label %29

29:                                               ; preds = %26, %23
  tail call void @_ZN4sptk6Matrix6ResizeEii(ptr noundef nonnull align 8 dereferenceable(64) %5, i32 noundef %2, i32 noundef %4)
  br label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %29, %26
  %30 = getelementptr inbounds i8, ptr %0, i64 40
  %31 = getelementptr inbounds i8, ptr %5, i64 40
  %32 = zext nneg i32 %3 to i64
  %33 = zext nneg i32 %1 to i64
  %wide.trip.count56 = zext nneg i32 %2 to i64
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv53 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next54, %._crit_edge.us ]
  %34 = add nuw nsw i64 %indvars.iv53, %33
  br label %35

35:                                               ; preds = %.preheader.us, %35
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %35 ]
  %36 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPdSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %34) #2
  %37 = load ptr, ptr %36, align 8, !tbaa !20
  %38 = getelementptr inbounds double, ptr %37, i64 %indvars.iv
  %39 = getelementptr inbounds double, ptr %38, i64 %32
  %40 = load double, ptr %39, align 8, !tbaa !21
  %41 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPdSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %31, i64 noundef %indvars.iv53) #2
  %42 = load ptr, ptr %41, align 8, !tbaa !20
  %43 = getelementptr inbounds double, ptr %42, i64 %indvars.iv
  store double %40, ptr %43, align 8, !tbaa !21
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %35, !llvm.loop !23

._crit_edge.us:                                   ; preds = %35
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %exitcond57.not = icmp eq i64 %indvars.iv.next54, %wide.trip.count56
  br i1 %exitcond57.not, label %.loopexit, label %.preheader.us, !llvm.loop !25

.loopexit:                                        ; preds = %._crit_edge.us, %6, %9, %16
  %.041 = phi i1 [ false, %16 ], [ false, %9 ], [ false, %6 ], [ true, %._crit_edge.us ]
  ret i1 %.041
}

attributes #0 = { 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 #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 = { 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, !7, i64 8}
!6 = !{!"_ZTSN4sptk6MatrixE", !7, i64 8, !7, i64 12, !10, i64 16, !15, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIdSaIdEE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"_ZTSSt6vectorIPdSaIS0_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIPdSaIS0_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIPdSaIS0_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIPdSaIS0_EE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!19 = !{!6, !7, i64 12}
!20 = !{!14, !14, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"double", !8, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass