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

; 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.DERIV_TYPE = type { double, [3 x double] }

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; 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 @g_ad_dMagnitude(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.DERIV_TYPE, align 8
  %8 = alloca %struct.DERIV_TYPE, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %56, %2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 3
  br i1 %11, label %12, label %59

12:                                               ; preds = %9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.DERIV_TYPE, ptr %13, i64 0
  %15 = getelementptr inbounds %struct.DERIV_TYPE, ptr %14, i32 0, i32 0
  %16 = load double, ptr %15, align 8, !tbaa !11
  %17 = fmul double 2.000000e+00, %16
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.DERIV_TYPE, ptr %18, i64 0
  %20 = getelementptr inbounds %struct.DERIV_TYPE, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [3 x double], ptr %20, i64 0, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !14
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.DERIV_TYPE, ptr %25, i64 1
  %27 = getelementptr inbounds %struct.DERIV_TYPE, ptr %26, i32 0, i32 0
  %28 = load double, ptr %27, align 8, !tbaa !11
  %29 = fmul double 2.000000e+00, %28
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.DERIV_TYPE, ptr %30, i64 1
  %32 = getelementptr inbounds %struct.DERIV_TYPE, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [3 x double], ptr %32, i64 0, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !14
  %37 = fmul double %29, %36
  %38 = call double @llvm.fmuladd.f64(double %17, double %24, double %37)
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.DERIV_TYPE, ptr %39, i64 2
  %41 = getelementptr inbounds %struct.DERIV_TYPE, ptr %40, i32 0, i32 0
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = fmul double 2.000000e+00, %42
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.DERIV_TYPE, ptr %44, i64 2
  %46 = getelementptr inbounds %struct.DERIV_TYPE, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [3 x double], ptr %46, i64 0, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !14
  %51 = call double @llvm.fmuladd.f64(double %43, double %50, double %38)
  %52 = getelementptr inbounds %struct.DERIV_TYPE, ptr %7, i32 0, i32 1
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [3 x double], ptr %52, i64 0, i64 %54
  store double %51, ptr %55, align 8, !tbaa !14
  br label %56

56:                                               ; preds = %12
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !15

59:                                               ; preds = %9
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.DERIV_TYPE, ptr %60, i64 0
  %62 = getelementptr inbounds %struct.DERIV_TYPE, ptr %61, i32 0, i32 0
  %63 = load double, ptr %62, align 8, !tbaa !11
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.DERIV_TYPE, ptr %64, i64 0
  %66 = getelementptr inbounds %struct.DERIV_TYPE, ptr %65, i32 0, i32 0
  %67 = load double, ptr %66, align 8, !tbaa !11
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.DERIV_TYPE, ptr %68, i64 1
  %70 = getelementptr inbounds %struct.DERIV_TYPE, ptr %69, i32 0, i32 0
  %71 = load double, ptr %70, align 8, !tbaa !11
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.DERIV_TYPE, ptr %72, i64 1
  %74 = getelementptr inbounds %struct.DERIV_TYPE, ptr %73, i32 0, i32 0
  %75 = load double, ptr %74, align 8, !tbaa !11
  %76 = fmul double %71, %75
  %77 = call double @llvm.fmuladd.f64(double %63, double %67, double %76)
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.DERIV_TYPE, ptr %78, i64 2
  %80 = getelementptr inbounds %struct.DERIV_TYPE, ptr %79, i32 0, i32 0
  %81 = load double, ptr %80, align 8, !tbaa !11
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.DERIV_TYPE, ptr %82, i64 2
  %84 = getelementptr inbounds %struct.DERIV_TYPE, ptr %83, i32 0, i32 0
  %85 = load double, ptr %84, align 8, !tbaa !11
  %86 = call double @llvm.fmuladd.f64(double %81, double %85, double %77)
  %87 = getelementptr inbounds %struct.DERIV_TYPE, ptr %7, i32 0, i32 0
  store double %86, ptr %87, align 8, !tbaa !11
  call void @g_ad_sqrt(ptr noundef %8, ptr noundef byval(%struct.DERIV_TYPE) align 8 %7)
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %88

88:                                               ; preds = %102, %59
  %89 = load i32, ptr %6, align 4, !tbaa !9
  %90 = icmp slt i32 %89, 3
  br i1 %90, label %91, label %105

91:                                               ; preds = %88
  %92 = getelementptr inbounds %struct.DERIV_TYPE, ptr %8, i32 0, i32 1
  %93 = load i32, ptr %6, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [3 x double], ptr %92, i64 0, i64 %94
  %96 = load double, ptr %95, align 8, !tbaa !14
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.DERIV_TYPE, ptr %97, i32 0, i32 1
  %99 = load i32, ptr %6, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [3 x double], ptr %98, i64 0, i64 %100
  store double %96, ptr %101, align 8, !tbaa !14
  br label %102

102:                                              ; preds = %91
  %103 = load i32, ptr %6, align 4, !tbaa !9
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %6, align 4, !tbaa !9
  br label %88, !llvm.loop !17

105:                                              ; preds = %88
  %106 = getelementptr inbounds %struct.DERIV_TYPE, ptr %8, i32 0, i32 0
  %107 = load double, ptr %106, align 8, !tbaa !11
  %108 = load ptr, ptr %3, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.DERIV_TYPE, ptr %108, i32 0, i32 0
  store double %107, ptr %109, align 8, !tbaa !11
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 0
}

declare void @g_ad_sqrt(ptr noundef, ptr noundef byval(%struct.DERIV_TYPE) align 8) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { "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 = { 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, !13, i64 0}
!12 = !{!"DERIV_TYPE", !13, i64 0, !7, i64 8}
!13 = !{!"double", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

%struct.DERIV_TYPE = type { double, [3 x double] }

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

; Function Attrs: mustprogress 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 noundef i32 @g_ad_dMagnitude(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = alloca %struct.DERIV_TYPE, align 16
  %4 = alloca %struct.DERIV_TYPE, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #5
  %5 = getelementptr inbounds i8, ptr %1, i64 32
  %6 = getelementptr inbounds i8, ptr %1, i64 64
  %7 = getelementptr inbounds i8, ptr %1, i64 16
  %8 = getelementptr inbounds i8, ptr %1, i64 48
  %9 = getelementptr inbounds i8, ptr %1, i64 80
  %10 = getelementptr inbounds i8, ptr %3, i64 16
  %11 = load <2 x double>, ptr %1, align 8, !tbaa !5
  %12 = extractelement <2 x double> %11, i64 0
  %13 = fmul double %12, 2.000000e+00
  %14 = load <2 x double>, ptr %5, align 8, !tbaa !5
  %15 = extractelement <2 x double> %14, i64 0
  %16 = fmul double %15, 2.000000e+00
  %17 = load <2 x double>, ptr %6, align 8, !tbaa !5
  %18 = extractelement <2 x double> %17, i64 0
  %19 = fmul double %18, 2.000000e+00
  %20 = load <2 x double>, ptr %7, align 8, !tbaa !5
  %21 = load <2 x double>, ptr %8, align 8, !tbaa !5
  %22 = load <2 x double>, ptr %9, align 8, !tbaa !5
  %23 = insertelement <2 x double> poison, double %16, i64 0
  %24 = shufflevector <2 x double> %23, <2 x double> poison, <2 x i32> zeroinitializer
  %25 = fmul <2 x double> %24, %21
  %26 = insertelement <2 x double> poison, double %13, i64 0
  %27 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> zeroinitializer
  %28 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %27, <2 x double> %20, <2 x double> %25)
  %29 = insertelement <2 x double> poison, double %19, i64 0
  %30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> zeroinitializer
  %31 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %30, <2 x double> %22, <2 x double> %28)
  store <2 x double> %31, ptr %10, align 16, !tbaa !5
  %32 = insertelement <2 x double> %14, double %16, i64 1
  %33 = fmul <2 x double> %32, %14
  %34 = insertelement <2 x double> %11, double %13, i64 1
  %35 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %34, <2 x double> %11, <2 x double> %33)
  %36 = insertelement <2 x double> %17, double %19, i64 1
  %37 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %36, <2 x double> %17, <2 x double> %35)
  store <2 x double> %37, ptr %3, align 16, !tbaa !5
  call void @g_ad_sqrt(ptr noundef nonnull %4, ptr noundef nonnull byval(%struct.DERIV_TYPE) align 8 %3) #5
  %38 = getelementptr inbounds i8, ptr %4, i64 8
  %39 = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %39, ptr noundef nonnull align 8 dereferenceable(24) %38, i64 24, i1 false), !tbaa !5
  %40 = load double, ptr %4, align 8, !tbaa !9
  store double %40, ptr %0, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #5
  ret i32 0
}

declare void @g_ad_sqrt(ptr noundef, ptr noundef byval(%struct.DERIV_TYPE) align 8) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #4

attributes #0 = { mustprogress 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 = { "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 nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"DERIV_TYPE", !6, i64 0, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass