; LLVM IR from fhanau/Efficient-Compression-Tool :: src/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: mustprogress uwtable
declare dso_local i64 @CalculateTreeSize(ptr noundef, ptr noundef, i8 noundef zeroext, ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local double @ZopfliCalculateBlockSize(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i32 noundef %4, i8 noundef zeroext %5, i8 noundef zeroext %6) #0 {
  %8 = alloca double, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i8, align 1
  %15 = alloca i8, align 1
  %16 = alloca double, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca [288 x i32], align 16
  %20 = alloca [32 x i32], align 16
  %21 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i64 %2, ptr %11, align 8, !tbaa !9
  store i64 %3, ptr %12, align 8, !tbaa !9
  store i32 %4, ptr %13, align 4, !tbaa !11
  store i8 %5, ptr %14, align 1, !tbaa !13
  store i8 %6, ptr %15, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store double 3.000000e+00, ptr %16, align 8, !tbaa !14
  %22 = load i32, ptr %13, align 4, !tbaa !11
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %93

24:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %25 = load double, ptr %16, align 8, !tbaa !14
  %26 = fadd double %25, 7.000000e+00
  store double %26, ptr %16, align 8, !tbaa !14
  %27 = load i64, ptr %12, align 8, !tbaa !9
  %28 = load i64, ptr %11, align 8, !tbaa !9
  %29 = sub i64 %27, %28
  %30 = mul i64 8, %29
  %31 = uitofp i64 %30 to double
  %32 = load double, ptr %16, align 8, !tbaa !14
  %33 = fadd double %32, %31
  store double %33, ptr %16, align 8, !tbaa !14
  %34 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %34, ptr %17, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %88, %24
  %36 = load i64, ptr %17, align 8, !tbaa !9
  %37 = load i64, ptr %12, align 8, !tbaa !9
  %38 = icmp ult i64 %36, %37
  br i1 %38, label %39, label %91

39:                                               ; preds = %35
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = load i64, ptr %17, align 8, !tbaa !9
  %42 = getelementptr inbounds i16, ptr %40, i64 %41
  %43 = load i16, ptr %42, align 2, !tbaa !16
  %44 = zext i16 %43 to i32
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %57

46:                                               ; preds = %39
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i64, ptr %17, align 8, !tbaa !9
  %49 = getelementptr inbounds i16, ptr %47, i64 %48
  %50 = load i16, ptr %49, align 2, !tbaa !16
  %51 = zext i16 %50 to i32
  %52 = icmp sge i32 %51, 144
  %53 = zext i1 %52 to i32
  %54 = sitofp i32 %53 to double
  %55 = load double, ptr %16, align 8, !tbaa !14
  %56 = fadd double %55, %54
  store double %56, ptr %16, align 8, !tbaa !14
  br label %87

57:                                               ; preds = %39
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load i64, ptr %17, align 8, !tbaa !9
  %60 = getelementptr inbounds i16, ptr %58, i64 %59
  %61 = load i16, ptr %60, align 2, !tbaa !16
  %62 = zext i16 %61 to i32
  %63 = icmp slt i32 %62, 115
  %64 = zext i1 %63 to i32
  %65 = sub nsw i32 5, %64
  %66 = sitofp i32 %65 to double
  %67 = load double, ptr %16, align 8, !tbaa !14
  %68 = fadd double %67, %66
  store double %68, ptr %16, align 8, !tbaa !14
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = load i64, ptr %17, align 8, !tbaa !9
  %71 = getelementptr inbounds i16, ptr %69, i64 %70
  %72 = load i16, ptr %71, align 2, !tbaa !16
  %73 = zext i16 %72 to i32
  %74 = call i32 @ZopfliGetLengthExtraBits(i32 noundef %73)
  %75 = uitofp i32 %74 to double
  %76 = load double, ptr %16, align 8, !tbaa !14
  %77 = fadd double %76, %75
  store double %77, ptr %16, align 8, !tbaa !14
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = load i64, ptr %17, align 8, !tbaa !9
  %80 = getelementptr inbounds i16, ptr %78, i64 %79
  %81 = load i16, ptr %80, align 2, !tbaa !16
  %82 = zext i16 %81 to i32
  %83 = call i32 @ZopfliGetDistExtraBits(i32 noundef %82)
  %84 = uitofp i32 %83 to double
  %85 = load double, ptr %16, align 8, !tbaa !14
  %86 = fadd double %85, %84
  store double %86, ptr %16, align 8, !tbaa !14
  br label %87

87:                                               ; preds = %57, %46
  br label %88

88:                                               ; preds = %87
  %89 = load i64, ptr %17, align 8, !tbaa !9
  %90 = add i64 %89, 1
  store i64 %90, ptr %17, align 8, !tbaa !9
  br label %35, !llvm.loop !18

91:                                               ; preds = %35
  %92 = load double, ptr %16, align 8, !tbaa !14
  store double %92, ptr %8, align 8
  store i32 1, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %113

93:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 1152, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 128, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  %95 = load ptr, ptr %10, align 8, !tbaa !5
  %96 = load i64, ptr %11, align 8, !tbaa !9
  %97 = load i64, ptr %12, align 8, !tbaa !9
  %98 = getelementptr inbounds [288 x i32], ptr %19, i64 0, i64 0
  %99 = getelementptr inbounds [32 x i32], ptr %20, i64 0, i64 0
  %100 = load i8, ptr %15, align 1, !tbaa !13
  %101 = call noundef i64 @_ZL17GetDynamicLengthsPKtS0_mmPjS1_h(ptr noundef %94, ptr noundef %95, i64 noundef %96, i64 noundef %97, ptr noundef %98, ptr noundef %99, i8 noundef zeroext %100)
  %102 = uitofp i64 %101 to double
  %103 = load double, ptr %16, align 8, !tbaa !14
  %104 = fadd double %103, %102
  store double %104, ptr %16, align 8, !tbaa !14
  %105 = getelementptr inbounds [288 x i32], ptr %19, i64 0, i64 0
  %106 = getelementptr inbounds [32 x i32], ptr %20, i64 0, i64 0
  %107 = load i8, ptr %14, align 1, !tbaa !13
  %108 = call i64 @CalculateTreeSize(ptr noundef %105, ptr noundef %106, i8 noundef zeroext %107, ptr noundef %21)
  %109 = uitofp i64 %108 to double
  %110 = load double, ptr %16, align 8, !tbaa !14
  %111 = fadd double %110, %109
  store double %111, ptr %16, align 8, !tbaa !14
  %112 = load double, ptr %16, align 8, !tbaa !14
  store double %112, ptr %8, align 8
  store i32 1, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 128, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 1152, ptr %19) #3
  br label %113

113:                                              ; preds = %93, %91
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  %114 = load double, ptr %8, align 8
  ret double %114
}

declare i32 @ZopfliGetLengthExtraBits(i32 noundef) #2

declare i32 @ZopfliGetDistExtraBits(i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden noundef i64 @_ZL17GetDynamicLengthsPKtS0_mmPjS1_h(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef, i8 noundef zeroext) #0

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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 uwtable
declare dso_local i64 @CalculateTreeSize(ptr noundef, ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local double @ZopfliCalculateBlockSize(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i32 noundef %4, i8 noundef zeroext %5, i8 noundef zeroext %6) local_unnamed_addr #0 {
  %8 = alloca [288 x i32], align 16
  %9 = alloca [32 x i32], align 16
  %10 = alloca i32, align 4
  %11 = icmp eq i32 %4, 1
  br i1 %11, label %12, label %42

12:                                               ; preds = %7
  %13 = sub i64 %3, %2
  %14 = shl i64 %13, 3
  %15 = uitofp i64 %14 to double
  %16 = fadd double %15, 1.000000e+01
  %17 = icmp ult i64 %2, %3
  br i1 %17, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %12, %40
  %.036 = phi i64 [ %41, %40 ], [ %2, %12 ]
  %.03335 = phi double [ %.1, %40 ], [ %16, %12 ]
  %18 = getelementptr inbounds i16, ptr %1, i64 %.036
  %19 = load i16, ptr %18, align 2, !tbaa !5
  %20 = icmp eq i16 %19, 0
  %21 = getelementptr inbounds i16, ptr %0, i64 %.036
  %22 = load i16, ptr %21, align 2, !tbaa !5
  br i1 %20, label %23, label %27

23:                                               ; preds = %.lr.ph
  %24 = icmp ugt i16 %22, 143
  %25 = uitofp i1 %24 to double
  %26 = fadd double %.03335, %25
  br label %40

27:                                               ; preds = %.lr.ph
  %28 = zext i16 %22 to i32
  %29 = icmp ult i16 %22, 115
  %30 = select i1 %29, double 4.000000e+00, double 5.000000e+00
  %31 = fadd double %.03335, %30
  %32 = tail call i32 @ZopfliGetLengthExtraBits(i32 noundef %28)
  %33 = uitofp i32 %32 to double
  %34 = fadd double %31, %33
  %35 = load i16, ptr %18, align 2, !tbaa !5
  %36 = zext i16 %35 to i32
  %37 = tail call i32 @ZopfliGetDistExtraBits(i32 noundef %36)
  %38 = uitofp i32 %37 to double
  %39 = fadd double %34, %38
  br label %40

40:                                               ; preds = %23, %27
  %.1 = phi double [ %26, %23 ], [ %39, %27 ]
  %41 = add i64 %.036, 1
  %exitcond.not = icmp eq i64 %41, %3
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !9

42:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 1152, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #3
  %43 = call noundef i64 @_ZL17GetDynamicLengthsPKtS0_mmPjS1_h(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef nonnull %8, ptr noundef nonnull %9, i8 noundef zeroext %6)
  %44 = uitofp i64 %43 to double
  %45 = fadd double %44, 3.000000e+00
  %46 = call i64 @CalculateTreeSize(ptr noundef nonnull %8, ptr noundef nonnull %9, i8 noundef zeroext %5, ptr noundef nonnull %10)
  %47 = uitofp i64 %46 to double
  %48 = fadd double %45, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 1152, ptr nonnull %8) #3
  br label %.loopexit

.loopexit:                                        ; preds = %40, %12, %42
  %.034 = phi double [ %48, %42 ], [ %16, %12 ], [ %.1, %40 ]
  ret double %.034
}

declare i32 @ZopfliGetLengthExtraBits(i32 noundef) local_unnamed_addr #2

declare i32 @ZopfliGetDistExtraBits(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare hidden noundef i64 @_ZL17GetDynamicLengthsPKtS0_mmPjS1_h(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

attributes #0 = { mustprogress 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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