; LLVM IR from sp-nitech/SPTK :: third_party/REAPER/core/float_matrix.ll (ZN4sptk6reaper11FloatMatrix6resizeEjj)

; 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::reaper::FloatMatrix" = type { ptr, i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4sptk6reaper11FloatMatrix6resizeEjj(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  %12 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %34

15:                                               ; preds = %3
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = mul i32 %16, %17
  %19 = zext i32 %18 to i64
  %20 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %19, i64 4)
  %21 = extractvalue { i64, i1 } %20, 1
  %22 = extractvalue { i64, i1 } %20, 0
  %23 = select i1 %21, i64 -1, i64 %22
  %24 = call noalias noundef nonnull ptr @_Znam(i64 noundef %23) #7
  %25 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 0
  store ptr %24, ptr %25, align 8, !tbaa !11
  %26 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = mul i64 4, %29
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = mul i64 %30, %32
  call void @llvm.memset.p0.i64(ptr align 4 %27, i8 0, i64 %33, i1 false)
  br label %119

34:                                               ; preds = %3
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !13
  %38 = icmp eq i32 %35, %37
  br i1 %38, label %39, label %45

39:                                               ; preds = %34
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 2
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = icmp eq i32 %40, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %39
  br label %124

45:                                               ; preds = %39, %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #8
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = mul i32 %46, %47
  %49 = zext i32 %48 to i64
  %50 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %49, i64 4)
  %51 = extractvalue { i64, i1 } %50, 1
  %52 = extractvalue { i64, i1 } %50, 0
  %53 = select i1 %51, i64 -1, i64 %52
  %54 = call noalias noundef nonnull ptr @_Znam(i64 noundef %53) #7
  store ptr %54, ptr %7, align 8, !tbaa !5
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = mul i64 4, %57
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = zext i32 %59 to i64
  %61 = mul i64 %58, %60
  call void @llvm.memset.p0.i64(ptr align 4 %55, i8 0, i64 %61, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  %62 = load i32, ptr %5, align 4, !tbaa !9
  %63 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 1
  %64 = load i32, ptr %63, align 8, !tbaa !13
  %65 = icmp ult i32 %62, %64
  br i1 %65, label %66, label %68

66:                                               ; preds = %45
  %67 = load i32, ptr %5, align 4, !tbaa !9
  br label %71

68:                                               ; preds = %45
  %69 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 1
  %70 = load i32, ptr %69, align 8, !tbaa !13
  br label %71

71:                                               ; preds = %68, %66
  %72 = phi i32 [ %67, %66 ], [ %70, %68 ]
  store i32 %72, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 2
  %75 = load i32, ptr %74, align 4, !tbaa !14
  %76 = icmp ult i32 %73, %75
  br i1 %76, label %77, label %79

77:                                               ; preds = %71
  %78 = load i32, ptr %6, align 4, !tbaa !9
  br label %82

79:                                               ; preds = %71
  %80 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 2
  %81 = load i32, ptr %80, align 4, !tbaa !14
  br label %82

82:                                               ; preds = %79, %77
  %83 = phi i32 [ %78, %77 ], [ %81, %79 ]
  store i32 %83, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #8
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %107, %82
  %85 = load i32, ptr %10, align 4, !tbaa !9
  %86 = load i32, ptr %9, align 4, !tbaa !9
  %87 = icmp slt i32 %85, %86
  br i1 %87, label %89, label %88

88:                                               ; preds = %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #8
  br label %110

89:                                               ; preds = %84
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = load i32, ptr %10, align 4, !tbaa !9
  %92 = load i32, ptr %5, align 4, !tbaa !9
  %93 = mul i32 %91, %92
  %94 = zext i32 %93 to i64
  %95 = getelementptr inbounds float, ptr %90, i64 %94
  %96 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 0
  %97 = load ptr, ptr %96, align 8, !tbaa !11
  %98 = load i32, ptr %10, align 4, !tbaa !9
  %99 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 1
  %100 = load i32, ptr %99, align 8, !tbaa !13
  %101 = mul i32 %98, %100
  %102 = zext i32 %101 to i64
  %103 = getelementptr inbounds float, ptr %97, i64 %102
  %104 = load i32, ptr %8, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = mul i64 %105, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %95, ptr align 4 %103, i64 %106, i1 false)
  br label %107

107:                                              ; preds = %89
  %108 = load i32, ptr %10, align 4, !tbaa !9
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %10, align 4, !tbaa !9
  br label %84, !llvm.loop !15

110:                                              ; preds = %88
  %111 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 0
  %112 = load ptr, ptr %111, align 8, !tbaa !11
  %113 = icmp eq ptr %112, null
  br i1 %113, label %115, label %114

114:                                              ; preds = %110
  call void @_ZdaPv(ptr noundef %112) #9
  br label %115

115:                                              ; preds = %114, %110
  %116 = load ptr, ptr %7, align 8, !tbaa !5
  %117 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 0
  store ptr %116, ptr %117, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #8
  br label %118

118:                                              ; preds = %115
  br label %119

119:                                              ; preds = %118, %15
  %120 = load i32, ptr %5, align 4, !tbaa !9
  %121 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 1
  store i32 %120, ptr %121, align 8, !tbaa !13
  %122 = load i32, ptr %6, align 4, !tbaa !9
  %123 = getelementptr inbounds %"class.sptk::reaper::FloatMatrix", ptr %11, i32 0, i32 2
  store i32 %122, ptr %123, align 4, !tbaa !14
  br label %124

124:                                              ; preds = %119, %44
  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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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

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 = { nobuiltin nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nobuiltin allocsize(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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { nounwind }
attributes #9 = { builtin 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, !6, i64 0}
!12 = !{!"_ZTSN4sptk6reaper11FloatMatrixE", !6, i64 0, !10, i64 8, !10, i64 12}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 12}
!15 = distinct !{!15, !16}
!16 = !{!"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 @_ZN4sptk6reaper11FloatMatrix6resizeEjj(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %15

6:                                                ; preds = %3
  %7 = mul i32 %2, %1
  %8 = zext i32 %7 to i64
  %9 = shl nuw nsw i64 %8, 2
  %10 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %9) #6
  store ptr %10, ptr %0, align 8, !tbaa !5
  %11 = zext i32 %1 to i64
  %12 = shl nuw nsw i64 %11, 2
  %13 = zext i32 %2 to i64
  %14 = mul i64 %12, %13
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %10, i8 0, i64 %14, i1 false)
  br label %59

15:                                               ; preds = %3
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp eq i32 %17, %1
  %19 = getelementptr inbounds i8, ptr %0, i64 12
  %20 = load i32, ptr %19, align 4
  %21 = icmp eq i32 %20, %2
  %or.cond = select i1 %18, i1 %21, i1 false
  br i1 %or.cond, label %62, label %22

22:                                               ; preds = %15
  %23 = mul i32 %2, %1
  %24 = zext i32 %23 to i64
  %25 = shl nuw nsw i64 %24, 2
  %26 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %25) #6
  %27 = zext i32 %1 to i64
  %28 = shl nuw nsw i64 %27, 2
  %29 = zext i32 %2 to i64
  %30 = mul i64 %28, %29
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %26, i8 0, i64 %30, i1 false)
  %31 = tail call i32 @llvm.umin.i32(i32 %20, i32 %2)
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %22
  %. = tail call i32 @llvm.umin.i32(i32 %17, i32 %1)
  %33 = sext i32 %. to i64
  %34 = shl nsw i64 %33, 2
  %wide.trip.count = zext nneg i32 %31 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %35 = icmp eq i32 %31, 1
  br i1 %35, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %36

36:                                               ; preds = %36, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %36 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %36 ]
  %37 = trunc nuw nsw i64 %indvars.iv to i32
  %38 = mul i32 %37, %1
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %26, i64 %39
  %41 = mul i32 %17, %37
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds float, ptr %4, i64 %42
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %40, ptr nonnull align 4 %43, i64 %34, i1 false)
  %44 = trunc i64 %indvars.iv to i32
  %45 = or disjoint i32 %44, 1
  %46 = mul i32 %45, %1
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds float, ptr %26, i64 %47
  %49 = mul i32 %17, %45
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds float, ptr %4, i64 %50
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %48, ptr nonnull align 4 %51, i64 %34, i1 false)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %36, !llvm.loop !12

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %36
  %52 = trunc nuw nsw i64 %indvars.iv.next.1 to i32
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph
  %indvars.iv.unr = phi i32 [ 0, %.lr.ph ], [ %52, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %53 = mul i32 %indvars.iv.unr, %1
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds float, ptr %26, i64 %54
  %56 = mul i32 %17, %indvars.iv.unr
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds float, ptr %4, i64 %57
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %55, ptr nonnull align 4 %58, i64 %34, i1 false)
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %22
  tail call void @_ZdaPv(ptr noundef %4) #7
  store ptr %26, ptr %0, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %._crit_edge, %6
  %60 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %1, ptr %60, align 8, !tbaa !11
  %61 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %2, ptr %61, align 4, !tbaa !14
  br label %62

62:                                               ; preds = %15, %59
  ret void
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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

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 = { nobuiltin nounwind "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 = { nobuiltin allocsize(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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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 0}
!6 = !{!"_ZTSN4sptk6reaper11FloatMatrixE", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !10, i64 12}


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