; 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.7 = external hidden unnamed_addr constant [37 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: 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_fmod(ptr noundef %0, ptr noundef byval(%struct.DERIV_TYPE) align 8 %1, ptr noundef byval(%struct.DERIV_TYPE) align 8 %2) #3 {
  %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
  %17 = load double, ptr %5, align 8, !tbaa !12
  %18 = load double, ptr %6, align 8, !tbaa !12
  %19 = call double @fmod(double noundef %17, double noundef %18) #4
  store double %19, ptr %7, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store double 1.000000e+00, ptr %8, align 8, !tbaa !12
  %20 = load double, ptr %7, align 8, !tbaa !12
  %21 = fcmp oeq double %20, 0.000000e+00
  br i1 %21, label %22, label %27

22:                                               ; preds = %3
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = load double, ptr %5, align 8, !tbaa !12
  %25 = load double, ptr %6, align 8, !tbaa !12
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.7, double noundef %24, double noundef %25) #4
  store double 0.000000e+00, ptr %9, align 8, !tbaa !12
  br label %34

27:                                               ; preds = %3
  %28 = load double, ptr %5, align 8, !tbaa !12
  %29 = load double, ptr %6, align 8, !tbaa !12
  %30 = fdiv double %28, %29
  %31 = fptosi double %30 to i32
  %32 = sub nsw i32 0, %31
  %33 = sitofp i32 %32 to double
  store double %33, ptr %9, align 8, !tbaa !12
  br label %34

34:                                               ; preds = %27, %22
  br label %35

35:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %36 = load double, ptr %8, align 8, !tbaa !12
  store double %36, ptr %10, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %37 = load double, ptr %9, align 8, !tbaa !12
  store double %37, 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 %38

38:                                               ; preds = %61, %35
  %39 = load i32, ptr %12, align 4, !tbaa !13
  %40 = icmp slt i32 %39, 3
  br i1 %40, label %41, label %64

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

61:                                               ; preds = %41
  %62 = load i32, ptr %12, align 4, !tbaa !13
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %12, align 4, !tbaa !13
  br label %38, !llvm.loop !15

64:                                               ; preds = %38
  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 %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  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
}

; Function Attrs: nounwind
declare double @fmod(double noundef, double noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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.7 = external hidden unnamed_addr constant [37 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @g_ad_fmod(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 = tail call double @fmod(double noundef %4, double noundef %5) #3
  %7 = fcmp oeq double %6, 0.000000e+00
  br i1 %7, label %8, label %11

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

11:                                               ; preds = %3
  %12 = fdiv double %4, %5
  %13 = fptosi double %12 to i32
  %14 = sub nsw i32 0, %13
  %15 = sitofp i32 %14 to double
  br label %16

16:                                               ; preds = %8, %11
  %.016 = phi double [ 0.000000e+00, %8 ], [ %15, %11 ]
  %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 %.016, i64 0
  %23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
  %24 = fmul <2 x double> %23, %21
  %25 = fadd <2 x double> %20, %24
  store <2 x double> %25, ptr %19, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %1, i64 24
  %27 = load double, ptr %26, align 8, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %2, i64 24
  %29 = load double, ptr %28, align 8, !tbaa !12
  %30 = fmul double %.016, %29
  %31 = fadd double %27, %30
  %32 = getelementptr inbounds i8, ptr %0, i64 24
  store double %31, ptr %32, align 8, !tbaa !12
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @fmod(double noundef, double noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { nofree 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 = { mustprogress nofree nounwind willreturn memory(write) "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 }
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