; 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(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 %69

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 double, ptr %8, align 8, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %31, i64 %34
  store double %30, ptr %35, align 8, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %36, align 4, !tbaa !11
  store i32 %37, ptr %10, align 4, !tbaa !11
  br label %38

38:                                               ; preds = %53, %24
  %39 = load i32, ptr %12, align 4, !tbaa !11
  %40 = load i32, ptr %10, align 4, !tbaa !11
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %42, label %56

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

53:                                               ; preds = %42
  %54 = load i32, ptr %10, align 4, !tbaa !11
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %10, align 4, !tbaa !11
  br label %38, !llvm.loop !13

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

69:                                               ; preds = %56, %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(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 %33

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 %0, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds double, ptr %1, i64 %13
  store double %3, ptr %14, align 8, !tbaa !9
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %.not24 = icmp sgt i32 %15, %12
  %.pre28 = sext i32 %15 to i64
  br i1 %.not24, label %._crit_edge, label %.lr.ph.preheader

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

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %17, -8
  %ind.end = sub nsw i64 %13, %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 %13, %index
  %18 = getelementptr i32, ptr %2, i64 %offset.idx
  %19 = getelementptr i8, ptr %18, i64 -16
  %20 = getelementptr i8, ptr %18, i64 -32
  %wide.load = load <4 x i32>, ptr %19, align 4, !tbaa !5
  %wide.load29 = load <4 x i32>, ptr %20, align 4, !tbaa !5
  %21 = getelementptr i8, ptr %18, i64 -12
  %22 = getelementptr i8, ptr %18, i64 -28
  store <4 x i32> %wide.load, ptr %21, align 4, !tbaa !5
  store <4 x i32> %wide.load29, ptr %22, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %17, %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 [ %13, %.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 ]
  %24 = getelementptr i32, ptr %2, i64 %indvars.iv
  %25 = getelementptr i8, ptr %24, i64 -4
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr %24, 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 = %11, %._crit_edge.loopexit
  %27 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %12, %11 ]
  %28 = add nsw i32 %27, 1
  %29 = getelementptr i32, ptr %2, i64 %.pre28
  %30 = getelementptr i8, ptr %29, i64 -4
  store i32 %28, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr %0, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %0, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %._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