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

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

%struct.SMquality_table = type { i32, i32, i32, i32, ptr }
%struct.SMqualityMeasure = type { i32, [128 x i8], double, double, double, double, double, double, i32, i32 }

; 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 @SMinsertQualityInfo(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %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
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  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 i32 %3, ptr %8, align 4, !tbaa !9
  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 8, ptr %11) #2
  store double 1.000000e+300, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  store double -1.000000e+300, ptr %12, align 8, !tbaa !11
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.SMquality_table, ptr %14, i32 0, i32 4
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds ptr, ptr %16, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.SMqualityMeasure, ptr %20, i32 0, i32 8
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = add nsw i32 %22, %13
  store i32 %23, ptr %21, align 8, !tbaa !15
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SMquality_table, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds ptr, ptr %26, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.SMqualityMeasure, ptr %30, i32 0, i32 9
  %32 = load i32, ptr %31, align 4, !tbaa !17
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %31, align 4, !tbaa !17
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %82, %4
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %38, label %85

38:                                               ; preds = %34
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %39, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !11
  %44 = load double, ptr %11, align 8, !tbaa !11
  %45 = fcmp olt double %43, %44
  br i1 %45, label %46, label %52

46:                                               ; preds = %38
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds double, ptr %47, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !11
  store double %51, ptr %11, align 8, !tbaa !11
  br label %52

52:                                               ; preds = %46, %38
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds double, ptr %53, i64 %55
  %57 = load double, ptr %56, align 8, !tbaa !11
  %58 = load double, ptr %12, align 8, !tbaa !11
  %59 = fcmp ogt double %57, %58
  br i1 %59, label %60, label %66

60:                                               ; preds = %52
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds double, ptr %61, i64 %63
  %65 = load double, ptr %64, align 8, !tbaa !11
  store double %65, ptr %12, align 8, !tbaa !11
  br label %66

66:                                               ; preds = %60, %52
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds double, ptr %67, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !11
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.SMquality_table, ptr %72, i32 0, i32 4
  %74 = load ptr, ptr %73, align 8, !tbaa !13
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds ptr, ptr %74, i64 %76
  %78 = load ptr, ptr %77, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.SMqualityMeasure, ptr %78, i32 0, i32 5
  %80 = load double, ptr %79, align 8, !tbaa !18
  %81 = fadd double %80, %71
  store double %81, ptr %79, align 8, !tbaa !18
  br label %82

82:                                               ; preds = %66
  %83 = load i32, ptr %10, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %10, align 4, !tbaa !9
  br label %34, !llvm.loop !19

85:                                               ; preds = %34
  %86 = load double, ptr %11, align 8, !tbaa !11
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.SMquality_table, ptr %87, i32 0, i32 4
  %89 = load ptr, ptr %88, align 8, !tbaa !13
  %90 = load i32, ptr %6, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds ptr, ptr %89, i64 %91
  %93 = load ptr, ptr %92, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.SMqualityMeasure, ptr %93, i32 0, i32 3
  %95 = load double, ptr %94, align 8, !tbaa !21
  %96 = fcmp olt double %86, %95
  br i1 %96, label %97, label %107

97:                                               ; preds = %85
  %98 = load double, ptr %11, align 8, !tbaa !11
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.SMquality_table, ptr %99, i32 0, i32 4
  %101 = load ptr, ptr %100, align 8, !tbaa !13
  %102 = load i32, ptr %6, align 4, !tbaa !9
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds ptr, ptr %101, i64 %103
  %105 = load ptr, ptr %104, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.SMqualityMeasure, ptr %105, i32 0, i32 3
  store double %98, ptr %106, align 8, !tbaa !21
  br label %107

107:                                              ; preds = %97, %85
  %108 = load double, ptr %12, align 8, !tbaa !11
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.SMquality_table, ptr %109, i32 0, i32 4
  %111 = load ptr, ptr %110, align 8, !tbaa !13
  %112 = load i32, ptr %6, align 4, !tbaa !9
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds ptr, ptr %111, i64 %113
  %115 = load ptr, ptr %114, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.SMqualityMeasure, ptr %115, i32 0, i32 4
  %117 = load double, ptr %116, align 8, !tbaa !22
  %118 = fcmp ogt double %108, %117
  br i1 %118, label %119, label %129

119:                                              ; preds = %107
  %120 = load double, ptr %12, align 8, !tbaa !11
  %121 = load ptr, ptr %5, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.SMquality_table, ptr %121, i32 0, i32 4
  %123 = load ptr, ptr %122, align 8, !tbaa !13
  %124 = load i32, ptr %6, align 4, !tbaa !9
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds ptr, ptr %123, i64 %125
  %127 = load ptr, ptr %126, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.SMqualityMeasure, ptr %127, i32 0, i32 4
  store double %120, ptr %128, align 8, !tbaa !22
  br label %129

129:                                              ; preds = %119, %107
  %130 = load double, ptr %11, align 8, !tbaa !11
  %131 = load ptr, ptr %5, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.SMquality_table, ptr %131, i32 0, i32 4
  %133 = load ptr, ptr %132, align 8, !tbaa !13
  %134 = load i32, ptr %6, align 4, !tbaa !9
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds ptr, ptr %133, i64 %135
  %137 = load ptr, ptr %136, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.SMqualityMeasure, ptr %137, i32 0, i32 6
  %139 = load double, ptr %138, align 8, !tbaa !23
  %140 = fadd double %139, %130
  store double %140, ptr %138, align 8, !tbaa !23
  %141 = load double, ptr %12, align 8, !tbaa !11
  %142 = load ptr, ptr %5, align 8, !tbaa !5
  %143 = getelementptr inbounds %struct.SMquality_table, ptr %142, i32 0, i32 4
  %144 = load ptr, ptr %143, align 8, !tbaa !13
  %145 = load i32, ptr %6, align 4, !tbaa !9
  %146 = sext i32 %145 to i64
  %147 = getelementptr inbounds ptr, ptr %144, i64 %146
  %148 = load ptr, ptr %147, align 8, !tbaa !5
  %149 = getelementptr inbounds %struct.SMqualityMeasure, ptr %148, i32 0, i32 7
  %150 = load double, ptr %149, align 8, !tbaa !24
  %151 = fadd double %150, %141
  store double %151, ptr %149, align 8, !tbaa !24
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, 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 = !{!14, !6, i64 16}
!14 = !{!"SMquality_table", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16}
!15 = !{!16, !10, i64 184}
!16 = !{!"SMqualityMeasure", !10, i64 0, !7, i64 4, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !10, i64 184, !10, i64 188}
!17 = !{!16, !10, i64 188}
!18 = !{!16, !12, i64 160}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!16, !12, i64 144}
!22 = !{!16, !12, i64 152}
!23 = !{!16, !12, i64 168}
!24 = !{!16, !12, i64 176}


; 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(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @SMinsertQualityInfo(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = sext i32 %1 to i64
  %8 = getelementptr inbounds ptr, ptr %6, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %9, i64 184
  %11 = load <2 x i32>, ptr %10, align 8, !tbaa !12
  %12 = insertelement <2 x i32> <i32 poison, i32 1>, i32 %3, i64 0
  %13 = add nsw <2 x i32> %11, %12
  store <2 x i32> %13, ptr %10, align 8, !tbaa !12
  %14 = icmp sgt i32 %3, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %15 = getelementptr inbounds i8, ptr %9, i64 160
  %.promoted = load double, ptr %15, align 8, !tbaa !13
  %wide.trip.count = zext nneg i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %16 = icmp eq i32 %3, 1
  br i1 %16, 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 %17

17:                                               ; preds = %17, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %17 ]
  %18 = phi double [ %.promoted, %.lr.ph.new ], [ %35, %17 ]
  %19 = phi <2 x double> [ <double 1.000000e+300, double -1.000000e+300>, %.lr.ph.new ], [ %34, %17 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %17 ]
  %20 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  %21 = load double, ptr %20, align 8, !tbaa !16
  %22 = insertelement <2 x double> %19, double %21, i64 0
  %23 = insertelement <2 x double> %19, double %21, i64 1
  %24 = fcmp olt <2 x double> %22, %23
  %25 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
  %26 = select <2 x i1> %24, <2 x double> %25, <2 x double> %19
  %27 = fadd double %21, %18
  store double %27, ptr %15, align 8, !tbaa !13
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %28 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next
  %29 = load double, ptr %28, align 8, !tbaa !16
  %30 = insertelement <2 x double> %26, double %29, i64 0
  %31 = insertelement <2 x double> %26, double %29, i64 1
  %32 = fcmp olt <2 x double> %30, %31
  %33 = shufflevector <2 x double> %30, <2 x double> poison, <2 x i32> zeroinitializer
  %34 = select <2 x i1> %32, <2 x double> %33, <2 x double> %26
  %35 = fadd double %29, %27
  store double %35, ptr %15, align 8, !tbaa !13
  %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, label %17, !llvm.loop !17

._crit_edge.loopexit.unr-lcssa:                   ; preds = %17, %.lr.ph
  %.lcssa.ph = phi <2 x double> [ poison, %.lr.ph ], [ %34, %17 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %17 ]
  %.unr = phi double [ %.promoted, %.lr.ph ], [ %35, %17 ]
  %.unr49 = phi <2 x double> [ <double 1.000000e+300, double -1.000000e+300>, %.lr.ph ], [ %34, %17 ]
  %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
  %36 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.unr
  %37 = load double, ptr %36, align 8, !tbaa !16
  %38 = insertelement <2 x double> %.unr49, double %37, i64 0
  %39 = insertelement <2 x double> %.unr49, double %37, i64 1
  %40 = fcmp olt <2 x double> %38, %39
  %41 = shufflevector <2 x double> %38, <2 x double> poison, <2 x i32> zeroinitializer
  %42 = select <2 x i1> %40, <2 x double> %41, <2 x double> %.unr49
  %43 = fadd double %37, %.unr
  store double %43, ptr %15, align 8, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %4
  %44 = phi <2 x double> [ <double 1.000000e+300, double -1.000000e+300>, %4 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %42, %._crit_edge.loopexit.epilog-lcssa ]
  %45 = getelementptr inbounds i8, ptr %9, i64 144
  %46 = load double, ptr %45, align 8, !tbaa !19
  %47 = extractelement <2 x double> %44, i64 0
  %48 = fcmp olt double %47, %46
  br i1 %48, label %49, label %50

49:                                               ; preds = %._crit_edge
  store double %47, ptr %45, align 8, !tbaa !19
  br label %50

50:                                               ; preds = %49, %._crit_edge
  %51 = getelementptr inbounds i8, ptr %9, i64 152
  %52 = load double, ptr %51, align 8, !tbaa !20
  %53 = extractelement <2 x double> %44, i64 1
  %54 = fcmp ogt double %53, %52
  br i1 %54, label %55, label %56

55:                                               ; preds = %50
  store double %53, ptr %51, align 8, !tbaa !20
  br label %56

56:                                               ; preds = %55, %50
  %57 = getelementptr inbounds i8, ptr %9, i64 168
  %58 = load <2 x double>, ptr %57, align 8, !tbaa !16
  %59 = fadd <2 x double> %44, %58
  store <2 x double> %59, ptr %57, align 8, !tbaa !16
  ret i32 0
}

attributes #0 = { nofree norecurse nosync nounwind memory(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, !10, i64 16}
!6 = !{!"SMquality_table", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !15, i64 160}
!14 = !{!"SMqualityMeasure", !7, i64 0, !8, i64 4, !15, i64 136, !15, i64 144, !15, i64 152, !15, i64 160, !15, i64 168, !15, i64 176, !7, i64 184, !7, i64 188}
!15 = !{!"double", !8, i64 0}
!16 = !{!15, !15, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!14, !15, i64 144}
!20 = !{!14, !15, i64 152}


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