; 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_search(i32 noundef, ptr noundef, ptr noundef, double noundef, ptr noundef, ptr noundef, ptr noundef) #1

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

17:                                               ; preds = %4
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %18, align 4, !tbaa !11
  %19 = load double, ptr %8, align 8, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds double, ptr %20, i64 0
  store double %19, ptr %21, align 8, !tbaa !9
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds i32, ptr %22, i64 0
  store i32 1, ptr %23, align 4, !tbaa !11
  store i32 1, ptr %13, align 4
  br label %73

24:                                               ; preds = %4
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load double, ptr %8, align 8, !tbaa !9
  call void @r8vec_index_search(i32 noundef %26, ptr noundef %27, ptr noundef %28, double noundef %29, ptr noundef %11, ptr noundef %9, ptr noundef %12)
  %30 = load i32, ptr %9, align 4, !tbaa !11
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %72

32:                                               ; preds = %24
  %33 = load double, ptr %8, align 8, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %34, i64 %37
  store double %33, ptr %38, align 8, !tbaa !9
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %39, align 4, !tbaa !11
  store i32 %40, ptr %10, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %56, %32
  %42 = load i32, ptr %12, align 4, !tbaa !11
  %43 = load i32, ptr %10, align 4, !tbaa !11
  %44 = icmp sle i32 %42, %43
  br i1 %44, label %45, label %59

45:                                               ; preds = %41
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !11
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %46, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !11
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !11
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  store i32 %51, ptr %55, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %45
  %57 = load i32, ptr %10, align 4, !tbaa !11
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr %10, align 4, !tbaa !11
  br label %41, !llvm.loop !13

59:                                               ; preds = %41
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load i32, ptr %60, align 4, !tbaa !11
  %62 = add nsw i32 %61, 1
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i32, ptr %12, align 4, !tbaa !11
  %65 = sub nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %63, i64 %66
  store i32 %62, ptr %67, align 4, !tbaa !11
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load i32, ptr %68, align 4, !tbaa !11
  %70 = add nsw i32 %69, 1
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %70, ptr %71, align 4, !tbaa !11
  br label %72

72:                                               ; preds = %59, %24
  store i32 1, ptr %13, align 4
  br label %73

73:                                               ; preds = %72, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #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 = !{!"any pointer", !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 = !{!12, !12, i64 0}
!12 = !{!"int", !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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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_search(i32 noundef, ptr noundef, ptr noundef, double noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @r8vec_index_insert_unique(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2, double noundef %3) local_unnamed_addr #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #2
  %8 = load i32, ptr %0, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 1
  br i1 %9, label %10, label %11

10:                                               ; preds = %4
  store i32 1, ptr %0, align 4, !tbaa !5
  store double %3, ptr %1, align 8, !tbaa !9
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %36

11:                                               ; preds = %4
  call void @r8vec_index_search(i32 noundef %8, ptr noundef %1, ptr noundef %2, double noundef %3, ptr noundef nonnull %6, ptr noundef nonnull %5, ptr noundef nonnull %7)
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %36

14:                                               ; preds = %11
  %15 = load i32, ptr %0, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds double, ptr %1, i64 %16
  store double %3, ptr %17, align 8, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %.not24 = icmp sgt i32 %18, %15
  %.pre28 = sext i32 %18 to i64
  br i1 %.not24, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %14
  %19 = add nsw i64 %16, 1
  %20 = sub nsw i64 %19, %.pre28
  %min.iters.check = icmp ult i64 %20, 8
  br i1 %min.iters.check, label %.lr.ph.preheader33, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %20, -8
  %ind.end = sub nsw i64 %16, %n.vec
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %16, %index
  %21 = getelementptr i32, ptr %2, i64 %offset.idx
  %22 = getelementptr i8, ptr %21, i64 -16
  %23 = getelementptr i8, ptr %21, i64 -32
  %wide.load = load <4 x i32>, ptr %22, align 4, !tbaa !5
  %wide.load29 = load <4 x i32>, ptr %23, align 4, !tbaa !5
  %24 = getelementptr i8, ptr %21, i64 -12
  %25 = getelementptr i8, ptr %21, i64 -28
  store <4 x i32> %wide.load, ptr %24, align 4, !tbaa !5
  store <4 x i32> %wide.load29, ptr %25, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %26 = icmp eq i64 %index.next, %n.vec
  br i1 %26, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %20, %n.vec
  br i1 %cmp.n, label %._crit_edge.loopexit, label %.lr.ph.preheader33

.lr.ph.preheader33:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ %16, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader33, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader33 ]
  %27 = getelementptr i32, ptr %2, i64 %indvars.iv
  %28 = getelementptr i8, ptr %27, i64 -4
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %27, align 4, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not.not = icmp sgt i64 %indvars.iv, %.pre28
  br i1 %.not.not, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !15

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

._crit_edge:                                      ; preds = %14, %._crit_edge.loopexit
  %30 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %15, %14 ]
  %31 = add nsw i32 %30, 1
  %32 = getelementptr i32, ptr %2, i64 %.pre28
  %33 = getelementptr i8, ptr %32, i64 -4
  store i32 %31, ptr %33, align 4, !tbaa !5
  %34 = load i32, ptr %0, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %0, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %11, %._crit_edge, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  ret void
}

attributes #0 = { mustprogress 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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !14, !13}


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