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

@atomnum = external global i32, align 4
@atom = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @TimeForward(double noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca i32, align 4
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %21, %1
  %5 = load i32, ptr %3, align 4, !tbaa !9
  %6 = load i32, ptr @atomnum, align 4, !tbaa !9
  %7 = icmp sle i32 %5, %6
  br i1 %7, label %9, label %8

8:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %24

9:                                                ; preds = %4
  %10 = load double, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr @atom, align 8, !tbaa !11
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds %struct.AtomStr, ptr %11, i64 %13
  %15 = getelementptr inbounds %struct.AtomStr, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds %struct.DynamicStr, ptr %16, i32 0, i32 5
  %18 = getelementptr inbounds %struct.InteractionEventStr, ptr %17, i32 0, i32 3
  %19 = load double, ptr %18, align 8, !tbaa !15
  %20 = fsub double %19, %10
  store double %20, ptr %18, align 8, !tbaa !15
  br label %21

21:                                               ; preds = %9
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %3, align 4, !tbaa !9
  br label %4, !llvm.loop !21

24:                                               ; preds = %8
  ret void
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"AtomStr", !12, i64 0, !12, i64 8}
!15 = !{!16, !6, i64 152}
!16 = !{!"DynamicStr", !7, i64 0, !7, i64 16, !7, i64 48, !17, i64 80, !18, i64 96, !19, i64 128}
!17 = !{!"HBStr", !10, i64 0, !10, i64 4, !7, i64 8, !10, i64 12}
!18 = !{!"HBNeighborStr", !7, i64 0, !10, i64 20, !10, i64 24}
!19 = !{!"InteractionEventStr", !10, i64 0, !20, i64 8, !20, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44}
!20 = !{!"long", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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.AtomStr = type { ptr, ptr }

@atomnum = external local_unnamed_addr global i32, align 4
@atom = external local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @TimeForward(double noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @atomnum, align 4, !tbaa !5
  %.not3 = icmp slt i32 %2, 1
  br i1 %.not3, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %3 = load ptr, ptr @atom, align 8, !tbaa !9
  %4 = zext nneg i32 %2 to i64
  %xtraiter = and i64 %4, 3
  %5 = icmp ult i32 %2, 4
  br i1 %5, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %4, 2147483644
  br label %11

._crit_edge.loopexit.unr-lcssa:                   ; preds = %11, %.lr.ph
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next.3, %11 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %6 = getelementptr inbounds %struct.AtomStr, ptr %3, i64 %indvars.iv.epil, i32 1
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %7, i64 152
  %9 = load double, ptr %8, align 8, !tbaa !13
  %10 = fsub double %9, %0
  store double %10, ptr %8, align 8, !tbaa !13
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !20

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %1
  ret void

11:                                               ; preds = %11, %.lr.ph.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.new ], [ %indvars.iv.next.3, %11 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %11 ]
  %12 = getelementptr inbounds %struct.AtomStr, ptr %3, i64 %indvars.iv, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %13, i64 152
  %15 = load double, ptr %14, align 8, !tbaa !13
  %16 = fsub double %15, %0
  store double %16, ptr %14, align 8, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = getelementptr inbounds %struct.AtomStr, ptr %3, i64 %indvars.iv.next, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %18, i64 152
  %20 = load double, ptr %19, align 8, !tbaa !13
  %21 = fsub double %20, %0
  store double %21, ptr %19, align 8, !tbaa !13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %22 = getelementptr inbounds %struct.AtomStr, ptr %3, i64 %indvars.iv.next.1, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %23, i64 152
  %25 = load double, ptr %24, align 8, !tbaa !13
  %26 = fsub double %25, %0
  store double %26, ptr %24, align 8, !tbaa !13
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %27 = getelementptr inbounds %struct.AtomStr, ptr %3, i64 %indvars.iv.next.2, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %28, i64 152
  %30 = load double, ptr %29, align 8, !tbaa !13
  %31 = fsub double %30, %0
  store double %31, ptr %29, align 8, !tbaa !13
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %11, !llvm.loop !22
}

attributes #0 = { nofree norecurse nosync nounwind memory(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 = !{!"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, !10, i64 8}
!12 = !{!"AtomStr", !10, i64 0, !10, i64 8}
!13 = !{!14, !19, i64 152}
!14 = !{!"DynamicStr", !7, i64 0, !7, i64 16, !7, i64 48, !15, i64 80, !16, i64 96, !17, i64 128}
!15 = !{!"HBStr", !6, i64 0, !6, i64 4, !7, i64 8, !6, i64 12}
!16 = !{!"HBNeighborStr", !7, i64 0, !6, i64 20, !6, i64 24}
!17 = !{!"InteractionEventStr", !6, i64 0, !18, i64 8, !18, i64 16, !19, i64 24, !19, i64 32, !6, i64 40, !6, i64 44}
!18 = !{!"long", !7, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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