; 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] }

@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [36 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

; Function Attrs: nounwind uwtable
declare hidden i32 @is_zero_vector(ptr noundef byval(%struct.DERIV_TYPE) align 8) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @g_ad_fmax(ptr noundef %0, ptr noundef byval(%struct.DERIV_TYPE) align 8 %1, ptr noundef byval(%struct.DERIV_TYPE) align 8 %2) #1 {
  %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) #4
  %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) #4
  %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) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %17 = load double, ptr %5, align 8, !tbaa !12
  %18 = load double, ptr %6, align 8, !tbaa !12
  %19 = fcmp ogt double %17, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %3
  store double 1.000000e+00, ptr %8, align 8, !tbaa !12
  store double 0.000000e+00, ptr %9, align 8, !tbaa !12
  %21 = load double, ptr %5, align 8, !tbaa !12
  store double %21, ptr %7, align 8, !tbaa !12
  br label %42

22:                                               ; preds = %3
  %23 = load double, ptr %5, align 8, !tbaa !12
  %24 = load double, ptr %6, align 8, !tbaa !12
  %25 = fcmp olt double %23, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %22
  store double 0.000000e+00, ptr %8, align 8, !tbaa !12
  store double 1.000000e+00, ptr %9, align 8, !tbaa !12
  %27 = load double, ptr %6, align 8, !tbaa !12
  store double %27, ptr %7, align 8, !tbaa !12
  br label %41

28:                                               ; preds = %22
  %29 = call i32 @is_zero_vector(ptr noundef byval(%struct.DERIV_TYPE) align 8 %1)
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %28
  %32 = call i32 @is_zero_vector(ptr noundef byval(%struct.DERIV_TYPE) align 8 %2)
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %39, label %34

34:                                               ; preds = %31, %28
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = load double, ptr %5, align 8, !tbaa !12
  %37 = load double, ptr %6, align 8, !tbaa !12
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str.3, double noundef %36, double noundef %37) #4
  br label %39

39:                                               ; preds = %34, %31
  store double 5.000000e-01, ptr %8, align 8, !tbaa !12
  store double 5.000000e-01, ptr %9, align 8, !tbaa !12
  %40 = load double, ptr %5, align 8, !tbaa !12
  store double %40, ptr %7, align 8, !tbaa !12
  br label %41

41:                                               ; preds = %39, %26
  br label %42

42:                                               ; preds = %41, %20
  %43 = load double, ptr %7, align 8, !tbaa !12
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.DERIV_TYPE, ptr %44, i32 0, i32 0
  store double %43, ptr %45, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %47 = load double, ptr %8, align 8, !tbaa !12
  store double %47, ptr %10, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %48 = load double, ptr %9, align 8, !tbaa !12
  store double %48, ptr %11, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !13
  br label %49

49:                                               ; preds = %72, %46
  %50 = load i32, ptr %12, align 4, !tbaa !13
  %51 = icmp slt i32 %50, 3
  br i1 %51, label %52, label %75

52:                                               ; preds = %49
  %53 = load double, ptr %10, align 8, !tbaa !12
  %54 = getelementptr inbounds %struct.DERIV_TYPE, ptr %1, i32 0, i32 1
  %55 = load i32, ptr %12, align 4, !tbaa !13
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [3 x double], ptr %54, i64 0, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !12
  %59 = load double, ptr %11, align 8, !tbaa !12
  %60 = getelementptr inbounds %struct.DERIV_TYPE, ptr %2, i32 0, i32 1
  %61 = load i32, ptr %12, align 4, !tbaa !13
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [3 x double], ptr %60, i64 0, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !12
  %65 = fmul double %59, %64
  %66 = call double @llvm.fmuladd.f64(double %53, double %58, double %65)
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.DERIV_TYPE, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %12, align 4, !tbaa !13
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [3 x double], ptr %68, i64 0, i64 %70
  store double %66, ptr %71, align 8, !tbaa !12
  br label %72

72:                                               ; preds = %52
  %73 = load i32, ptr %12, align 4, !tbaa !13
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %12, align 4, !tbaa !13
  br label %49, !llvm.loop !15

75:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %76

76:                                               ; preds = %75
  br label %77

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

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 "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 = { 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] }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden i32 @is_zero_vector(ptr noundef byval(%struct.DERIV_TYPE) align 8) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @g_ad_fmax(ptr nocapture noundef writeonly %0, ptr noundef byval(%struct.DERIV_TYPE) align 8 %1, ptr noundef byval(%struct.DERIV_TYPE) align 8 %2) local_unnamed_addr #0 {
  %4 = load double, ptr %1, align 8, !tbaa !5
  %5 = load double, ptr %2, align 8, !tbaa !5
  %6 = fcmp ogt double %4, %5
  br i1 %6, label %16, label %7

7:                                                ; preds = %3
  %8 = fcmp olt double %4, %5
  br i1 %8, label %16, label %9

9:                                                ; preds = %7
  %10 = tail call i32 @is_zero_vector(ptr noundef nonnull byval(%struct.DERIV_TYPE) align 8 %1)
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %13, label %11

11:                                               ; preds = %9
  %12 = tail call i32 @is_zero_vector(ptr noundef nonnull byval(%struct.DERIV_TYPE) align 8 %2)
  %.not25 = icmp eq i32 %12, 0
  br i1 %.not25, label %13, label %16

13:                                               ; preds = %11, %9
  %14 = load ptr, ptr @stderr, align 8, !tbaa !10
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str.3, double noundef %4, double noundef %5) #4
  br label %16

16:                                               ; preds = %11, %13, %7, %3
  %.022 = phi double [ 0.000000e+00, %3 ], [ 1.000000e+00, %7 ], [ 5.000000e-01, %13 ], [ 5.000000e-01, %11 ]
  %.021 = phi double [ 1.000000e+00, %3 ], [ 0.000000e+00, %7 ], [ 5.000000e-01, %13 ], [ 5.000000e-01, %11 ]
  %.020 = phi double [ %4, %3 ], [ %5, %7 ], [ %4, %13 ], [ %4, %11 ]
  store double %.020, ptr %0, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = getelementptr inbounds i8, ptr %2, i64 8
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load <2 x double>, ptr %17, align 8, !tbaa !12
  %21 = load <2 x double>, ptr %18, align 8, !tbaa !12
  %22 = insertelement <2 x double> poison, double %.022, i64 0
  %23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
  %24 = fmul <2 x double> %23, %21
  %25 = insertelement <2 x double> poison, double %.021, i64 0
  %26 = shufflevector <2 x double> %25, <2 x double> poison, <2 x i32> zeroinitializer
  %27 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %26, <2 x double> %20, <2 x double> %24)
  store <2 x double> %27, ptr %19, align 8, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %1, i64 24
  %29 = load double, ptr %28, align 8, !tbaa !12
  %30 = getelementptr inbounds i8, ptr %2, i64 24
  %31 = load double, ptr %30, align 8, !tbaa !12
  %32 = fmul double %.022, %31
  %33 = tail call double @llvm.fmuladd.f64(double %.021, double %29, double %32)
  %34 = getelementptr inbounds i8, ptr %0, i64 24
  store double %33, ptr %34, align 8, !tbaa !12
  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>) #3

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { cold 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, !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 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!7, !7, i64 0}


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