; LLVM IR from alexzheng42/sDMD :: src (ToolFunctions)

; 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.PepStr = type { i32, i32, i32, i32, double }
%struct.AtomStr = type { ptr, ptr }
%struct.DynamicStr = type { [4 x i32], [4 x double], [4 x double], %struct.HBStr, %struct.HBNeighborStr, %struct.InteractionEventStr }
%struct.HBStr = type { i32, i32, i8, i32 }
%struct.HBNeighborStr = type { [5 x i32], i32, i32 }
%struct.InteractionEventStr = type { i32, i64, i64, double, double, i32, i32 }
%struct.PropertyStr = type { [8 x i8], [2 x [16 x i8]], [8 x i8], i32, i32, i32, double, double, [3 x double], %struct.AtomSeqStr, ptr, ptr }
%struct.AtomSeqStr = type { i32, i32, i32 }

@atom = external global ptr, align 8
@protein = external global ptr, align 8

; 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 @CalCOMV(i32 noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %9 = load ptr, ptr @protein, align 8, !tbaa !9
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds %struct.PepStr, ptr %9, i64 %11
  %13 = getelementptr inbounds %struct.PepStr, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !11
  store i32 %14, ptr %5, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %60, %2
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load ptr, ptr @protein, align 8, !tbaa !9
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds %struct.PepStr, ptr %17, i64 %19
  %21 = getelementptr inbounds %struct.PepStr, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %23 = icmp sle i32 %16, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %15
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %63

25:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %56, %25
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = icmp sle i32 %27, 3
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %59

30:                                               ; preds = %26
  %31 = load ptr, ptr @atom, align 8, !tbaa !9
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.AtomStr, ptr %31, i64 %33
  %35 = getelementptr inbounds %struct.AtomStr, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = getelementptr inbounds %struct.DynamicStr, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [4 x double], ptr %37, i64 0, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !17
  %42 = load ptr, ptr @atom, align 8, !tbaa !9
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.AtomStr, ptr %42, i64 %44
  %46 = getelementptr inbounds %struct.AtomStr, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = getelementptr inbounds %struct.PropertyStr, ptr %47, i32 0, i32 7
  %49 = load double, ptr %48, align 8, !tbaa !19
  %50 = load ptr, ptr %4, align 8, !tbaa !9
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %50, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !17
  %55 = call double @llvm.fmuladd.f64(double %41, double %49, double %54)
  store double %55, ptr %53, align 8, !tbaa !17
  br label %56

56:                                               ; preds = %30
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %7, align 4, !tbaa !5
  br label %26, !llvm.loop !22

59:                                               ; preds = %29
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %5, align 4, !tbaa !5
  br label %15, !llvm.loop !24

63:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %81, %63
  %65 = load i32, ptr %8, align 4, !tbaa !5
  %66 = icmp sle i32 %65, 3
  br i1 %66, label %68, label %67

67:                                               ; preds = %64
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %84

68:                                               ; preds = %64
  %69 = load ptr, ptr @protein, align 8, !tbaa !9
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds %struct.PepStr, ptr %69, i64 %71
  %73 = getelementptr inbounds %struct.PepStr, ptr %72, i32 0, i32 4
  %74 = load double, ptr %73, align 8, !tbaa !25
  %75 = load ptr, ptr %4, align 8, !tbaa !9
  %76 = load i32, ptr %8, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds double, ptr %75, i64 %77
  %79 = load double, ptr %78, align 8, !tbaa !17
  %80 = fdiv double %79, %74
  store double %80, ptr %78, align 8, !tbaa !17
  br label %81

81:                                               ; preds = %68
  %82 = load i32, ptr %8, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %8, align 4, !tbaa !5
  br label %64, !llvm.loop !26

84:                                               ; preds = %67
  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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"PepStr", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !13, i64 16}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !6, i64 4}
!15 = !{!16, !10, i64 8}
!16 = !{!"AtomStr", !10, i64 0, !10, i64 8}
!17 = !{!13, !13, i64 0}
!18 = !{!16, !10, i64 0}
!19 = !{!20, !13, i64 72}
!20 = !{!"PropertyStr", !7, i64 0, !7, i64 8, !7, i64 40, !6, i64 48, !6, i64 52, !6, i64 56, !13, i64 64, !13, i64 72, !7, i64 80, !21, i64 104, !10, i64 120, !10, i64 128}
!21 = !{!"AtomSeqStr", !6, i64 0, !6, i64 4, !6, i64 8}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}
!25 = !{!12, !13, i64 16}
!26 = distinct !{!26, !23}


; 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.PepStr = type { i32, i32, i32, i32, double }
%struct.AtomStr = type { ptr, ptr }

@atom = external local_unnamed_addr global ptr, align 8
@protein = external local_unnamed_addr global ptr, align 8

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

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @CalCOMV(i32 noundef %0, ptr nocapture noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr @protein, align 8, !tbaa !5
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds %struct.PepStr, ptr %3, i64 %4
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds %struct.PepStr, ptr %3, i64 %4, i32 1
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %.not19 = icmp sgt i32 %6, %8
  %.pre33 = load double, ptr %1, align 8, !tbaa !14
  br i1 %.not19, label %..preheader_crit_edge, label %.preheader17.lr.ph

..preheader_crit_edge:                            ; preds = %2
  %.phi.trans.insert34 = getelementptr inbounds i8, ptr %1, i64 8
  %.pre = load double, ptr %.phi.trans.insert34, align 8, !tbaa !14
  %.phi.trans.insert35 = getelementptr inbounds i8, ptr %1, i64 16
  %.pre36 = load double, ptr %.phi.trans.insert35, align 8, !tbaa !14
  %.phi.trans.insert37 = getelementptr inbounds i8, ptr %1, i64 24
  %.pre38 = load double, ptr %.phi.trans.insert37, align 8, !tbaa !14
  br label %.preheader

.preheader17.lr.ph:                               ; preds = %2
  %9 = load ptr, ptr @atom, align 8, !tbaa !5
  %10 = sext i32 %6 to i64
  %11 = add i32 %8, 1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %1, i64 8
  %.pre28 = load double, ptr %.phi.trans.insert, align 8, !tbaa !14
  %.phi.trans.insert29 = getelementptr inbounds i8, ptr %1, i64 16
  %.pre30 = load double, ptr %.phi.trans.insert29, align 8, !tbaa !14
  %.phi.trans.insert31 = getelementptr inbounds i8, ptr %1, i64 24
  %.pre32 = load double, ptr %.phi.trans.insert31, align 8, !tbaa !14
  br label %.preheader17

.preheader17:                                     ; preds = %.preheader17.lr.ph, %.preheader17
  %12 = phi double [ %.pre32, %.preheader17.lr.ph ], [ %36, %.preheader17 ]
  %13 = phi double [ %.pre30, %.preheader17.lr.ph ], [ %32, %.preheader17 ]
  %14 = phi double [ %.pre28, %.preheader17.lr.ph ], [ %28, %.preheader17 ]
  %15 = phi double [ %.pre33, %.preheader17.lr.ph ], [ %24, %.preheader17 ]
  %indvars.iv = phi i64 [ %10, %.preheader17.lr.ph ], [ %indvars.iv.next, %.preheader17 ]
  %16 = getelementptr inbounds %struct.AtomStr, ptr %9, i64 %indvars.iv
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %18, i64 48
  %20 = load ptr, ptr %16, align 8, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %20, i64 72
  %22 = load double, ptr %19, align 8, !tbaa !14
  %23 = load double, ptr %21, align 8, !tbaa !18
  %24 = tail call double @llvm.fmuladd.f64(double %22, double %23, double %15)
  store double %24, ptr %1, align 8, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %18, i64 56
  %26 = load double, ptr %25, align 8, !tbaa !14
  %27 = load double, ptr %21, align 8, !tbaa !18
  %28 = tail call double @llvm.fmuladd.f64(double %26, double %27, double %14)
  store double %28, ptr %.phi.trans.insert, align 8, !tbaa !14
  %29 = getelementptr inbounds i8, ptr %18, i64 64
  %30 = load double, ptr %29, align 8, !tbaa !14
  %31 = load double, ptr %21, align 8, !tbaa !18
  %32 = tail call double @llvm.fmuladd.f64(double %30, double %31, double %13)
  store double %32, ptr %.phi.trans.insert29, align 8, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %18, i64 72
  %34 = load double, ptr %33, align 8, !tbaa !14
  %35 = load double, ptr %21, align 8, !tbaa !18
  %36 = tail call double @llvm.fmuladd.f64(double %34, double %35, double %12)
  store double %36, ptr %.phi.trans.insert31, align 8, !tbaa !14
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond.not = icmp eq i32 %11, %lftr.wideiv
  br i1 %exitcond.not, label %.preheader, label %.preheader17, !llvm.loop !21

.preheader:                                       ; preds = %.preheader17, %..preheader_crit_edge
  %37 = phi double [ %.pre38, %..preheader_crit_edge ], [ %36, %.preheader17 ]
  %38 = phi double [ %.pre36, %..preheader_crit_edge ], [ %32, %.preheader17 ]
  %39 = phi double [ %.pre, %..preheader_crit_edge ], [ %28, %.preheader17 ]
  %40 = phi double [ %.pre33, %..preheader_crit_edge ], [ %24, %.preheader17 ]
  %41 = getelementptr inbounds %struct.PepStr, ptr %3, i64 %4, i32 4
  %42 = load double, ptr %41, align 8, !tbaa !23
  %43 = fdiv double %40, %42
  store double %43, ptr %1, align 8, !tbaa !14
  %44 = load double, ptr %41, align 8, !tbaa !23
  %45 = getelementptr inbounds i8, ptr %1, i64 8
  %46 = fdiv double %39, %44
  store double %46, ptr %45, align 8, !tbaa !14
  %47 = load double, ptr %41, align 8, !tbaa !23
  %48 = getelementptr inbounds i8, ptr %1, i64 16
  %49 = fdiv double %38, %47
  store double %49, ptr %48, align 8, !tbaa !14
  %50 = load double, ptr %41, align 8, !tbaa !23
  %51 = getelementptr inbounds i8, ptr %1, i64 24
  %52 = fdiv double %37, %50
  store double %52, ptr %51, align 8, !tbaa !14
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nofree norecurse nosync nounwind memory(read, argmem: 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, !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 = !{!"PepStr", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !6, i64 8}
!16 = !{!"AtomStr", !6, i64 0, !6, i64 8}
!17 = !{!16, !6, i64 0}
!18 = !{!19, !12, i64 72}
!19 = !{!"PropertyStr", !7, i64 0, !7, i64 8, !7, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !12, i64 64, !12, i64 72, !7, i64 80, !20, i64 104, !6, i64 120, !6, i64 128}
!20 = !{!"AtomSeqStr", !11, i64 0, !11, i64 4, !11, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!10, !12, i64 16}


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