; 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: nounwind uwtable
declare dso_local void @r8vec_index_insert_unique(ptr noundef, ptr noundef, ptr noundef, double noundef) #1

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

13:                                               ; preds = %26, %5
  %14 = load i32, ptr %11, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %29

17:                                               ; preds = %13
  %18 = load ptr, ptr %8, align 8, !tbaa !9
  %19 = load ptr, ptr %9, align 8, !tbaa !9
  %20 = load ptr, ptr %10, align 8, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !9
  %22 = load i32, ptr %11, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %21, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !11
  call void @r8vec_index_insert_unique(ptr noundef %18, ptr noundef %19, ptr noundef %20, double noundef %25)
  br label %26

26:                                               ; preds = %17
  %27 = load i32, ptr %11, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %11, align 4, !tbaa !5
  br label %13, !llvm.loop !13

29:                                               ; preds = %13
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %11, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %41, %29
  %33 = load i32, ptr %11, align 4, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %44

36:                                               ; preds = %32
  %37 = load ptr, ptr %9, align 8, !tbaa !9
  %38 = load i32, ptr %11, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds double, ptr %37, i64 %39
  store double -1.000000e+00, ptr %40, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %36
  %42 = load i32, ptr %11, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %11, align 4, !tbaa !5
  br label %32, !llvm.loop !15

44:                                               ; preds = %32
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr %11, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %56, %44
  %48 = load i32, ptr %11, align 4, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %59

51:                                               ; preds = %47
  %52 = load ptr, ptr %10, align 8, !tbaa !9
  %53 = load i32, ptr %11, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  store i32 -1, ptr %55, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %51
  %57 = load i32, ptr %11, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %11, align 4, !tbaa !5
  br label %47, !llvm.loop !16

59:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"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"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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: nounwind uwtable
declare dso_local void @r8vec_index_insert_unique(ptr noundef, ptr noundef, ptr noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @r8vec_index_sort_unique(i32 noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  store i32 0, ptr %2, align 4, !tbaa !5
  %6 = icmp sgt i32 %0, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %7 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %8 = load double, ptr %7, align 8, !tbaa !9
  tail call void @r8vec_index_insert_unique(ptr noundef nonnull %2, ptr noundef %3, ptr noundef %4, double noundef %8)
  %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, label %.lr.ph, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %2, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %5
  %9 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ 0, %5 ]
  %10 = icmp slt i32 %9, %0
  br i1 %10, label %.lr.ph24.preheader, label %._crit_edge27

.lr.ph24.preheader:                               ; preds = %._crit_edge
  %11 = sext i32 %9 to i64
  %wide.trip.count32 = sext i32 %0 to i64
  %12 = sub nsw i64 %wide.trip.count32, %11
  %min.iters.check = icmp ult i64 %12, 4
  br i1 %min.iters.check, label %.lr.ph24.preheader37, label %vector.ph

.lr.ph24.preheader37:                             ; preds = %middle.block, %.lr.ph24.preheader
  %indvars.iv29.ph = phi i64 [ %11, %.lr.ph24.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph24

vector.ph:                                        ; preds = %.lr.ph24.preheader
  %n.vec = and i64 %12, -4
  %ind.end = add nsw i64 %n.vec, %11
  %invariant.gep = getelementptr double, ptr %3, i64 %11
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %gep = getelementptr double, ptr %invariant.gep, i64 %index
  %13 = getelementptr inbounds i8, ptr %gep, i64 16
  store <2 x double> <double -1.000000e+00, double -1.000000e+00>, ptr %gep, align 8, !tbaa !9
  store <2 x double> <double -1.000000e+00, double -1.000000e+00>, ptr %13, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %14 = icmp eq i64 %index.next, %n.vec
  br i1 %14, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %12, %n.vec
  br i1 %cmp.n, label %.preheader, label %.lr.ph24.preheader37

.preheader:                                       ; preds = %.lr.ph24, %middle.block
  br i1 %10, label %.lr.ph26.preheader, label %._crit_edge27

.lr.ph26.preheader:                               ; preds = %.preheader
  %15 = sext i32 %9 to i64
  %16 = shl nsw i64 %15, 2
  %scevgep = getelementptr i8, ptr %4, i64 %16
  %17 = xor i32 %9, -1
  %18 = add i32 %17, %0
  %19 = zext i32 %18 to i64
  %20 = shl nuw nsw i64 %19, 2
  %21 = add nuw nsw i64 %20, 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %scevgep, i8 -1, i64 %21, i1 false), !tbaa !5
  br label %._crit_edge27

.lr.ph24:                                         ; preds = %.lr.ph24.preheader37, %.lr.ph24
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %.lr.ph24 ], [ %indvars.iv29.ph, %.lr.ph24.preheader37 ]
  %22 = getelementptr inbounds double, ptr %3, i64 %indvars.iv29
  store double -1.000000e+00, ptr %22, align 8, !tbaa !9
  %indvars.iv.next30 = add nsw i64 %indvars.iv29, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next30, %wide.trip.count32
  br i1 %exitcond33.not, label %.preheader, label %.lr.ph24, !llvm.loop !16

._crit_edge27:                                    ; preds = %._crit_edge, %.lr.ph26.preheader, %.preheader
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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"}
!13 = distinct !{!13, !12, !14, !15}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !12, !15, !14}


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