; LLVM IR from JayXon/Leanify :: lib/zopfli (tree)

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

@.str.1 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@__PRETTY_FUNCTION__.ZopfliCalculateEntropy = external hidden unnamed_addr constant [62 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

10:                                               ; preds = %25, %3
  %11 = load i32, ptr %8, align 4, !tbaa !11
  %12 = zext i32 %11 to i64
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %15, label %28

15:                                               ; preds = %10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !11
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds i64, ptr %16, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !11
  %22 = zext i32 %21 to i64
  %23 = add i64 %22, %20
  %24 = trunc i64 %23 to i32
  store i32 %24, ptr %7, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %15
  %26 = load i32, ptr %8, align 4, !tbaa !11
  %27 = add i32 %26, 1
  store i32 %27, ptr %8, align 4, !tbaa !11
  br label %10, !llvm.loop !13

28:                                               ; preds = %10
  %29 = load i32, ptr %7, align 4, !tbaa !11
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %35

31:                                               ; preds = %28
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = uitofp i64 %32 to double
  %34 = call double @log(double noundef %33) #5
  br label %39

35:                                               ; preds = %28
  %36 = load i32, ptr %7, align 4, !tbaa !11
  %37 = uitofp i32 %36 to double
  %38 = call double @log(double noundef %37) #5
  br label %39

39:                                               ; preds = %35, %31
  %40 = phi double [ %34, %31 ], [ %38, %35 ]
  %41 = fmul double %40, 0x3FF71547652B81E1
  store double %41, ptr %9, align 8, !tbaa !15
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %42

42:                                               ; preds = %104, %39
  %43 = load i32, ptr %8, align 4, !tbaa !11
  %44 = zext i32 %43 to i64
  %45 = load i64, ptr %5, align 8, !tbaa !9
  %46 = icmp ult i64 %44, %45
  br i1 %46, label %47, label %107

47:                                               ; preds = %42
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !11
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds i64, ptr %48, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = icmp eq i64 %52, 0
  br i1 %53, label %54, label %60

54:                                               ; preds = %47
  %55 = load double, ptr %9, align 8, !tbaa !15
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !11
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %56, i64 %58
  store double %55, ptr %59, align 8, !tbaa !15
  br label %75

60:                                               ; preds = %47
  %61 = load double, ptr %9, align 8, !tbaa !15
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load i32, ptr %8, align 4, !tbaa !11
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds i64, ptr %62, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !9
  %67 = uitofp i64 %66 to double
  %68 = call double @log(double noundef %67) #5
  %69 = fneg double %68
  %70 = call double @llvm.fmuladd.f64(double %69, double 0x3FF71547652B81E1, double %61)
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !11
  %73 = zext i32 %72 to i64
  %74 = getelementptr inbounds double, ptr %71, i64 %73
  store double %70, ptr %74, align 8, !tbaa !15
  br label %75

75:                                               ; preds = %60, %54
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load i32, ptr %8, align 4, !tbaa !11
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds double, ptr %76, i64 %78
  %80 = load double, ptr %79, align 8, !tbaa !15
  %81 = fcmp olt double %80, 0.000000e+00
  br i1 %81, label %82, label %94

82:                                               ; preds = %75
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = load i32, ptr %8, align 4, !tbaa !11
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds double, ptr %83, i64 %85
  %87 = load double, ptr %86, align 8, !tbaa !15
  %88 = fcmp ogt double %87, -1.000000e-05
  br i1 %88, label %89, label %94

89:                                               ; preds = %82
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = load i32, ptr %8, align 4, !tbaa !11
  %92 = zext i32 %91 to i64
  %93 = getelementptr inbounds double, ptr %90, i64 %92
  store double 0.000000e+00, ptr %93, align 8, !tbaa !15
  br label %94

94:                                               ; preds = %89, %82, %75
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = load i32, ptr %8, align 4, !tbaa !11
  %97 = zext i32 %96 to i64
  %98 = getelementptr inbounds double, ptr %95, i64 %97
  %99 = load double, ptr %98, align 8, !tbaa !15
  %100 = fcmp oge double %99, 0.000000e+00
  br i1 %100, label %101, label %102

101:                                              ; preds = %94
  br label %103

102:                                              ; preds = %94
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 92, ptr noundef @__PRETTY_FUNCTION__.ZopfliCalculateEntropy) #6
  unreachable

103:                                              ; preds = %101
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %8, align 4, !tbaa !11
  %106 = add i32 %105, 1
  store i32 %106, ptr %8, align 4, !tbaa !11
  br label %42, !llvm.loop !17

107:                                              ; preds = %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void
}

; Function Attrs: nounwind
declare double @log(double noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !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"

@.str.1 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@__PRETTY_FUNCTION__.ZopfliCalculateEntropy = external hidden unnamed_addr constant [62 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @ZopfliCalculateEntropy(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %.thread44, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %min.iters.check = icmp ult i64 %1, 14
  br i1 %min.iters.check, label %.lr.ph.preheader50, label %vector.scevcheck

.lr.ph.preheader50:                               ; preds = %middle.block, %vector.scevcheck, %.lr.ph.preheader
  %.ph = phi i64 [ 0, %vector.scevcheck ], [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %.036.ph = phi i32 [ 0, %vector.scevcheck ], [ 0, %.lr.ph.preheader ], [ %16, %middle.block ]
  %.02935.ph = phi i32 [ 0, %vector.scevcheck ], [ 0, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

vector.scevcheck:                                 ; preds = %.lr.ph.preheader
  %4 = add i64 %1, -1
  %5 = and i64 %4, 4294967295
  %6 = icmp eq i64 %5, 4294967295
  %7 = icmp ugt i64 %4, 4294967295
  %8 = or i1 %6, %7
  br i1 %8, label %.lr.ph.preheader50, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %1, 8589934588
  %ind.end = trunc i64 %n.vec to i32
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i32> [ zeroinitializer, %vector.ph ], [ %13, %vector.body ]
  %vec.phi48 = phi <2 x i32> [ zeroinitializer, %vector.ph ], [ %14, %vector.body ]
  %9 = getelementptr inbounds i64, ptr %0, i64 %index
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  %wide.load = load <2 x i64>, ptr %9, align 8, !tbaa !5
  %wide.load49 = load <2 x i64>, ptr %10, align 8, !tbaa !5
  %11 = trunc <2 x i64> %wide.load to <2 x i32>
  %12 = trunc <2 x i64> %wide.load49 to <2 x i32>
  %13 = add <2 x i32> %vec.phi, %11
  %14 = add <2 x i32> %vec.phi48, %12
  %index.next = add nuw i64 %index, 4
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i32> %14, %13
  %16 = tail call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %1
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader50

.thread44:                                        ; preds = %3
  %17 = uitofp nneg i64 %1 to double
  %18 = tail call double @log(double noundef %17) #5
  br label %._crit_edge40

.lr.ph:                                           ; preds = %.lr.ph.preheader50, %.lr.ph
  %19 = phi i64 [ %25, %.lr.ph ], [ %.ph, %.lr.ph.preheader50 ]
  %.036 = phi i32 [ %23, %.lr.ph ], [ %.036.ph, %.lr.ph.preheader50 ]
  %.02935 = phi i32 [ %24, %.lr.ph ], [ %.02935.ph, %.lr.ph.preheader50 ]
  %20 = getelementptr inbounds i64, ptr %0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = trunc i64 %21 to i32
  %23 = add i32 %.036, %22
  %24 = add i32 %.02935, 1
  %25 = zext i32 %24 to i64
  %26 = icmp ult i64 %25, %1
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %middle.block
  %.lcssa = phi i32 [ %16, %middle.block ], [ %23, %.lr.ph ]
  %27 = icmp eq i32 %.lcssa, 0
  %28 = uitofp nneg i64 %1 to double
  %29 = uitofp i32 %.lcssa to double
  %.sink46 = select i1 %27, double %28, double %29
  %30 = tail call double @log(double noundef %.sink46) #5
  %31 = fmul double %30, 0x3FF71547652B81E1
  br label %.lr.ph39

.lr.ph39:                                         ; preds = %._crit_edge, %48
  %32 = phi i64 [ %50, %48 ], [ 0, %._crit_edge ]
  %.137 = phi i32 [ %49, %48 ], [ 0, %._crit_edge ]
  %33 = getelementptr inbounds i64, ptr %0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = icmp eq i64 %34, 0
  br i1 %35, label %41, label %36

36:                                               ; preds = %.lr.ph39
  %37 = uitofp i64 %34 to double
  %38 = tail call double @log(double noundef %37) #5
  %39 = fneg double %38
  %40 = tail call double @llvm.fmuladd.f64(double %39, double 0x3FF71547652B81E1, double %31)
  br label %41

41:                                               ; preds = %.lr.ph39, %36
  %.sink = phi double [ %40, %36 ], [ %31, %.lr.ph39 ]
  %42 = getelementptr inbounds double, ptr %2, i64 %32
  store double %.sink, ptr %42, align 8
  %43 = fcmp olt double %.sink, 0.000000e+00
  %44 = fcmp ogt double %.sink, -1.000000e-05
  %or.cond = and i1 %43, %44
  br i1 %or.cond, label %.thread, label %45

.thread:                                          ; preds = %41
  store double 0.000000e+00, ptr %42, align 8, !tbaa !14
  br label %48

45:                                               ; preds = %41
  %46 = fcmp ult double %.sink, 0.000000e+00
  br i1 %46, label %47, label %48

47:                                               ; preds = %45
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 92, ptr noundef nonnull @__PRETTY_FUNCTION__.ZopfliCalculateEntropy) #6
  unreachable

48:                                               ; preds = %.thread, %45
  %49 = add i32 %.137, 1
  %50 = zext i32 %49 to i64
  %51 = icmp ult i64 %50, %1
  br i1 %51, label %.lr.ph39, label %._crit_edge40, !llvm.loop !16

._crit_edge40:                                    ; preds = %48, %.thread44
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v2i32(<2 x i32>) #4

attributes #0 = { 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 #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 = { mustprogress nofree nounwind willreturn memory(write) "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long", !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}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass