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

; 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.CGBeadStr = type { double, double, double, double }

@.str.34 = external hidden unnamed_addr constant [16 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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local double @FindMinPotDis(ptr noundef byval(%struct.CGBeadStr) align 8 %0, ptr noundef byval(%struct.CGBeadStr) align 8 %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store i32 %2, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 1.000000e+08, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store double 1.000000e+00, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  br label %9

9:                                                ; preds = %28, %3
  %10 = load double, ptr %7, align 8, !tbaa !9
  %11 = fcmp olt double %10, 1.000000e+01
  br i1 %11, label %12, label %31

12:                                               ; preds = %9
  %13 = load double, ptr %7, align 8, !tbaa !9
  %14 = call double @CalculateSurPoten(ptr noundef byval(%struct.CGBeadStr) align 8 %0, ptr noundef byval(%struct.CGBeadStr) align 8 %1, double noundef %13)
  store double %14, ptr %8, align 8, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %21

17:                                               ; preds = %12
  %18 = load double, ptr %7, align 8, !tbaa !9
  %19 = load double, ptr %8, align 8, !tbaa !9
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.34, double noundef %18, double noundef %19)
  br label %21

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

25:                                               ; preds = %21
  %26 = load double, ptr %8, align 8, !tbaa !9
  store double %26, ptr %5, align 8, !tbaa !9
  %27 = load double, ptr %7, align 8, !tbaa !9
  store double %27, ptr %6, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %25, %21
  %29 = load double, ptr %7, align 8, !tbaa !9
  %30 = fadd double %29, 1.000000e-03
  store double %30, ptr %7, align 8, !tbaa !9
  br label %9, !llvm.loop !11

31:                                               ; preds = %9
  %32 = load double, ptr %6, align 8, !tbaa !9
  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 double %32
}

; Function Attrs: nounwind uwtable
declare dso_local double @CalculateSurPoten(ptr noundef byval(%struct.CGBeadStr) align 8, ptr noundef byval(%struct.CGBeadStr) align 8, double noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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.CGBeadStr = type { double, double, double, double }

@.str.34 = external hidden unnamed_addr constant [16 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local double @FindMinPotDis(ptr noundef byval(%struct.CGBeadStr) align 8 %0, ptr noundef byval(%struct.CGBeadStr) align 8 %1, i32 noundef %2) local_unnamed_addr #1 {
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %.split.us, label %.split

.split.us:                                        ; preds = %3, %.split.us
  %.016.us = phi double [ %.1.us, %.split.us ], [ 1.000000e+08, %3 ]
  %.01015.us = phi double [ %6, %.split.us ], [ 1.000000e+00, %3 ]
  %.01114.us = phi double [ %.112.us, %.split.us ], [ 0.000000e+00, %3 ]
  %4 = tail call double @CalculateSurPoten(ptr noundef nonnull byval(%struct.CGBeadStr) align 8 %0, ptr noundef nonnull byval(%struct.CGBeadStr) align 8 %1, double noundef %.01015.us)
  %5 = fcmp olt double %4, %.016.us
  %.112.us = select i1 %5, double %.01015.us, double %.01114.us
  %.1.us = select i1 %5, double %4, double %.016.us
  %6 = fadd double %.01015.us, 1.000000e-03
  %7 = fcmp olt double %6, 1.000000e+01
  br i1 %7, label %.split.us, label %.split18.us, !llvm.loop !5

.split:                                           ; preds = %3, %.split
  %.016 = phi double [ %.1, %.split ], [ 1.000000e+08, %3 ]
  %.01015 = phi double [ %11, %.split ], [ 1.000000e+00, %3 ]
  %.01114 = phi double [ %.112, %.split ], [ 0.000000e+00, %3 ]
  %8 = tail call double @CalculateSurPoten(ptr noundef nonnull byval(%struct.CGBeadStr) align 8 %0, ptr noundef nonnull byval(%struct.CGBeadStr) align 8 %1, double noundef %.01015)
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.34, double noundef %.01015, double noundef %8)
  %10 = fcmp olt double %8, %.016
  %.112 = select i1 %10, double %.01015, double %.01114
  %.1 = select i1 %10, double %8, double %.016
  %11 = fadd double %.01015, 1.000000e-03
  %12 = fcmp olt double %11, 1.000000e+01
  br i1 %12, label %.split, label %.split18.us, !llvm.loop !5

.split18.us:                                      ; preds = %.split, %.split.us
  %.us-phi = phi double [ %.112.us, %.split.us ], [ %.112, %.split ]
  ret double %.us-phi
}

; Function Attrs: nounwind uwtable
declare dso_local double @CalculateSurPoten(ptr noundef byval(%struct.CGBeadStr) align 8, ptr noundef byval(%struct.CGBeadStr) align 8, double noundef) local_unnamed_addr #1

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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