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

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

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

17:                                               ; preds = %2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %27, %17
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %30

22:                                               ; preds = %18
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %23, i64 %25
  store double 5.000000e-01, ptr %26, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %22
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %7, align 4, !tbaa !5
  br label %18, !llvm.loop !13

30:                                               ; preds = %18
  br label %56

31:                                               ; preds = %2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %52, %31
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %55

36:                                               ; preds = %32
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds double, ptr %37, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !11
  %42 = load double, ptr %6, align 8, !tbaa !11
  %43 = fsub double %41, %42
  %44 = load double, ptr %5, align 8, !tbaa !11
  %45 = load double, ptr %6, align 8, !tbaa !11
  %46 = fsub double %44, %45
  %47 = fdiv double %43, %46
  %48 = load ptr, ptr %4, align 8, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %48, i64 %50
  store double %47, ptr %51, align 8, !tbaa !11
  br label %52

52:                                               ; preds = %36
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !5
  br label %32, !llvm.loop !15

55:                                               ; preds = %32
  br label %56

56:                                               ; preds = %55, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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 = !{!"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: nounwind uwtable
declare dso_local double @r8vec_max(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local double @r8vec_min(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @r8vec_ab_to_01(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call double @r8vec_max(i32 noundef %0, ptr noundef %1)
  %4 = tail call double @r8vec_min(i32 noundef %0, ptr noundef %1)
  %5 = fcmp oeq double %4, %3
  %6 = icmp sgt i32 %0, 0
  br i1 %5, label %.preheader, label %.preheader22

.preheader22:                                     ; preds = %2
  br i1 %6, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader22
  %7 = fsub double %3, %4
  %wide.trip.count = zext nneg i32 %0 to i64
  %min.iters.check = icmp eq i32 %0, 1
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

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

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 2147483646
  %broadcast.splatinsert = insertelement <2 x double> poison, double %4, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert36 = insertelement <2 x double> poison, double %7, i64 0
  %broadcast.splat37 = shufflevector <2 x double> %broadcast.splatinsert36, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %8 = getelementptr inbounds double, ptr %1, i64 %index
  %wide.load = load <2 x double>, ptr %8, align 8, !tbaa !5
  %9 = fsub <2 x double> %wide.load, %broadcast.splat
  %10 = fdiv <2 x double> %9, %broadcast.splat37
  store <2 x double> %10, ptr %8, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 2
  %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.count
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

.preheader:                                       ; preds = %2
  br i1 %6, label %.lr.ph26.preheader, label %.loopexit

.lr.ph26.preheader:                               ; preds = %.preheader
  %wide.trip.count32 = zext nneg i32 %0 to i64
  %min.iters.check40 = icmp ult i32 %0, 4
  br i1 %min.iters.check40, label %.lr.ph26.preheader49, label %vector.ph41

vector.ph41:                                      ; preds = %.lr.ph26.preheader
  %n.vec43 = and i64 %wide.trip.count32, 2147483644
  br label %vector.body45

vector.body45:                                    ; preds = %vector.body45, %vector.ph41
  %index46 = phi i64 [ 0, %vector.ph41 ], [ %index.next47, %vector.body45 ]
  %12 = getelementptr inbounds double, ptr %1, i64 %index46
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  store <2 x double> <double 5.000000e-01, double 5.000000e-01>, ptr %12, align 8, !tbaa !5
  store <2 x double> <double 5.000000e-01, double 5.000000e-01>, ptr %13, align 8, !tbaa !5
  %index.next47 = add nuw i64 %index46, 4
  %14 = icmp eq i64 %index.next47, %n.vec43
  br i1 %14, label %middle.block38, label %vector.body45, !llvm.loop !13

middle.block38:                                   ; preds = %vector.body45
  %cmp.n48 = icmp eq i64 %n.vec43, %wide.trip.count32
  br i1 %cmp.n48, label %.loopexit, label %.lr.ph26.preheader49

.lr.ph26.preheader49:                             ; preds = %middle.block38, %.lr.ph26.preheader
  %indvars.iv29.ph = phi i64 [ 0, %.lr.ph26.preheader ], [ %n.vec43, %middle.block38 ]
  br label %.lr.ph26

.lr.ph26:                                         ; preds = %.lr.ph26.preheader49, %.lr.ph26
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %.lr.ph26 ], [ %indvars.iv29.ph, %.lr.ph26.preheader49 ]
  %15 = getelementptr inbounds double, ptr %1, i64 %indvars.iv29
  store double 5.000000e-01, ptr %15, align 8, !tbaa !5
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next30, %wide.trip.count32
  br i1 %exitcond33.not, label %.loopexit, label %.lr.ph26, !llvm.loop !14

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %16 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = fsub double %17, %4
  %19 = fdiv double %18, %7
  store double %19, ptr %16, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %scalar.ph, !llvm.loop !15

.loopexit:                                        ; preds = %scalar.ph, %.lr.ph26, %middle.block, %middle.block38, %.preheader22, %.preheader
  ret void
}

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" }

!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, !11, !12}
!14 = distinct !{!14, !10, !12, !11}
!15 = distinct !{!15, !10, !12, !11}


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