; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (r8lib)

; 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"

; 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.fabs.f64(double) #1

; Function Attrs: nounwind uwtable
define dso_local void @r8vec_sorted_unique_hist(i32 noundef %0, ptr noundef %1, double noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #2 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !9
  store double %2, ptr %10, align 8, !tbaa !11
  store i32 %3, ptr %11, align 4, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !9
  store ptr %6, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 -1, ptr %16, align 4, !tbaa !5
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %86, %7
  %18 = load i32, ptr %15, align 4, !tbaa !5
  %19 = load i32, ptr %8, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %89

21:                                               ; preds = %17
  %22 = load i32, ptr %15, align 4, !tbaa !5
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %36

24:                                               ; preds = %21
  store i32 0, ptr %16, align 4, !tbaa !5
  %25 = load ptr, ptr %9, align 8, !tbaa !9
  %26 = getelementptr inbounds double, ptr %25, i64 0
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = load ptr, ptr %13, align 8, !tbaa !9
  %29 = load i32, ptr %16, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %28, i64 %30
  store double %27, ptr %31, align 8, !tbaa !11
  %32 = load ptr, ptr %14, align 8, !tbaa !9
  %33 = load i32, ptr %16, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i32, ptr %32, i64 %34
  store i32 1, ptr %35, align 4, !tbaa !5
  br label %85

36:                                               ; preds = %21
  %37 = load ptr, ptr %9, align 8, !tbaa !9
  %38 = load i32, ptr %15, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds double, ptr %37, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !11
  %42 = load ptr, ptr %13, align 8, !tbaa !9
  %43 = load i32, ptr %16, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %42, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !11
  %47 = fsub double %41, %46
  %48 = call double @llvm.fabs.f64(double %47)
  %49 = load double, ptr %10, align 8, !tbaa !11
  %50 = fcmp ole double %48, %49
  br i1 %50, label %51, label %62

51:                                               ; preds = %36
  %52 = load ptr, ptr %14, align 8, !tbaa !9
  %53 = load i32, ptr %16, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  %58 = load ptr, ptr %14, align 8, !tbaa !9
  %59 = load i32, ptr %16, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  store i32 %57, ptr %61, align 4, !tbaa !5
  br label %84

62:                                               ; preds = %36
  %63 = load i32, ptr %16, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  %65 = load i32, ptr %11, align 4, !tbaa !5
  %66 = icmp slt i32 %64, %65
  br i1 %66, label %67, label %83

67:                                               ; preds = %62
  %68 = load i32, ptr %16, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %16, align 4, !tbaa !5
  %70 = load ptr, ptr %9, align 8, !tbaa !9
  %71 = load i32, ptr %15, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds double, ptr %70, i64 %72
  %74 = load double, ptr %73, align 8, !tbaa !11
  %75 = load ptr, ptr %13, align 8, !tbaa !9
  %76 = load i32, ptr %16, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds double, ptr %75, i64 %77
  store double %74, ptr %78, align 8, !tbaa !11
  %79 = load ptr, ptr %14, align 8, !tbaa !9
  %80 = load i32, ptr %16, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i32, ptr %79, i64 %81
  store i32 1, ptr %82, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %67, %62
  br label %84

84:                                               ; preds = %83, %51
  br label %85

85:                                               ; preds = %84, %24
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %15, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %15, align 4, !tbaa !5
  br label %17, !llvm.loop !13

89:                                               ; preds = %17
  %90 = load i32, ptr %16, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  %92 = load ptr, ptr %12, align 8, !tbaa !9
  store i32 %91, ptr %92, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @r8vec_sorted_unique_hist(i32 noundef %0, ptr nocapture noundef readonly %1, double noundef %2, i32 noundef %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef %5, ptr nocapture noundef %6) local_unnamed_addr #1 {
  %8 = icmp sgt i32 %0, 0
  br i1 %8, label %9, label %._crit_edge

9:                                                ; preds = %7
  %wide.trip.count = zext nneg i32 %0 to i64
  %10 = load double, ptr %1, align 8, !tbaa !5
  store double %10, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %6, align 4, !tbaa !9
  %exitcond.peel.not = icmp eq i32 %0, 1
  br i1 %exitcond.peel.not, label %._crit_edge, label %.lr.ph.peel.next

.lr.ph.peel.next:                                 ; preds = %9, %30
  %indvars.iv = phi i64 [ %indvars.iv.next, %30 ], [ 1, %9 ]
  %.031 = phi i32 [ %.1, %30 ], [ 0, %9 ]
  %11 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = sext i32 %.031 to i64
  %14 = getelementptr inbounds double, ptr %5, i64 %13
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fsub double %12, %15
  %17 = tail call double @llvm.fabs.f64(double %16)
  %18 = fcmp ugt double %17, %2
  br i1 %18, label %23, label %19

19:                                               ; preds = %.lr.ph.peel.next
  %20 = getelementptr inbounds i32, ptr %6, i64 %13
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %20, align 4, !tbaa !9
  br label %30

23:                                               ; preds = %.lr.ph.peel.next
  %24 = add nsw i32 %.031, 1
  %25 = icmp slt i32 %24, %3
  br i1 %25, label %26, label %30

26:                                               ; preds = %23
  %27 = sext i32 %24 to i64
  %28 = getelementptr inbounds double, ptr %5, i64 %27
  store double %12, ptr %28, align 8, !tbaa !5
  %29 = getelementptr inbounds i32, ptr %6, i64 %27
  store i32 1, ptr %29, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %23, %26, %19
  %.1 = phi i32 [ %.031, %19 ], [ %24, %26 ], [ %.031, %23 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit.loopexit, label %.lr.ph.peel.next, !llvm.loop !11

._crit_edge.loopexit.loopexit:                    ; preds = %30
  %31 = add nsw i32 %.1, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %9, %._crit_edge.loopexit.loopexit, %7
  %.0.lcssa = phi i32 [ 0, %7 ], [ 1, %9 ], [ %31, %._crit_edge.loopexit.loopexit ]
  store i32 %.0.lcssa, ptr %4, align 4, !tbaa !9
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = !{!"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 = distinct !{!11, !12, !13}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.peeled.count", i32 1}


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