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

; 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
define dso_local double @ZopfliCalculateBlockSize(ptr noundef %0, i64 noundef %1, i64 noundef %2, i32 noundef %3) #1 {
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca [288 x i32], align 16
  %11 = alloca [32 x i32], align 16
  %12 = alloca double, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1152, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 128, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store double 3.000000e+00, ptr %12, align 8, !tbaa !13
  %17 = load i32, ptr %9, align 4, !tbaa !11
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %41

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = call i64 @ZopfliLZ77GetByteRange(ptr noundef %20, i64 noundef %21, i64 noundef %22)
  store i64 %23, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %24 = load i64, ptr %13, align 8, !tbaa !9
  %25 = urem i64 %24, 65535
  store i64 %25, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %26 = load i64, ptr %13, align 8, !tbaa !9
  %27 = udiv i64 %26, 65535
  %28 = load i64, ptr %14, align 8, !tbaa !9
  %29 = icmp ne i64 %28, 0
  %30 = zext i1 %29 to i64
  %31 = select i1 %29, i32 1, i32 0
  %32 = sext i32 %31 to i64
  %33 = add i64 %27, %32
  store i64 %33, ptr %15, align 8, !tbaa !9
  %34 = load i64, ptr %15, align 8, !tbaa !9
  %35 = mul i64 %34, 5
  %36 = mul i64 %35, 8
  %37 = load i64, ptr %13, align 8, !tbaa !9
  %38 = mul i64 %37, 8
  %39 = add i64 %36, %38
  %40 = uitofp i64 %39 to double
  store double %40, ptr %5, align 8
  store i32 1, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %67

41:                                               ; preds = %4
  %42 = load i32, ptr %9, align 4, !tbaa !11
  %43 = icmp eq i32 %42, 1
  br i1 %43, label %44, label %56

44:                                               ; preds = %41
  %45 = getelementptr inbounds [288 x i32], ptr %10, i64 0, i64 0
  %46 = getelementptr inbounds [32 x i32], ptr %11, i64 0, i64 0
  call void @GetFixedTree(ptr noundef %45, ptr noundef %46)
  %47 = getelementptr inbounds [288 x i32], ptr %10, i64 0, i64 0
  %48 = getelementptr inbounds [32 x i32], ptr %11, i64 0, i64 0
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load i64, ptr %7, align 8, !tbaa !9
  %51 = load i64, ptr %8, align 8, !tbaa !9
  %52 = call i64 @CalculateBlockSymbolSize(ptr noundef %47, ptr noundef %48, ptr noundef %49, i64 noundef %50, i64 noundef %51)
  %53 = uitofp i64 %52 to double
  %54 = load double, ptr %12, align 8, !tbaa !13
  %55 = fadd double %54, %53
  store double %55, ptr %12, align 8, !tbaa !13
  br label %65

56:                                               ; preds = %41
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load i64, ptr %7, align 8, !tbaa !9
  %59 = load i64, ptr %8, align 8, !tbaa !9
  %60 = getelementptr inbounds [288 x i32], ptr %10, i64 0, i64 0
  %61 = getelementptr inbounds [32 x i32], ptr %11, i64 0, i64 0
  %62 = call double @GetDynamicLengths(ptr noundef %57, i64 noundef %58, i64 noundef %59, ptr noundef %60, ptr noundef %61)
  %63 = load double, ptr %12, align 8, !tbaa !13
  %64 = fadd double %63, %62
  store double %64, ptr %12, align 8, !tbaa !13
  br label %65

65:                                               ; preds = %56, %44
  %66 = load double, ptr %12, align 8, !tbaa !13
  store double %66, ptr %5, align 8
  store i32 1, ptr %16, align 4
  br label %67

67:                                               ; preds = %65, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 128, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1152, ptr %10) #3
  %68 = load double, ptr %5, align 8
  ret double %68
}

declare i64 @ZopfliLZ77GetByteRange(ptr noundef, i64 noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @GetFixedTree(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i64 @CalculateBlockSymbolSize(ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden double @GetDynamicLengths(ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) #1

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 = { "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 = !{!"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 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 double @ZopfliCalculateBlockSize(ptr noundef %0, i64 noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca [288 x i32], align 16
  %6 = alloca [32 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 1152, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %6) #3
  switch i32 %3, label %20 [
    i32 0, label %7
    i32 1, label %17
  ]

7:                                                ; preds = %4
  %8 = tail call i64 @ZopfliLZ77GetByteRange(ptr noundef %0, i64 noundef %1, i64 noundef %2) #3
  %9 = urem i64 %8, 65535
  %10 = udiv i64 %8, 65535
  %.not = icmp ne i64 %9, 0
  %11 = zext i1 %.not to i64
  %12 = add nuw nsw i64 %10, %11
  %13 = mul nuw nsw i64 %12, 40
  %14 = shl i64 %8, 3
  %15 = add i64 %13, %14
  %16 = uitofp i64 %15 to double
  br label %23

17:                                               ; preds = %4
  call void @GetFixedTree(ptr noundef nonnull %5, ptr noundef nonnull %6)
  %18 = call i64 @CalculateBlockSymbolSize(ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef %0, i64 noundef %1, i64 noundef %2)
  %19 = uitofp i64 %18 to double
  br label %22

20:                                               ; preds = %4
  %21 = call double @GetDynamicLengths(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef nonnull %5, ptr noundef nonnull %6)
  br label %22

22:                                               ; preds = %20, %17
  %.019.in = phi double [ %19, %17 ], [ %21, %20 ]
  %.019 = fadd double %.019.in, 3.000000e+00
  br label %23

23:                                               ; preds = %22, %7
  %.0 = phi double [ %16, %7 ], [ %.019, %22 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 1152, ptr nonnull %5) #3
  ret double %.0
}

declare i64 @ZopfliLZ77GetByteRange(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @GetFixedTree(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i64 @CalculateBlockSymbolSize(ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden double @GetDynamicLengths(ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { "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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass