; LLVM IR from sourceryinstitute/MORFEUS-Source :: src/FV/src/mesh_optimize/OptMS (SMuntangle)

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

; 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: nounwind uwtable
define dso_local i32 @SMgetActiveMatrix(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %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
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %45, %4
  %14 = load i32, ptr %11, align 4, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %48

17:                                               ; preds = %13
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %41, %17
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %44

22:                                               ; preds = %18
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds ptr, ptr %23, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %27, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i32, ptr %12, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %12, align 4, !tbaa !9
  %39 = sext i32 %37 to i64
  %40 = getelementptr inbounds double, ptr %36, i64 %39
  store double %35, ptr %40, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %22
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %10, align 4, !tbaa !9
  br label %18, !llvm.loop !13

44:                                               ; preds = %18
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %11, align 4, !tbaa !9
  br label %13, !llvm.loop !15

48:                                               ; preds = %13
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @SMgetActiveMatrix(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.preheader.us.preheader, label %._crit_edge18

.preheader.us.preheader:                          ; preds = %4
  %wide.trip.count27 = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count27, 3
  %6 = icmp ult i32 %1, 4
  %unroll_iter = and i64 %wide.trip.count27, 2147483644
  %invariant.gep = getelementptr i8, ptr %3, i64 8
  %invariant.gep30 = getelementptr i8, ptr %3, i64 16
  %invariant.gep32 = getelementptr i8, ptr %3, i64 24
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv24 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next25, %._crit_edge.us ]
  %.017.us = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next.lcssa, %._crit_edge.us ]
  %7 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv24
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %sext = shl i64 %.017.us, 32
  %10 = ashr exact i64 %sext, 32
  br i1 %6, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv19 = phi i64 [ %indvars.iv.next20.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.preheader.us.new ], [ %10, %.preheader.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %11 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv19
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds double, ptr %12, i64 %9
  %14 = load double, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds double, ptr %3, i64 %indvars.iv
  store double %14, ptr %15, align 8, !tbaa !11
  %indvars.iv.next20 = or disjoint i64 %indvars.iv19, 1
  %16 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next20
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds double, ptr %17, i64 %9
  %19 = load double, ptr %18, align 8, !tbaa !11
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv
  store double %19, ptr %gep, align 8, !tbaa !11
  %indvars.iv.next20.1 = or disjoint i64 %indvars.iv19, 2
  %20 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next20.1
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds double, ptr %21, i64 %9
  %23 = load double, ptr %22, align 8, !tbaa !11
  %gep31 = getelementptr double, ptr %invariant.gep30, i64 %indvars.iv
  store double %23, ptr %gep31, align 8, !tbaa !11
  %indvars.iv.next20.2 = or disjoint i64 %indvars.iv19, 3
  %24 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next20.2
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds double, ptr %25, i64 %9
  %27 = load double, ptr %26, align 8, !tbaa !11
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %gep33 = getelementptr double, ptr %invariant.gep32, i64 %indvars.iv
  store double %27, ptr %gep33, align 8, !tbaa !11
  %indvars.iv.next20.3 = add nuw nsw i64 %indvars.iv19, 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_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !13

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %indvars.iv.next.lcssa.ph = phi i64 [ poison, %.preheader.us ], [ %indvars.iv.next.3, %.preheader.us.new ]
  %indvars.iv19.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next20.3, %.preheader.us.new ]
  %indvars.iv.unr = phi i64 [ %10, %.preheader.us ], [ %indvars.iv.next.3, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %indvars.iv19.epil = phi i64 [ %indvars.iv.next20.epil, %.epil.preheader ], [ %indvars.iv19.unr, %._crit_edge.us.unr-lcssa ]
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %28 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv19.epil
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds double, ptr %29, i64 %9
  %31 = load double, ptr %30, align 8, !tbaa !11
  %indvars.iv.next.epil = add nsw i64 %indvars.iv.epil, 1
  %32 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.epil
  store double %31, ptr %32, align 8, !tbaa !11
  %indvars.iv.next20.epil = add nuw nsw i64 %indvars.iv19.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_edge.us, label %.epil.preheader, !llvm.loop !15

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %indvars.iv.next.lcssa = phi i64 [ %indvars.iv.next.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %indvars.iv.next.epil, %.epil.preheader ]
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %exitcond28.not = icmp eq i64 %indvars.iv.next25, %wide.trip.count27
  br i1 %exitcond28.not, label %._crit_edge18, label %.preheader.us, !llvm.loop !17

._crit_edge18:                                    ; preds = %._crit_edge.us, %4
  ret i32 0
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = distinct !{!17, !14}


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