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

@atom = external global ptr, align 8
@.str.34 = external hidden unnamed_addr constant [58 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
declare double @sqrt(double noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @PrintBonds(i32 noundef %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %8 = load ptr, ptr @atom, align 8, !tbaa !9
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds %struct.AtomStr, ptr %8, i64 %10
  %12 = getelementptr inbounds %struct.AtomStr, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.PropertyStr, ptr %13, i32 0, i32 10
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  store ptr %15, ptr %7, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %19, %1
  %17 = load ptr, ptr %7, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %67

19:                                               ; preds = %16
  %20 = load ptr, ptr %7, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.ConstraintStr, ptr %20, i32 0, i32 1
  %22 = load double, ptr %21, align 8, !tbaa !17
  %23 = call double @sqrt(double noundef %22) #4
  store double %23, ptr %5, align 8, !tbaa !19
  %24 = load ptr, ptr %7, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.ConstraintStr, ptr %24, i32 0, i32 3
  %26 = load double, ptr %25, align 8, !tbaa !20
  %27 = call double @sqrt(double noundef %26) #4
  store double %27, ptr %6, align 8, !tbaa !19
  %28 = load double, ptr %6, align 8, !tbaa !19
  %29 = load double, ptr %5, align 8, !tbaa !19
  %30 = fsub double %28, %29
  %31 = load double, ptr %6, align 8, !tbaa !19
  %32 = load double, ptr %5, align 8, !tbaa !19
  %33 = fadd double %31, %32
  %34 = fdiv double %30, %33
  store double %34, ptr %3, align 8, !tbaa !19
  %35 = load double, ptr %6, align 8, !tbaa !19
  %36 = load double, ptr %5, align 8, !tbaa !19
  %37 = fadd double %35, %36
  %38 = fmul double %37, 5.000000e-01
  store double %38, ptr %4, align 8, !tbaa !19
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = load ptr, ptr @atom, align 8, !tbaa !9
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.AtomStr, ptr %40, i64 %42
  %44 = getelementptr inbounds %struct.AtomStr, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.PropertyStr, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds [8 x i8], ptr %46, i64 0, i64 0
  %48 = load ptr, ptr %7, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.ConstraintStr, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !21
  %51 = load ptr, ptr @atom, align 8, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.ConstraintStr, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 8, !tbaa !21
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds %struct.AtomStr, ptr %51, i64 %55
  %57 = getelementptr inbounds %struct.AtomStr, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  %59 = getelementptr inbounds %struct.PropertyStr, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds [8 x i8], ptr %59, i64 0, i64 0
  %61 = load double, ptr %4, align 8, !tbaa !19
  %62 = load double, ptr %3, align 8, !tbaa !19
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.34, i32 noundef %39, ptr noundef %47, i32 noundef %50, ptr noundef %60, double noundef %61, double noundef %62)
  %64 = load ptr, ptr %7, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.ConstraintStr, ptr %64, i32 0, i32 4
  %66 = load ptr, ptr %65, align 8, !tbaa !22
  store ptr %66, ptr %7, align 8, !tbaa !9
  br label %16, !llvm.loop !23

67:                                               ; preds = %16
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

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 "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 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 = !{!"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 0}
!12 = !{!"AtomStr", !10, i64 0, !10, i64 8}
!13 = !{!14, !10, i64 120}
!14 = !{!"PropertyStr", !7, i64 0, !7, i64 8, !7, i64 40, !6, i64 48, !6, i64 52, !6, i64 56, !15, i64 64, !15, i64 72, !7, i64 80, !16, i64 104, !10, i64 120, !10, i64 128}
!15 = !{!"double", !7, i64 0}
!16 = !{!"AtomSeqStr", !6, i64 0, !6, i64 4, !6, i64 8}
!17 = !{!18, !15, i64 8}
!18 = !{!"ConstraintStr", !6, i64 0, !15, i64 8, !10, i64 16, !15, i64 24, !10, i64 32}
!19 = !{!15, !15, i64 0}
!20 = !{!18, !15, i64 24}
!21 = !{!18, !6, i64 0}
!22 = !{!18, !10, i64 32}
!23 = distinct !{!23, !24}
!24 = !{!"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 }

@atom = external local_unnamed_addr global ptr, align 8
@.str.34 = external hidden unnamed_addr constant [58 x i8], align 1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind uwtable
define dso_local void @PrintBonds(i32 noundef %0) local_unnamed_addr #2 {
  %2 = load ptr, ptr @atom, align 8, !tbaa !5
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds %struct.AtomStr, ptr %2, i64 %3
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %5, i64 120
  %.016 = load ptr, ptr %6, align 8, !tbaa !5
  %.not17 = icmp eq ptr %.016, null
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.018 = phi ptr [ %.0, %.lr.ph ], [ %.016, %1 ]
  %7 = getelementptr inbounds i8, ptr %.018, i64 8
  %8 = load double, ptr %7, align 8, !tbaa !11
  %9 = tail call double @sqrt(double noundef %8) #3
  %10 = getelementptr inbounds i8, ptr %.018, i64 24
  %11 = load double, ptr %10, align 8, !tbaa !15
  %12 = tail call double @sqrt(double noundef %11) #3
  %13 = fsub double %12, %9
  %14 = fadd double %9, %12
  %15 = fdiv double %13, %14
  %16 = fmul double %14, 5.000000e-01
  %17 = load ptr, ptr @atom, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.AtomStr, ptr %17, i64 %3
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = load i32, ptr %.018, align 8, !tbaa !16
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %struct.AtomStr, ptr %17, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.34, i32 noundef %0, ptr noundef %19, i32 noundef %20, ptr noundef %23, double noundef %16, double noundef %15)
  %25 = getelementptr inbounds i8, ptr %.018, i64 32
  %.0 = load ptr, ptr %25, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %1
  ret void
}

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 = { 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 #2 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"AtomStr", !6, i64 0, !6, i64 8}
!11 = !{!12, !14, i64 8}
!12 = !{!"ConstraintStr", !13, i64 0, !14, i64 8, !6, i64 16, !14, i64 24, !6, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !14, i64 24}
!16 = !{!12, !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass