; 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_first_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 ptr, align 8
  %8 = alloca i32, align 4
  %9 = 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 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = mul i64 %11, 4
  %13 = call noalias ptr @malloc(i64 noundef %12) #5
  store ptr %13, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %23, %3
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %26

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

23:                                               ; preds = %18
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %8, align 4, !tbaa !5
  br label %14, !llvm.loop !13

26:                                               ; preds = %14
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %27

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

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

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

46:                                               ; preds = %72, %38
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %50, label %75

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

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

71:                                               ; preds = %65, %50
  br label %72

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

75:                                               ; preds = %46
  br label %76

76:                                               ; preds = %75, %31
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %8, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %8, align 4, !tbaa !5
  br label %27, !llvm.loop !16

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

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_first_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.ph34.preheader, label %._crit_edge

.lr.ph34.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.count43 = zext nneg i32 %0 to i64
  %broadcast.splatinsert46 = insertelement <2 x double> poison, double %2, i64 0
  %broadcast.splat47 = shufflevector <2 x double> %broadcast.splatinsert46, <2 x double> poison, <2 x i32> zeroinitializer
  %invariant.gep = getelementptr i8, ptr %6, i64 4
  %invariant.gep54 = getelementptr i8, ptr %6, i64 8
  %invariant.gep56 = getelementptr i8, ptr %6, i64 12
  br label %.lr.ph34

.lr.ph34:                                         ; preds = %.lr.ph34.preheader, %.loopexit
  %indvar = phi i64 [ 0, %.lr.ph34.preheader ], [ %indvar.next, %.loopexit ]
  %indvars.iv39 = phi i64 [ 0, %.lr.ph34.preheader ], [ %indvars.iv.next40.pre-phi, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph34.preheader ], [ %indvars.iv.next, %.loopexit ]
  %10 = xor i64 %indvar, -1
  %11 = add i64 %10, %wide.trip.count43
  %12 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv39
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %15, label %.lr.ph34..loopexit_crit_edge

.lr.ph34..loopexit_crit_edge:                     ; preds = %.lr.ph34
  %.pre = add nuw nsw i64 %indvars.iv39, 1
  br label %.loopexit

15:                                               ; preds = %.lr.ph34
  %16 = trunc nuw nsw i64 %indvars.iv39 to i32
  store i32 %16, ptr %12, align 4, !tbaa !5
  %17 = add nuw nsw i64 %indvars.iv39, 1
  %18 = icmp slt i64 %17, %4
  br i1 %18, label %.lr.ph31, label %.loopexit

.lr.ph31:                                         ; preds = %15
  %19 = getelementptr inbounds double, ptr %1, i64 %indvars.iv39
  %20 = load double, ptr %19, 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.ph31
  %n.vec = and i64 %11, -4
  %ind.end = add i64 %indvars.iv, %n.vec
  %broadcast.splatinsert = insertelement <2 x double> poison, double %20, 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.continue53, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %pred.store.continue53 ]
  %offset.idx = add i64 %indvars.iv, %index
  %21 = getelementptr inbounds double, ptr %1, i64 %offset.idx
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %wide.load = load <2 x double>, ptr %21, align 8, !tbaa !9
  %wide.load45 = load <2 x double>, ptr %22, align 8, !tbaa !9
  %23 = fsub <2 x double> %broadcast.splat, %wide.load
  %24 = fsub <2 x double> %broadcast.splat, %wide.load45
  %25 = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %23)
  %26 = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %24)
  %27 = fcmp ole <2 x double> %25, %broadcast.splat47
  %28 = fcmp ole <2 x double> %26, %broadcast.splat47
  %29 = extractelement <2 x i1> %27, i64 0
  br i1 %29, label %pred.store.if, label %pred.store.continue

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

pred.store.continue:                              ; preds = %pred.store.if, %vector.body
  %31 = extractelement <2 x i1> %27, i64 1
  br i1 %31, label %pred.store.if48, label %pred.store.continue49

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

pred.store.continue49:                            ; preds = %pred.store.if48, %pred.store.continue
  %32 = extractelement <2 x i1> %28, i64 0
  br i1 %32, label %pred.store.if50, label %pred.store.continue51

pred.store.if50:                                  ; preds = %pred.store.continue49
  %gep55 = getelementptr i32, ptr %invariant.gep54, i64 %offset.idx
  store i32 %16, ptr %gep55, align 4, !tbaa !5
  br label %pred.store.continue51

pred.store.continue51:                            ; preds = %pred.store.if50, %pred.store.continue49
  %33 = extractelement <2 x i1> %28, i64 1
  br i1 %33, label %pred.store.if52, label %pred.store.continue53

pred.store.if52:                                  ; preds = %pred.store.continue51
  %gep57 = getelementptr i32, ptr %invariant.gep56, i64 %offset.idx
  store i32 %16, ptr %gep57, align 4, !tbaa !5
  br label %pred.store.continue53

pred.store.continue53:                            ; preds = %pred.store.if52, %pred.store.continue51
  %index.next = add nuw i64 %index, 4
  %34 = icmp eq i64 %index.next, %n.vec
  br i1 %34, label %middle.block, label %vector.body, !llvm.loop !11

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

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

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

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

42:                                               ; preds = %scalar.ph, %40
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next37, %wide.trip.count43
  br i1 %exitcond.not, label %.loopexit, label %scalar.ph, !llvm.loop !15

.loopexit:                                        ; preds = %42, %middle.block, %.lr.ph34..loopexit_crit_edge, %15
  %indvars.iv.next40.pre-phi = phi i64 [ %.pre, %.lr.ph34..loopexit_crit_edge ], [ %17, %15 ], [ %17, %middle.block ], [ %17, %42 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond44.not = icmp eq i64 %indvars.iv.next40.pre-phi, %wide.trip.count43
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond44.not, label %._crit_edge, label %.lr.ph34, !llvm.loop !16

._crit_edge:                                      ; preds = %.loopexit, %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