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

%struct.ZopfliLZ77Store = type { ptr, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local double @ZopfliCalculateBlockSizeAutoType(ptr noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = call double @ZopfliCalculateBlockSize(ptr noundef %10, i64 noundef %11, i64 noundef %12, i32 noundef 0)
  store double %13, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ZopfliLZ77Store, ptr %14, i32 0, i32 2
  %16 = load i64, ptr %15, align 8, !tbaa !13
  %17 = icmp ugt i64 %16, 1000
  br i1 %17, label %18, label %20

18:                                               ; preds = %3
  %19 = load double, ptr %7, align 8, !tbaa !11
  br label %25

20:                                               ; preds = %3
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = call double @ZopfliCalculateBlockSize(ptr noundef %21, i64 noundef %22, i64 noundef %23, i32 noundef 1)
  br label %25

25:                                               ; preds = %20, %18
  %26 = phi double [ %19, %18 ], [ %24, %20 ]
  store double %26, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = call double @ZopfliCalculateBlockSize(ptr noundef %27, i64 noundef %28, i64 noundef %29, i32 noundef 2)
  store double %30, ptr %9, align 8, !tbaa !11
  %31 = load double, ptr %7, align 8, !tbaa !11
  %32 = load double, ptr %8, align 8, !tbaa !11
  %33 = fcmp olt double %31, %32
  br i1 %33, label %34, label %40

34:                                               ; preds = %25
  %35 = load double, ptr %7, align 8, !tbaa !11
  %36 = load double, ptr %9, align 8, !tbaa !11
  %37 = fcmp olt double %35, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %34
  %39 = load double, ptr %7, align 8, !tbaa !11
  br label %50

40:                                               ; preds = %34, %25
  %41 = load double, ptr %8, align 8, !tbaa !11
  %42 = load double, ptr %9, align 8, !tbaa !11
  %43 = fcmp olt double %41, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %40
  %45 = load double, ptr %8, align 8, !tbaa !11
  br label %48

46:                                               ; preds = %40
  %47 = load double, ptr %9, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %46, %44
  %49 = phi double [ %45, %44 ], [ %47, %46 ]
  br label %50

50:                                               ; preds = %48, %38
  %51 = phi double [ %39, %38 ], [ %49, %48 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret double %51
}

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 = !{!"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 = !{!"double", !7, i64 0}
!13 = !{!14, !10, i64 16}
!14 = !{!"ZopfliLZ77Store", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}


; 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 @ZopfliCalculateBlockSize(ptr noundef, i64 noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local double @ZopfliCalculateBlockSizeAutoType(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call double @ZopfliCalculateBlockSize(ptr noundef %0, i64 noundef %1, i64 noundef %2, i32 noundef 0)
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp ugt i64 %6, 1000
  br i1 %7, label %10, label %8

8:                                                ; preds = %3
  %9 = tail call double @ZopfliCalculateBlockSize(ptr noundef nonnull %0, i64 noundef %1, i64 noundef %2, i32 noundef 1)
  br label %10

10:                                               ; preds = %3, %8
  %11 = phi double [ %9, %8 ], [ %4, %3 ]
  %12 = tail call double @ZopfliCalculateBlockSize(ptr noundef nonnull %0, i64 noundef %1, i64 noundef %2, i32 noundef 2)
  %13 = fcmp olt double %4, %11
  %14 = fcmp olt double %4, %12
  %or.cond = select i1 %13, i1 %14, i1 false
  %15 = fcmp olt double %11, %12
  %16 = select i1 %15, double %11, double %12
  %17 = select i1 %or.cond, double %4, double %16
  ret double %17
}

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, !10, i64 16}
!6 = !{!"ZopfliLZ77Store", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass