; 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

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

15:                                               ; preds = %24, %3
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %27

19:                                               ; preds = %15
  %20 = load ptr, ptr %9, align 8, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %20, i64 %22
  store i32 -1, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %19
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %7, align 4, !tbaa !5
  br label %15, !llvm.loop !13

27:                                               ; preds = %15
  store i32 0, ptr %10, align 4, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %80, %27
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %83

32:                                               ; preds = %28
  %33 = load ptr, ptr %9, align 8, !tbaa !9
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %33, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = icmp eq i32 %37, -1
  br i1 %38, label %39, label %79

39:                                               ; preds = %32
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !9
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %41, i64 %43
  store i32 %40, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %8, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %73, %39
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %76

51:                                               ; preds = %47
  %52 = load ptr, ptr %5, align 8, !tbaa !9
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %52, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !11
  %57 = load ptr, ptr %5, align 8, !tbaa !9
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %57, i64 %59
  %61 = load double, ptr %60, align 8, !tbaa !11
  %62 = fsub double %56, %61
  %63 = call double @llvm.fabs.f64(double %62)
  %64 = load double, ptr %6, align 8, !tbaa !11
  %65 = fcmp ole double %63, %64
  br i1 %65, label %66, label %72

66:                                               ; preds = %51
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = load ptr, ptr %9, align 8, !tbaa !9
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i32, ptr %68, i64 %70
  store i32 %67, ptr %71, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %66, %51
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %8, align 4, !tbaa !5
  br label %47, !llvm.loop !15

76:                                               ; preds = %47
  %77 = load i32, ptr %10, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %10, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %76, %32
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %7, align 4, !tbaa !5
  br label %28, !llvm.loop !16

83:                                               ; preds = %28
  %84 = load ptr, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret ptr %84
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 }
attributes #5 = { nounwind allocsize(0) }

!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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nofree nounwind memory(readwrite, argmem: read) uwtable
define dso_local noalias noundef ptr @r8vec_unique_index(i32 noundef %0, ptr nocapture noundef readonly %1, double noundef %2) local_unnamed_addr #2 {
  %4 = sext i32 %0 to i64
  %5 = shl nsw i64 %4, 2
  %6 = tail call noalias ptr @malloc(i64 noundef %5) #5
  %7 = icmp sgt i32 %0, 0
  br i1 %7, label %.lr.ph37.preheader, label %._crit_edge38

.lr.ph37.preheader:                               ; preds = %3
  %8 = zext nneg i32 %0 to i64
  %9 = shl nuw nsw i64 %8, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %6, i8 -1, i64 %9, i1 false), !tbaa !5
  %wide.trip.count47 = zext nneg i32 %0 to i64
  %broadcast.splatinsert50 = insertelement <2 x double> poison, double %2, i64 0
  %broadcast.splat51 = shufflevector <2 x double> %broadcast.splatinsert50, <2 x double> poison, <2 x i32> zeroinitializer
  %invariant.gep = getelementptr i8, ptr %6, i64 4
  %invariant.gep58 = getelementptr i8, ptr %6, i64 8
  %invariant.gep60 = getelementptr i8, ptr %6, i64 12
  br label %.lr.ph37

.lr.ph37:                                         ; preds = %.lr.ph37.preheader, %43
  %indvar = phi i64 [ 0, %.lr.ph37.preheader ], [ %indvar.next, %43 ]
  %indvars.iv43 = phi i64 [ 0, %.lr.ph37.preheader ], [ %indvars.iv.next44.pre-phi, %43 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph37.preheader ], [ %indvars.iv.next, %43 ]
  %.036 = phi i32 [ 0, %.lr.ph37.preheader ], [ %.1, %43 ]
  %10 = xor i64 %indvar, -1
  %11 = add i64 %10, %wide.trip.count47
  %12 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv43
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %15, label %.lr.ph37._crit_edge

.lr.ph37._crit_edge:                              ; preds = %.lr.ph37
  %.pre = add nuw nsw i64 %indvars.iv43, 1
  br label %43

15:                                               ; preds = %.lr.ph37
  store i32 %.036, ptr %12, align 4, !tbaa !5
  %16 = add nuw nsw i64 %indvars.iv43, 1
  %17 = icmp slt i64 %16, %4
  br i1 %17, label %.lr.ph34, label %._crit_edge

.lr.ph34:                                         ; preds = %15
  %18 = getelementptr inbounds double, ptr %1, i64 %indvars.iv43
  %19 = load double, ptr %18, align 8, !tbaa !9
  %min.iters.check = icmp ult i64 %11, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph34
  %n.vec = and i64 %11, -4
  %ind.end = add i64 %indvars.iv, %n.vec
  %broadcast.splatinsert = insertelement <2 x double> poison, double %19, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %pred.store.continue57, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %pred.store.continue57 ]
  %offset.idx = add i64 %indvars.iv, %index
  %20 = getelementptr inbounds double, ptr %1, i64 %offset.idx
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %wide.load = load <2 x double>, ptr %20, align 8, !tbaa !9
  %wide.load49 = load <2 x double>, ptr %21, align 8, !tbaa !9
  %22 = fsub <2 x double> %broadcast.splat, %wide.load
  %23 = fsub <2 x double> %broadcast.splat, %wide.load49
  %24 = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %22)
  %25 = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %23)
  %26 = fcmp ole <2 x double> %24, %broadcast.splat51
  %27 = fcmp ole <2 x double> %25, %broadcast.splat51
  %28 = extractelement <2 x i1> %26, i64 0
  br i1 %28, label %pred.store.if, label %pred.store.continue

pred.store.if:                                    ; preds = %vector.body
  %29 = getelementptr inbounds i32, ptr %6, i64 %offset.idx
  store i32 %.036, ptr %29, align 4, !tbaa !5
  br label %pred.store.continue

pred.store.continue:                              ; preds = %pred.store.if, %vector.body
  %30 = extractelement <2 x i1> %26, i64 1
  br i1 %30, label %pred.store.if52, label %pred.store.continue53

pred.store.if52:                                  ; preds = %pred.store.continue
  %gep = getelementptr i32, ptr %invariant.gep, i64 %offset.idx
  store i32 %.036, ptr %gep, align 4, !tbaa !5
  br label %pred.store.continue53

pred.store.continue53:                            ; preds = %pred.store.if52, %pred.store.continue
  %31 = extractelement <2 x i1> %27, i64 0
  br i1 %31, label %pred.store.if54, label %pred.store.continue55

pred.store.if54:                                  ; preds = %pred.store.continue53
  %gep59 = getelementptr i32, ptr %invariant.gep58, i64 %offset.idx
  store i32 %.036, ptr %gep59, align 4, !tbaa !5
  br label %pred.store.continue55

pred.store.continue55:                            ; preds = %pred.store.if54, %pred.store.continue53
  %32 = extractelement <2 x i1> %27, i64 1
  br i1 %32, label %pred.store.if56, label %pred.store.continue57

pred.store.if56:                                  ; preds = %pred.store.continue55
  %gep61 = getelementptr i32, ptr %invariant.gep60, i64 %offset.idx
  store i32 %.036, ptr %gep61, align 4, !tbaa !5
  br label %pred.store.continue57

pred.store.continue57:                            ; preds = %pred.store.if56, %pred.store.continue55
  %index.next = add nuw i64 %index, 4
  %33 = icmp eq i64 %index.next, %n.vec
  br i1 %33, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %pred.store.continue57
  %cmp.n = icmp eq i64 %11, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

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

scalar.ph:                                        ; preds = %scalar.ph.preheader, %41
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %41 ], [ %indvars.iv40.ph, %scalar.ph.preheader ]
  %34 = getelementptr inbounds double, ptr %1, i64 %indvars.iv40
  %35 = load double, ptr %34, align 8, !tbaa !9
  %36 = fsub double %19, %35
  %37 = tail call double @llvm.fabs.f64(double %36)
  %38 = fcmp ugt double %37, %2
  br i1 %38, label %41, label %39

39:                                               ; preds = %scalar.ph
  %40 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv40
  store i32 %.036, ptr %40, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %scalar.ph, %39
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next41, %wide.trip.count47
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %41, %middle.block, %15
  %42 = add nsw i32 %.036, 1
  br label %43

43:                                               ; preds = %.lr.ph37._crit_edge, %._crit_edge
  %indvars.iv.next44.pre-phi = phi i64 [ %.pre, %.lr.ph37._crit_edge ], [ %16, %._crit_edge ]
  %.1 = phi i32 [ %.036, %.lr.ph37._crit_edge ], [ %42, %._crit_edge ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond48.not = icmp eq i64 %indvars.iv.next44.pre-phi, %wide.trip.count47
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond48.not, label %._crit_edge38, label %.lr.ph37, !llvm.loop !16

._crit_edge38:                                    ; preds = %43, %3
  ret ptr %6
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fabs.v2f64(<2 x double>) #4

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nofree nounwind memory(readwrite, argmem: read) 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind allocsize(0) }

!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}
!16 = distinct !{!16, !12}


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