; 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 ptr @i4vec_indicator1_new(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @r8vec_sort_insert_index_a(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca double, 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 1
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %91

14:                                               ; preds = %2
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = call ptr @i4vec_indicator1_new(i32 noundef %15)
  store ptr %16, ptr %7, align 8, !tbaa !9
  store i32 2, ptr %6, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %67, %14
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %21, label %70

21:                                               ; preds = %17
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %22, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !11
  store double %27, ptr %9, align 8, !tbaa !11
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  store i32 %29, ptr %8, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %48, %21
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = icmp sle i32 1, %31
  br i1 %32, label %33, label %61

33:                                               ; preds = %30
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = sub nsw i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %35, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sub nsw i32 %40, 1
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %34, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = load double, ptr %9, align 8, !tbaa !11
  %46 = fcmp ole double %44, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %33
  br label %61

48:                                               ; preds = %33
  %49 = load ptr, ptr %7, align 8, !tbaa !9
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = sub nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %49, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load ptr, ptr %7, align 8, !tbaa !9
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i32, ptr %55, i64 %57
  store i32 %54, ptr %58, align 4, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = sub nsw i32 %59, 1
  store i32 %60, ptr %8, align 4, !tbaa !5
  br label %30, !llvm.loop !13

61:                                               ; preds = %47, %30
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !9
  %64 = load i32, ptr %8, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i32, ptr %63, i64 %65
  store i32 %62, ptr %66, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %61
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %6, align 4, !tbaa !5
  br label %17, !llvm.loop !15

70:                                               ; preds = %17
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %86, %70
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = icmp slt i32 %72, %73
  br i1 %74, label %75, label %89

75:                                               ; preds = %71
  %76 = load ptr, ptr %7, align 8, !tbaa !9
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i32, ptr %76, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = sub nsw i32 %80, 1
  %82 = load ptr, ptr %7, align 8, !tbaa !9
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i32, ptr %82, i64 %84
  store i32 %81, ptr %85, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %75
  %87 = load i32, ptr %6, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %6, align 4, !tbaa !5
  br label %71, !llvm.loop !16

89:                                               ; preds = %71
  %90 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %90, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %91

91:                                               ; preds = %89, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %92 = load ptr, ptr %3, align 8
  ret ptr %92
}

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 ptr @i4vec_indicator1_new(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @r8vec_sort_insert_index_a(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp slt i32 %0, 1
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %2
  %5 = tail call ptr @i4vec_indicator1_new(i32 noundef %0)
  %.not35 = icmp eq i32 %0, 1
  br i1 %.not35, label %.lr.ph40.preheader, label %.lr.ph38

.lr.ph38:                                         ; preds = %4
  %invariant.gep = getelementptr i8, ptr %1, i64 -8
  %6 = add nuw i32 %0, 1
  %wide.trip.count = zext i32 %6 to i64
  %invariant.gep54 = getelementptr i8, ptr %1, i64 -8
  br label %.lr.ph.preheader

.lr.ph40.preheader:                               ; preds = %._crit_edge, %4
  %smax = tail call i32 @llvm.smax.i32(i32 %0, i32 1)
  %wide.trip.count52 = zext nneg i32 %smax to i64
  %min.iters.check = icmp slt i32 %0, 8
  br i1 %min.iters.check, label %.lr.ph40.preheader57, label %vector.ph

.lr.ph40.preheader57:                             ; preds = %middle.block, %.lr.ph40.preheader
  %indvars.iv48.ph = phi i64 [ 0, %.lr.ph40.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph40

vector.ph:                                        ; preds = %.lr.ph40.preheader
  %n.vec = and i64 %wide.trip.count52, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %7 = getelementptr inbounds i32, ptr %5, i64 %index
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %wide.load = load <4 x i32>, ptr %7, align 4, !tbaa !5
  %wide.load56 = load <4 x i32>, ptr %8, align 4, !tbaa !5
  %9 = add nsw <4 x i32> %wide.load, <i32 -1, i32 -1, i32 -1, i32 -1>
  %10 = add nsw <4 x i32> %wide.load56, <i32 -1, i32 -1, i32 -1, i32 -1>
  store <4 x i32> %9, ptr %7, align 4, !tbaa !5
  store <4 x i32> %10, ptr %8, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %11 = icmp eq i64 %index.next, %n.vec
  br i1 %11, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count52
  br i1 %cmp.n, label %.loopexit, label %.lr.ph40.preheader57

.lr.ph.preheader:                                 ; preds = %._crit_edge, %.lr.ph38
  %indvars.iv44 = phi i64 [ 2, %.lr.ph38 ], [ %indvars.iv.next45, %._crit_edge ]
  %indvars.iv = phi i64 [ 1, %.lr.ph38 ], [ %indvars.iv.next, %._crit_edge ]
  %gep55 = getelementptr double, ptr %invariant.gep54, i64 %indvars.iv44
  %12 = load double, ptr %gep55, align 8, !tbaa !13
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %indvars.iv41 = phi i64 [ %indvars.iv, %.lr.ph.preheader ], [ %indvars.iv.next42, %19 ]
  %indvars.iv.next42 = add nsw i64 %indvars.iv41, -1
  %13 = and i64 %indvars.iv.next42, 4294967295
  %14 = getelementptr inbounds i32, ptr %5, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %gep = getelementptr double, ptr %invariant.gep, i64 %16
  %17 = load double, ptr %gep, align 8, !tbaa !13
  %18 = fcmp ugt double %17, %12
  br i1 %18, label %19, label %._crit_edge

19:                                               ; preds = %.lr.ph
  %20 = getelementptr inbounds i32, ptr %5, i64 %indvars.iv41
  store i32 %15, ptr %20, align 4, !tbaa !5
  %21 = icmp sgt i64 %indvars.iv41, 1
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %19, %.lr.ph
  %.029.lcssa.ph = phi i64 [ 0, %19 ], [ %indvars.iv41, %.lr.ph ]
  %sext = shl i64 %.029.lcssa.ph, 32
  %22 = ashr exact i64 %sext, 30
  %23 = getelementptr inbounds i8, ptr %5, i64 %22
  %24 = trunc nuw nsw i64 %indvars.iv44 to i32
  store i32 %24, ptr %23, align 4, !tbaa !5
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next45, %wide.trip.count
  br i1 %exitcond.not, label %.lr.ph40.preheader, label %.lr.ph.preheader, !llvm.loop !16

.lr.ph40:                                         ; preds = %.lr.ph40.preheader57, %.lr.ph40
  %indvars.iv48 = phi i64 [ %indvars.iv.next49, %.lr.ph40 ], [ %indvars.iv48.ph, %.lr.ph40.preheader57 ]
  %25 = getelementptr inbounds i32, ptr %5, i64 %indvars.iv48
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %25, align 4, !tbaa !5
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %exitcond53.not = icmp eq i64 %indvars.iv.next49, %wide.trip.count52
  br i1 %exitcond53.not, label %.loopexit, label %.lr.ph40, !llvm.loop !17

.loopexit:                                        ; preds = %.lr.ph40, %middle.block, %2
  %.0 = phi ptr [ null, %2 ], [ %5, %middle.block ], [ %5, %.lr.ph40 ]
  ret ptr %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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 nosync nounwind speculatable willreturn memory(none) }

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


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