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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.174 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.175 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.176 = external hidden unnamed_addr constant [21 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local double @r8_log_2(double noundef) #4

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

9:                                                ; preds = %28, %2
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %31

13:                                               ; preds = %9
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds double, ptr %14, i64 %16
  %18 = load double, ptr %17, align 8, !tbaa !11
  %19 = fcmp olt double %18, 0.000000e+00
  br i1 %19, label %20, label %27

20:                                               ; preds = %13
  %21 = load ptr, ptr @stderr, align 8, !tbaa !9
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str) #5
  %23 = load ptr, ptr @stderr, align 8, !tbaa !9
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.174) #5
  %25 = load ptr, ptr @stderr, align 8, !tbaa !9
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str.175) #5
  call void @exit(i32 noundef 1) #6
  unreachable

27:                                               ; preds = %13
  br label %28

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

31:                                               ; preds = %9
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %44, %31
  %33 = load i32, ptr %5, 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 %47

36:                                               ; preds = %32
  %37 = load double, ptr %7, align 8, !tbaa !11
  %38 = load ptr, ptr %4, align 8, !tbaa !9
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %38, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = fadd double %37, %42
  store double %43, ptr %7, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %36
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %5, align 4, !tbaa !5
  br label %32, !llvm.loop !15

47:                                               ; preds = %32
  %48 = load double, ptr %7, align 8, !tbaa !11
  %49 = fcmp oeq double %48, 0.000000e+00
  br i1 %49, label %50, label %57

50:                                               ; preds = %47
  %51 = load ptr, ptr @stderr, align 8, !tbaa !9
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef @.str) #5
  %53 = load ptr, ptr @stderr, align 8, !tbaa !9
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef @.str.174) #5
  %55 = load ptr, ptr @stderr, align 8, !tbaa !9
  %56 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef @.str.176) #5
  call void @exit(i32 noundef 1) #6
  unreachable

57:                                               ; preds = %47
  store double 0.000000e+00, ptr %6, align 8, !tbaa !11
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %84, %57
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %62, label %87

62:                                               ; preds = %58
  %63 = load ptr, ptr %4, align 8, !tbaa !9
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds double, ptr %63, i64 %65
  %67 = load double, ptr %66, align 8, !tbaa !11
  %68 = fcmp olt double 0.000000e+00, %67
  br i1 %68, label %69, label %83

69:                                               ; preds = %62
  %70 = load ptr, ptr %4, align 8, !tbaa !9
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds double, ptr %70, i64 %72
  %74 = load double, ptr %73, align 8, !tbaa !11
  %75 = load double, ptr %7, align 8, !tbaa !11
  %76 = fdiv double %74, %75
  store double %76, ptr %8, align 8, !tbaa !11
  %77 = load double, ptr %6, align 8, !tbaa !11
  %78 = load double, ptr %8, align 8, !tbaa !11
  %79 = call double @r8_log_2(double noundef %78)
  %80 = load double, ptr %8, align 8, !tbaa !11
  %81 = fneg double %79
  %82 = call double @llvm.fmuladd.f64(double %81, double %80, double %77)
  store double %82, ptr %6, align 8, !tbaa !11
  br label %83

83:                                               ; preds = %69, %62
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %5, align 4, !tbaa !5
  br label %58, !llvm.loop !16

87:                                               ; preds = %58
  %88 = load double, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret double %88
}

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 = { noreturn 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { noreturn 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.174 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.175 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.176 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local double @r8_log_2(double noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local double @r8vec_entropy(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #3 {
  %3 = icmp sgt i32 %0, 0
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge.thread

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.lr.ph

4:                                                ; preds = %.lr.ph
  %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 %.preheader28, label %.lr.ph, !llvm.loop !5

.preheader28:                                     ; preds = %4
  br i1 %3, label %.lr.ph32.preheader, label %._crit_edge.thread

.lr.ph32.preheader:                               ; preds = %.preheader28
  %xtraiter = and i64 %wide.trip.count, 7
  %5 = icmp ult i32 %0, 8
  br i1 %5, label %._crit_edge.unr-lcssa, label %.lr.ph32.preheader.new

.lr.ph32.preheader.new:                           ; preds = %.lr.ph32.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483640
  br label %.lr.ph32

.lr.ph:                                           ; preds = %.lr.ph.preheader, %4
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %4 ]
  %6 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %7 = load double, ptr %6, align 8, !tbaa !7
  %8 = fcmp olt double %7, 0.000000e+00
  br i1 %8, label %9, label %4

9:                                                ; preds = %.lr.ph
  %10 = load ptr, ptr @stderr, align 8, !tbaa !11
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str) #4
  %12 = load ptr, ptr @stderr, align 8, !tbaa !11
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.174) #4
  %14 = load ptr, ptr @stderr, align 8, !tbaa !11
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str.175) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

.lr.ph32:                                         ; preds = %.lr.ph32, %.lr.ph32.preheader.new
  %indvars.iv39 = phi i64 [ 0, %.lr.ph32.preheader.new ], [ %indvars.iv.next40.7, %.lr.ph32 ]
  %.02330 = phi double [ 0.000000e+00, %.lr.ph32.preheader.new ], [ %39, %.lr.ph32 ]
  %niter = phi i64 [ 0, %.lr.ph32.preheader.new ], [ %niter.next.7, %.lr.ph32 ]
  %16 = getelementptr inbounds double, ptr %1, i64 %indvars.iv39
  %17 = load double, ptr %16, align 8, !tbaa !7
  %18 = fadd double %.02330, %17
  %indvars.iv.next40 = or disjoint i64 %indvars.iv39, 1
  %19 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next40
  %20 = load double, ptr %19, align 8, !tbaa !7
  %21 = fadd double %18, %20
  %indvars.iv.next40.1 = or disjoint i64 %indvars.iv39, 2
  %22 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next40.1
  %23 = load double, ptr %22, align 8, !tbaa !7
  %24 = fadd double %21, %23
  %indvars.iv.next40.2 = or disjoint i64 %indvars.iv39, 3
  %25 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next40.2
  %26 = load double, ptr %25, align 8, !tbaa !7
  %27 = fadd double %24, %26
  %indvars.iv.next40.3 = or disjoint i64 %indvars.iv39, 4
  %28 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next40.3
  %29 = load double, ptr %28, align 8, !tbaa !7
  %30 = fadd double %27, %29
  %indvars.iv.next40.4 = or disjoint i64 %indvars.iv39, 5
  %31 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next40.4
  %32 = load double, ptr %31, align 8, !tbaa !7
  %33 = fadd double %30, %32
  %indvars.iv.next40.5 = or disjoint i64 %indvars.iv39, 6
  %34 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next40.5
  %35 = load double, ptr %34, align 8, !tbaa !7
  %36 = fadd double %33, %35
  %indvars.iv.next40.6 = or disjoint i64 %indvars.iv39, 7
  %37 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next40.6
  %38 = load double, ptr %37, align 8, !tbaa !7
  %39 = fadd double %36, %38
  %indvars.iv.next40.7 = add nuw nsw i64 %indvars.iv39, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.unr-lcssa, label %.lr.ph32, !llvm.loop !13

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph32, %.lr.ph32.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph32.preheader ], [ %39, %.lr.ph32 ]
  %indvars.iv39.unr = phi i64 [ 0, %.lr.ph32.preheader ], [ %indvars.iv.next40.7, %.lr.ph32 ]
  %.02330.unr = phi double [ 0.000000e+00, %.lr.ph32.preheader ], [ %39, %.lr.ph32 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph32.epil

.lr.ph32.epil:                                    ; preds = %._crit_edge.unr-lcssa, %.lr.ph32.epil
  %indvars.iv39.epil = phi i64 [ %indvars.iv.next40.epil, %.lr.ph32.epil ], [ %indvars.iv39.unr, %._crit_edge.unr-lcssa ]
  %.02330.epil = phi double [ %42, %.lr.ph32.epil ], [ %.02330.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph32.epil ], [ 0, %._crit_edge.unr-lcssa ]
  %40 = getelementptr inbounds double, ptr %1, i64 %indvars.iv39.epil
  %41 = load double, ptr %40, align 8, !tbaa !7
  %42 = fadd double %.02330.epil, %41
  %indvars.iv.next40.epil = add nuw nsw i64 %indvars.iv39.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph32.epil, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph32.epil, %._crit_edge.unr-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %42, %.lr.ph32.epil ]
  %43 = fcmp oeq double %.lcssa, 0.000000e+00
  br i1 %43, label %._crit_edge.thread, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  br i1 %3, label %.lr.ph35.preheader, label %._crit_edge36

.lr.ph35.preheader:                               ; preds = %.preheader
  %wide.trip.count47 = zext nneg i32 %0 to i64
  br label %.lr.ph35

._crit_edge.thread:                               ; preds = %2, %.preheader28, %._crit_edge
  %44 = load ptr, ptr @stderr, align 8, !tbaa !11
  %45 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef nonnull @.str) #4
  %46 = load ptr, ptr @stderr, align 8, !tbaa !11
  %47 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef nonnull @.str.174) #4
  %48 = load ptr, ptr @stderr, align 8, !tbaa !11
  %49 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef nonnull @.str.176) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %58
  %indvars.iv44 = phi i64 [ 0, %.lr.ph35.preheader ], [ %indvars.iv.next45, %58 ]
  %.02433 = phi double [ 0.000000e+00, %.lr.ph35.preheader ], [ %.125, %58 ]
  %50 = getelementptr inbounds double, ptr %1, i64 %indvars.iv44
  %51 = load double, ptr %50, align 8, !tbaa !7
  %52 = fcmp ogt double %51, 0.000000e+00
  br i1 %52, label %53, label %58

53:                                               ; preds = %.lr.ph35
  %54 = fdiv double %51, %.lcssa
  %55 = tail call double @r8_log_2(double noundef %54)
  %56 = fneg double %55
  %57 = tail call double @llvm.fmuladd.f64(double %56, double %54, double %.02433)
  br label %58

58:                                               ; preds = %.lr.ph35, %53
  %.125 = phi double [ %57, %53 ], [ %.02433, %.lr.ph35 ]
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %exitcond48.not = icmp eq i64 %indvars.iv.next45, %wide.trip.count47
  br i1 %exitcond48.not, label %._crit_edge36, label %.lr.ph35, !llvm.loop !16

._crit_edge36:                                    ; preds = %58, %.preheader
  %.024.lcssa = phi double [ 0.000000e+00, %.preheader ], [ %.125, %58 ]
  ret double %.024.lcssa
}

attributes #0 = { nofree 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 #1 = { noreturn 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 = { mustprogress 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 = { cold nounwind }
attributes #5 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = distinct !{!13, !6}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass