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

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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: nounwind uwtable
define dso_local void @g_ad_atan2(ptr noundef %0, ptr noundef byval(%struct.DERIV_TYPE) align 8 %1, ptr noundef byval(%struct.DERIV_TYPE) align 8 %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %13 = getelementptr inbounds %struct.DERIV_TYPE, ptr %1, i32 0, i32 0
  %14 = load double, ptr %13, align 8, !tbaa !9
  store double %14, ptr %5, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %15 = getelementptr inbounds %struct.DERIV_TYPE, ptr %2, i32 0, i32 0
  %16 = load double, ptr %15, align 8, !tbaa !9
  store double %16, ptr %6, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %17 = load double, ptr %5, align 8, !tbaa !12
  %18 = load double, ptr %5, align 8, !tbaa !12
  %19 = load double, ptr %6, align 8, !tbaa !12
  %20 = load double, ptr %6, align 8, !tbaa !12
  %21 = fmul double %19, %20
  %22 = call double @llvm.fmuladd.f64(double %17, double %18, double %21)
  %23 = fdiv double 1.000000e+00, %22
  store double %23, ptr %9, align 8, !tbaa !12
  %24 = load double, ptr %6, align 8, !tbaa !12
  %25 = load double, ptr %9, align 8, !tbaa !12
  %26 = fmul double %24, %25
  store double %26, ptr %7, align 8, !tbaa !12
  %27 = load double, ptr %5, align 8, !tbaa !12
  %28 = load double, ptr %9, align 8, !tbaa !12
  %29 = fmul double %27, %28
  %30 = fneg double %29
  store double %30, ptr %8, align 8, !tbaa !12
  br label %31

31:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %32 = load double, ptr %7, align 8, !tbaa !12
  store double %32, ptr %10, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %33 = load double, ptr %8, align 8, !tbaa !12
  store double %33, ptr %11, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !13
  br label %34

34:                                               ; preds = %57, %31
  %35 = load i32, ptr %12, align 4, !tbaa !13
  %36 = icmp slt i32 %35, 3
  br i1 %36, label %37, label %60

37:                                               ; preds = %34
  %38 = load double, ptr %10, align 8, !tbaa !12
  %39 = getelementptr inbounds %struct.DERIV_TYPE, ptr %1, i32 0, i32 1
  %40 = load i32, ptr %12, align 4, !tbaa !13
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [3 x double], ptr %39, i64 0, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !12
  %44 = load double, ptr %11, align 8, !tbaa !12
  %45 = getelementptr inbounds %struct.DERIV_TYPE, ptr %2, i32 0, i32 1
  %46 = load i32, ptr %12, align 4, !tbaa !13
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [3 x double], ptr %45, i64 0, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !12
  %50 = fmul double %44, %49
  %51 = call double @llvm.fmuladd.f64(double %38, double %43, double %50)
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.DERIV_TYPE, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %12, align 4, !tbaa !13
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [3 x double], ptr %53, i64 0, i64 %55
  store double %51, ptr %56, align 8, !tbaa !12
  br label %57

57:                                               ; preds = %37
  %58 = load i32, ptr %12, align 4, !tbaa !13
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %12, align 4, !tbaa !13
  br label %34, !llvm.loop !15

60:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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 = { 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, !11, i64 0}
!10 = !{!"DERIV_TYPE", !11, i64 0, !7, i64 8}
!11 = !{!"double", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!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"

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @g_ad_atan2(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly byval(%struct.DERIV_TYPE) align 8 %1, ptr nocapture noundef readonly byval(%struct.DERIV_TYPE) align 8 %2) local_unnamed_addr #1 {
  %4 = load double, ptr %1, align 8, !tbaa !5
  %5 = load double, ptr %2, align 8, !tbaa !5
  %6 = fmul double %5, %5
  %7 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %6)
  %8 = fdiv double 1.000000e+00, %7
  %9 = fmul double %5, %8
  %10 = fneg double %4
  %11 = fmul double %8, %10
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = getelementptr inbounds i8, ptr %2, i64 8
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load <2 x double>, ptr %12, align 8, !tbaa !10
  %16 = load <2 x double>, ptr %13, align 8, !tbaa !10
  %17 = insertelement <2 x double> poison, double %11, i64 0
  %18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
  %19 = fmul <2 x double> %18, %16
  %20 = insertelement <2 x double> poison, double %9, i64 0
  %21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
  %22 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> %15, <2 x double> %19)
  store <2 x double> %22, ptr %14, align 8, !tbaa !10
  %23 = getelementptr inbounds i8, ptr %1, i64 24
  %24 = load double, ptr %23, align 8, !tbaa !10
  %25 = getelementptr inbounds i8, ptr %2, i64 24
  %26 = load double, ptr %25, align 8, !tbaa !10
  %27 = fmul double %11, %26
  %28 = tail call double @llvm.fmuladd.f64(double %9, double %24, double %27)
  %29 = getelementptr inbounds i8, ptr %0, i64 24
  store double %28, ptr %29, align 8, !tbaa !10
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"DERIV_TYPE", !7, i64 0, !8, i64 8}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}


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