; LLVM IR from JoshuaSBrown/QC_Tools :: src/libcatnip/matrix.ll (ZN6catnip6MatrixC2Eiii)

; 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.catnip::Matrix" = type { i32, i32, i32, ptr }

@.str.25 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [54 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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 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: mustprogress uwtable
define dso_local void @_ZN6catnip6MatrixC2Eiii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) unnamed_addr #5 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 1
  br i1 %15, label %16, label %18

16:                                               ; preds = %4
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.25)
  call void @exit(i32 noundef 1) #6
  unreachable

18:                                               ; preds = %4
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 1
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.26)
  call void @exit(i32 noundef 1) #6
  unreachable

23:                                               ; preds = %18
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 1
  br i1 %25, label %26, label %28

26:                                               ; preds = %23
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.27)
  call void @exit(i32 noundef 1) #6
  unreachable

28:                                               ; preds = %23
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 0
  store i32 %31, ptr %32, align 8, !tbaa !11
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 1
  store i32 %33, ptr %34, align 4, !tbaa !13
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 2
  store i32 %35, ptr %36, align 8, !tbaa !14
  %37 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !13
  %41 = mul nsw i32 %38, %40
  %42 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 2
  %43 = load i32, ptr %42, align 8, !tbaa !14
  %44 = mul nsw i32 %41, %43
  %45 = sext i32 %44 to i64
  %46 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %45, i64 8)
  %47 = extractvalue { i64, i1 } %46, 1
  %48 = extractvalue { i64, i1 } %46, 0
  %49 = select i1 %47, i64 -1, i64 %48
  %50 = call noalias noundef nonnull ptr @_Znam(i64 noundef %49) #7
  %51 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 3
  store ptr %50, ptr %51, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %102, %30
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !11
  %56 = icmp sle i32 %53, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %52
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  br label %105

58:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #8
  store i32 1, ptr %11, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %98, %58
  %60 = load i32, ptr %11, align 4, !tbaa !9
  %61 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 1
  %62 = load i32, ptr %61, align 4, !tbaa !13
  %63 = icmp sle i32 %60, %62
  br i1 %63, label %65, label %64

64:                                               ; preds = %59
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #8
  br label %101

65:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #8
  store i32 1, ptr %12, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %94, %65
  %67 = load i32, ptr %12, align 4, !tbaa !9
  %68 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 2
  %69 = load i32, ptr %68, align 8, !tbaa !14
  %70 = icmp sle i32 %67, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %66
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  br label %97

72:                                               ; preds = %66
  %73 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 3
  %74 = load ptr, ptr %73, align 8, !tbaa !15
  %75 = load i32, ptr %9, align 4, !tbaa !9
  %76 = sub nsw i32 %75, 1
  %77 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 1
  %78 = load i32, ptr %77, align 4, !tbaa !13
  %79 = mul nsw i32 %76, %78
  %80 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 2
  %81 = load i32, ptr %80, align 8, !tbaa !14
  %82 = mul nsw i32 %79, %81
  %83 = load i32, ptr %11, align 4, !tbaa !9
  %84 = sub nsw i32 %83, 1
  %85 = getelementptr inbounds %"class.catnip::Matrix", ptr %13, i32 0, i32 2
  %86 = load i32, ptr %85, align 8, !tbaa !14
  %87 = mul nsw i32 %84, %86
  %88 = add nsw i32 %82, %87
  %89 = load i32, ptr %12, align 4, !tbaa !9
  %90 = add nsw i32 %88, %89
  %91 = sub nsw i32 %90, 1
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds double, ptr %74, i64 %92
  store double 0.000000e+00, ptr %93, align 8, !tbaa !16
  br label %94

94:                                               ; preds = %72
  %95 = load i32, ptr %12, align 4, !tbaa !9
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %12, align 4, !tbaa !9
  br label %66, !llvm.loop !18

97:                                               ; preds = %71
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %11, align 4, !tbaa !9
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %11, align 4, !tbaa !9
  br label %59, !llvm.loop !20

101:                                              ; preds = %64
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %9, align 4, !tbaa !9
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %9, align 4, !tbaa !9
  br label %52, !llvm.loop !21

105:                                              ; preds = %57
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { noreturn 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 = { 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 #6 = { noreturn nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { 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 = !{!"_ZTSN6catnip6MatrixE", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !6, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = distinct !{!21, !19}


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

@.str.25 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6catnip6MatrixC2Eiii(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) unnamed_addr #3 align 2 {
  %5 = icmp slt i32 %1, 1
  br i1 %5, label %6, label %8

6:                                                ; preds = %4
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.25)
  tail call void @exit(i32 noundef 1) #5
  unreachable

8:                                                ; preds = %4
  %9 = icmp slt i32 %2, 1
  br i1 %9, label %10, label %12

10:                                               ; preds = %8
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.26)
  tail call void @exit(i32 noundef 1) #5
  unreachable

12:                                               ; preds = %8
  %13 = icmp slt i32 %3, 1
  br i1 %13, label %14, label %.preheader23.preheader

14:                                               ; preds = %12
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.27)
  tail call void @exit(i32 noundef 1) #5
  unreachable

.preheader23.preheader:                           ; preds = %12
  store i32 %1, ptr %0, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %2, ptr %16, align 4, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %3, ptr %17, align 8, !tbaa !12
  %18 = mul nuw nsw i32 %2, %1
  %19 = mul nuw nsw i32 %18, %3
  %20 = zext nneg i32 %19 to i64
  %21 = shl nuw nsw i64 %20, 3
  %22 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %21) #6
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %22, ptr %23, align 8, !tbaa !13
  %scevgep = getelementptr i8, ptr %22, i64 -8
  %24 = mul i32 %3, %2
  %25 = zext nneg i32 %3 to i64
  %26 = shl nuw nsw i64 %25, 3
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %27 = icmp ult i32 %2, 4
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader23

.preheader23:                                     ; preds = %.preheader23.preheader, %._crit_edge28.split
  %indvar = phi i32 [ 0, %.preheader23.preheader ], [ %indvar.next, %._crit_edge28.split ]
  %28 = mul i32 %24, %indvar
  %29 = add i32 %28, 1
  br i1 %27, label %._crit_edge28.split.unr-lcssa, label %.preheader

._crit_edge31:                                    ; preds = %._crit_edge28.split
  ret void

.preheader:                                       ; preds = %.preheader23, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.preheader ], [ 0, %.preheader23 ]
  %niter = phi i64 [ %niter.next.3, %.preheader ], [ 0, %.preheader23 ]
  %30 = trunc nuw nsw i64 %indvars.iv to i32
  %31 = mul i32 %30, %3
  %32 = add i32 %29, %31
  %33 = sext i32 %32 to i64
  %34 = shl nsw i64 %33, 3
  %scevgep39 = getelementptr i8, ptr %scevgep, i64 %34
  tail call void @llvm.memset.p0.i64(ptr align 8 %scevgep39, i8 0, i64 %26, i1 false), !tbaa !14
  %35 = trunc i64 %indvars.iv to i32
  %36 = or disjoint i32 %35, 1
  %37 = mul i32 %36, %3
  %38 = add i32 %29, %37
  %39 = sext i32 %38 to i64
  %40 = shl nsw i64 %39, 3
  %scevgep39.1 = getelementptr i8, ptr %scevgep, i64 %40
  tail call void @llvm.memset.p0.i64(ptr align 8 %scevgep39.1, i8 0, i64 %26, i1 false), !tbaa !14
  %41 = trunc i64 %indvars.iv to i32
  %42 = or disjoint i32 %41, 2
  %43 = mul i32 %42, %3
  %44 = add i32 %29, %43
  %45 = sext i32 %44 to i64
  %46 = shl nsw i64 %45, 3
  %scevgep39.2 = getelementptr i8, ptr %scevgep, i64 %46
  tail call void @llvm.memset.p0.i64(ptr align 8 %scevgep39.2, i8 0, i64 %26, i1 false), !tbaa !14
  %47 = trunc i64 %indvars.iv to i32
  %48 = or disjoint i32 %47, 3
  %49 = mul i32 %48, %3
  %50 = add i32 %29, %49
  %51 = sext i32 %50 to i64
  %52 = shl nsw i64 %51, 3
  %scevgep39.3 = getelementptr i8, ptr %scevgep, i64 %52
  tail call void @llvm.memset.p0.i64(ptr align 8 %scevgep39.3, i8 0, i64 %26, i1 false), !tbaa !14
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge28.split.unr-lcssa, label %.preheader, !llvm.loop !16

._crit_edge28.split.unr-lcssa:                    ; preds = %.preheader, %.preheader23
  %indvars.iv.unr = phi i64 [ 0, %.preheader23 ], [ %indvars.iv.next.3, %.preheader ]
  br i1 %lcmp.mod.not, label %._crit_edge28.split, label %.preheader.epil

.preheader.epil:                                  ; preds = %._crit_edge28.split.unr-lcssa, %.preheader.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.preheader.epil ], [ %indvars.iv.unr, %._crit_edge28.split.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.epil ], [ 0, %._crit_edge28.split.unr-lcssa ]
  %53 = trunc nuw nsw i64 %indvars.iv.epil to i32
  %54 = mul i32 %53, %3
  %55 = add i32 %29, %54
  %56 = sext i32 %55 to i64
  %57 = shl nsw i64 %56, 3
  %scevgep39.epil = getelementptr i8, ptr %scevgep, i64 %57
  tail call void @llvm.memset.p0.i64(ptr align 8 %scevgep39.epil, i8 0, i64 %26, i1 false), !tbaa !14
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge28.split, label %.preheader.epil, !llvm.loop !18

._crit_edge28.split:                              ; preds = %.preheader.epil, %._crit_edge28.split.unr-lcssa
  %indvar.next = add nuw nsw i32 %indvar, 1
  %exitcond42.not = icmp eq i32 %indvar.next, %1
  br i1 %exitcond42.not, label %._crit_edge31, label %.preheader23, !llvm.loop !20
}

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

attributes #0 = { nofree 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 #1 = { noreturn 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 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 nounwind willreturn memory(argmem: write) }
attributes #5 = { noreturn nounwind }
attributes #6 = { builtin allocsize(0) }

!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 = !{!"_ZTSN6catnip6MatrixE", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !10, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !17}


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