; 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
declare void @free(ptr noundef) #1

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

16:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %71

17:                                               ; preds = %3
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = call ptr @r8vec_copy_new(i32 noundef %19, ptr noundef %20)
  store ptr %21, ptr %9, align 8, !tbaa !9
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %59, %17
  %23 = load i32, ptr %10, align 4, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %26, label %62

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

27:                                               ; preds = %48, %26
  %28 = load i32, ptr %11, align 4, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = load i32, ptr %10, align 4, !tbaa !5
  %31 = sub nsw i32 %29, %30
  %32 = icmp sle i32 %28, %31
  br i1 %32, label %33, label %51

33:                                               ; preds = %27
  %34 = load i32, ptr %11, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = sitofp i32 %35 to double
  %37 = load ptr, ptr %9, align 8, !tbaa !9
  %38 = load i32, ptr %11, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %37, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = fmul double %36, %42
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  %45 = load i32, ptr %11, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %44, i64 %46
  store double %43, ptr %47, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %33
  %49 = load i32, ptr %11, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %11, align 4, !tbaa !5
  br label %27, !llvm.loop !13

51:                                               ; preds = %27
  %52 = load ptr, ptr %9, align 8, !tbaa !9
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = sub nsw i32 %53, %54
  %56 = add nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds double, ptr %52, i64 %57
  store double 0.000000e+00, ptr %58, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %51
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %10, align 4, !tbaa !5
  br label %22, !llvm.loop !15

62:                                               ; preds = %22
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = sub nsw i32 %63, %64
  %66 = add nsw i32 %65, 1
  %67 = load ptr, ptr %9, align 8, !tbaa !9
  %68 = call ptr @r8vec_copy_new(i32 noundef %66, ptr noundef %67)
  store ptr %68, ptr %8, align 8, !tbaa !9
  %69 = load ptr, ptr %9, align 8, !tbaa !9
  call void @free(ptr noundef %69) #3
  %70 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %70, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %71

71:                                               ; preds = %62, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %72 = load ptr, ptr %4, align 8
  ret ptr %72
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @r8vec_copy_new(i32 noundef, ptr noundef) #2

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


; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @r8poly_deriv(i32 noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = icmp slt i32 %0, %2
  br i1 %4, label %39, label %5

5:                                                ; preds = %3
  %6 = add i32 %0, 1
  %7 = tail call ptr @r8vec_copy_new(i32 noundef %6, ptr noundef %1)
  %invariant.gep = getelementptr i8, ptr %7, i64 8
  %.not32 = icmp slt i32 %2, 1
  br i1 %.not32, label %._crit_edge34, label %.preheader.preheader

.preheader.preheader:                             ; preds = %5
  %8 = sext i32 %0 to i64
  %9 = add nuw i32 %2, 1
  %wide.trip.count41 = zext i32 %9 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv38 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next39, %._crit_edge ]
  %indvars.iv36 = phi i32 [ %0, %.preheader.preheader ], [ %indvars.iv.next37, %._crit_edge ]
  %10 = zext i32 %indvars.iv36 to i64
  %11 = sub nsw i64 %8, %indvars.iv38
  %.not2930 = icmp slt i64 %11, 0
  br i1 %.not2930, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext i32 %indvars.iv36 to i64
  %min.iters.check = icmp ult i32 %indvars.iv36, 4
  br i1 %min.iters.check, label %.lr.ph.preheader44, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %10, 4294967292
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %12 = insertelement <2 x i64> poison, i64 %index, i64 0
  %13 = shufflevector <2 x i64> %12, <2 x i64> poison, <2 x i32> zeroinitializer
  %14 = or disjoint <2 x i64> %13, <i64 1, i64 2>
  %15 = or disjoint i64 %index, 3
  %16 = add nuw nsw i64 %index, 4
  %17 = insertelement <2 x i64> poison, i64 %15, i64 0
  %18 = insertelement <2 x i64> %17, i64 %16, i64 1
  %19 = trunc <2 x i64> %14 to <2 x i32>
  %20 = trunc <2 x i64> %18 to <2 x i32>
  %21 = uitofp <2 x i32> %19 to <2 x double>
  %22 = uitofp <2 x i32> %20 to <2 x double>
  %23 = extractelement <2 x i64> %14, i64 0
  %24 = getelementptr inbounds double, ptr %7, i64 %23
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %wide.load = load <2 x double>, ptr %24, align 8, !tbaa !5
  %wide.load43 = load <2 x double>, ptr %25, align 8, !tbaa !5
  %26 = fmul <2 x double> %wide.load, %21
  %27 = fmul <2 x double> %wide.load43, %22
  %28 = getelementptr inbounds double, ptr %7, i64 %index
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  store <2 x double> %26, ptr %28, align 8, !tbaa !5
  store <2 x double> %27, ptr %29, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %30 = icmp eq i64 %index.next, %n.vec
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !9

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

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

.lr.ph:                                           ; preds = %.lr.ph.preheader44, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader44 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = trunc nuw nsw i64 %indvars.iv.next to i32
  %32 = uitofp nneg i32 %31 to double
  %33 = getelementptr inbounds double, ptr %7, i64 %indvars.iv.next
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = fmul double %34, %32
  %36 = getelementptr inbounds double, ptr %7, i64 %indvars.iv
  store double %35, ptr %36, align 8, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %.preheader
  %gep = getelementptr double, ptr %invariant.gep, i64 %11
  store double 0.000000e+00, ptr %gep, align 8, !tbaa !5
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %indvars.iv.next37 = add i32 %indvars.iv36, -1
  %exitcond42.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count41
  br i1 %exitcond42.not, label %._crit_edge34, label %.preheader, !llvm.loop !14

._crit_edge34:                                    ; preds = %._crit_edge, %5
  %37 = sub i32 %6, %2
  %38 = tail call ptr @r8vec_copy_new(i32 noundef %37, ptr noundef %7)
  tail call void @free(ptr noundef %7) #2
  br label %39

39:                                               ; preds = %3, %._crit_edge34
  %.025 = phi ptr [ %38, %._crit_edge34 ], [ null, %3 ]
  ret ptr %.025
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @r8vec_copy_new(i32 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 = { 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 = !{!"double", !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 = distinct !{!13, !10, !12, !11}
!14 = distinct !{!14, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass