; LLVM IR from indygreg/python-zstandard :: zstd (zstd)

; 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: nounwind uwtable
declare hidden i32 @ERR_isError(i64 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: nounwind uwtable
declare dso_local i32 @FSE_optimalTableLog_internal(i32 noundef, i64 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @HUF_writeCTable_wksp(ptr noundef, i64 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @HUF_buildCTable_wksp(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @HUF_estimateCompressedSize(ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @HUF_cardinality(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @HUF_minTableLog(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @HUF_optimalTableLog(i32 noundef %0, i64 noundef %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6, i32 noundef %7) #0 {
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca i64, align 8
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i64, align 8
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  %27 = alloca i64, align 8
  %28 = alloca i32, align 4
  store i32 %0, ptr %10, align 4, !tbaa !5
  store i64 %1, ptr %11, align 8, !tbaa !9
  store i32 %2, ptr %12, align 4, !tbaa !5
  store ptr %3, ptr %13, align 8, !tbaa !11
  store i64 %4, ptr %14, align 8, !tbaa !9
  store ptr %5, ptr %15, align 8, !tbaa !11
  store ptr %6, ptr %16, align 8, !tbaa !11
  store i32 %7, ptr %17, align 4, !tbaa !5
  %29 = load i32, ptr %17, align 4, !tbaa !5
  %30 = and i32 %29, 2
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %37, label %32

32:                                               ; preds = %8
  %33 = load i32, ptr %10, align 4, !tbaa !5
  %34 = load i64, ptr %11, align 8, !tbaa !9
  %35 = load i32, ptr %12, align 4, !tbaa !5
  %36 = call i32 @FSE_optimalTableLog_internal(i32 noundef %33, i64 noundef %34, i32 noundef %35, i32 noundef 1)
  store i32 %36, ptr %9, align 4
  br label %123

37:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #2
  %38 = load ptr, ptr %13, align 8, !tbaa !11
  %39 = getelementptr inbounds i8, ptr %38, i64 748
  store ptr %39, ptr %18, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #2
  %40 = load i64, ptr %14, align 8, !tbaa !9
  %41 = sub i64 %40, 748
  store i64 %41, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #2
  %42 = load ptr, ptr %16, align 8, !tbaa !11
  %43 = load i32, ptr %12, align 4, !tbaa !5
  %44 = call i32 @HUF_cardinality(ptr noundef %42, i32 noundef %43)
  store i32 %44, ptr %22, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #2
  %45 = load i32, ptr %22, align 4, !tbaa !5
  %46 = call i32 @HUF_minTableLog(i32 noundef %45)
  store i32 %46, ptr %23, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #2
  store i64 -2, ptr %24, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #2
  %47 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %47, ptr %25, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #2
  br label %48

48:                                               ; preds = %37
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %23, align 4, !tbaa !5
  store i32 %51, ptr %26, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %118, %50
  %53 = load i32, ptr %26, align 4, !tbaa !5
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = icmp ule i32 %53, %54
  br i1 %55, label %56, label %121

56:                                               ; preds = %52
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #2
  %60 = load ptr, ptr %15, align 8, !tbaa !11
  %61 = load ptr, ptr %16, align 8, !tbaa !11
  %62 = load i32, ptr %12, align 4, !tbaa !5
  %63 = load i32, ptr %26, align 4, !tbaa !5
  %64 = load ptr, ptr %13, align 8, !tbaa !11
  %65 = load i64, ptr %14, align 8, !tbaa !9
  %66 = call i64 @HUF_buildCTable_wksp(ptr noundef %60, ptr noundef %61, i32 noundef %62, i32 noundef %63, ptr noundef %64, i64 noundef %65)
  store i64 %66, ptr %27, align 8, !tbaa !9
  %67 = load i64, ptr %27, align 8, !tbaa !9
  %68 = call i32 @ERR_isError(i64 noundef %67)
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %71

70:                                               ; preds = %59
  store i32 6, ptr %28, align 4
  br label %91

71:                                               ; preds = %59
  %72 = load i64, ptr %27, align 8, !tbaa !9
  %73 = load i32, ptr %26, align 4, !tbaa !5
  %74 = zext i32 %73 to i64
  %75 = icmp ult i64 %72, %74
  br i1 %75, label %76, label %81

76:                                               ; preds = %71
  %77 = load i32, ptr %26, align 4, !tbaa !5
  %78 = load i32, ptr %23, align 4, !tbaa !5
  %79 = icmp ugt i32 %77, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %76
  store i32 4, ptr %28, align 4
  br label %91

81:                                               ; preds = %76, %71
  %82 = load ptr, ptr %18, align 8, !tbaa !11
  %83 = load i64, ptr %19, align 8, !tbaa !9
  %84 = load ptr, ptr %15, align 8, !tbaa !11
  %85 = load i32, ptr %12, align 4, !tbaa !5
  %86 = load i64, ptr %27, align 8, !tbaa !9
  %87 = trunc i64 %86 to i32
  %88 = load ptr, ptr %13, align 8, !tbaa !11
  %89 = load i64, ptr %14, align 8, !tbaa !9
  %90 = call i64 @HUF_writeCTable_wksp(ptr noundef %82, i64 noundef %83, ptr noundef %84, i32 noundef %85, i32 noundef %87, ptr noundef %88, i64 noundef %89)
  store i64 %90, ptr %20, align 8, !tbaa !9
  store i32 0, ptr %28, align 4
  br label %91

91:                                               ; preds = %81, %80, %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #2
  %92 = load i32, ptr %28, align 4
  switch i32 %92, label %125 [
    i32 0, label %93
    i32 6, label %118
    i32 4, label %121
  ]

93:                                               ; preds = %91
  %94 = load i64, ptr %20, align 8, !tbaa !9
  %95 = call i32 @ERR_isError(i64 noundef %94)
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %98

97:                                               ; preds = %93
  br label %118

98:                                               ; preds = %93
  %99 = load ptr, ptr %15, align 8, !tbaa !11
  %100 = load ptr, ptr %16, align 8, !tbaa !11
  %101 = load i32, ptr %12, align 4, !tbaa !5
  %102 = call i64 @HUF_estimateCompressedSize(ptr noundef %99, ptr noundef %100, i32 noundef %101)
  %103 = load i64, ptr %20, align 8, !tbaa !9
  %104 = add i64 %102, %103
  store i64 %104, ptr %21, align 8, !tbaa !9
  %105 = load i64, ptr %21, align 8, !tbaa !9
  %106 = load i64, ptr %24, align 8, !tbaa !9
  %107 = add i64 %106, 1
  %108 = icmp ugt i64 %105, %107
  br i1 %108, label %109, label %110

109:                                              ; preds = %98
  br label %121

110:                                              ; preds = %98
  %111 = load i64, ptr %21, align 8, !tbaa !9
  %112 = load i64, ptr %24, align 8, !tbaa !9
  %113 = icmp ult i64 %111, %112
  br i1 %113, label %114, label %117

114:                                              ; preds = %110
  %115 = load i64, ptr %21, align 8, !tbaa !9
  store i64 %115, ptr %24, align 8, !tbaa !9
  %116 = load i32, ptr %26, align 4, !tbaa !5
  store i32 %116, ptr %25, align 4, !tbaa !5
  br label %117

117:                                              ; preds = %114, %110
  br label %118

118:                                              ; preds = %117, %97, %91
  %119 = load i32, ptr %26, align 4, !tbaa !5
  %120 = add i32 %119, 1
  store i32 %120, ptr %26, align 4, !tbaa !5
  br label %52, !llvm.loop !13

121:                                              ; preds = %109, %91, %52
  %122 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %122, ptr %9, align 4
  store i32 1, ptr %28, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #2
  br label %123

123:                                              ; preds = %121, %32
  %124 = load i32, ptr %9, align 4
  ret i32 %124

125:                                              ; preds = %91
  unreachable
}

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !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 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: nounwind uwtable
declare hidden i32 @ERR_isError(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @FSE_optimalTableLog_internal(i32 noundef, i64 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @HUF_writeCTable_wksp(ptr noundef, i64 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @HUF_buildCTable_wksp(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @HUF_estimateCompressedSize(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @HUF_cardinality(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @HUF_minTableLog(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @HUF_optimalTableLog(i32 noundef %0, i64 noundef %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6, i32 noundef %7) local_unnamed_addr #0 {
  %9 = and i32 %7, 2
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %12

10:                                               ; preds = %8
  %11 = tail call i32 @FSE_optimalTableLog_internal(i32 noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef 1)
  br label %.loopexit

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %3, i64 748
  %14 = add i64 %4, -748
  %15 = tail call i32 @HUF_cardinality(ptr noundef %6, i32 noundef %2)
  %16 = tail call i32 @HUF_minTableLog(i32 noundef %15)
  %.not5364 = icmp ugt i32 %16, %0
  br i1 %.not5364, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %12, %.thread61
  %.04667 = phi i32 [ %34, %.thread61 ], [ %16, %12 ]
  %.04766 = phi i32 [ %.1, %.thread61 ], [ %0, %12 ]
  %.04865 = phi i64 [ %.149, %.thread61 ], [ -2, %12 ]
  %17 = tail call i64 @HUF_buildCTable_wksp(ptr noundef %5, ptr noundef %6, i32 noundef %2, i32 noundef %.04667, ptr noundef %3, i64 noundef %4)
  %18 = tail call i32 @ERR_isError(i64 noundef %17)
  %.not54 = icmp eq i32 %18, 0
  br i1 %.not54, label %19, label %.thread61

19:                                               ; preds = %.lr.ph
  %20 = zext i32 %.04667 to i64
  %21 = icmp ult i64 %17, %20
  %22 = icmp ugt i32 %.04667, %16
  %or.cond = and i1 %21, %22
  br i1 %or.cond, label %.loopexit, label %23

23:                                               ; preds = %19
  %24 = trunc i64 %17 to i32
  %25 = tail call i64 @HUF_writeCTable_wksp(ptr noundef nonnull %13, i64 noundef %14, ptr noundef %5, i32 noundef %2, i32 noundef %24, ptr noundef %3, i64 noundef %4)
  %26 = tail call i32 @ERR_isError(i64 noundef %25)
  %.not55 = icmp eq i32 %26, 0
  br i1 %.not55, label %27, label %.thread61

27:                                               ; preds = %23
  %28 = tail call i64 @HUF_estimateCompressedSize(ptr noundef %5, ptr noundef %6, i32 noundef %2)
  %29 = add i64 %28, %25
  %30 = add nuw i64 %.04865, 1
  %31 = icmp ugt i64 %29, %30
  br i1 %31, label %.loopexit, label %32

32:                                               ; preds = %27
  %33 = icmp ult i64 %29, %.04865
  %spec.select = tail call i64 @llvm.umin.i64(i64 %29, i64 %.04865)
  %spec.select56 = select i1 %33, i32 %.04667, i32 %.04766
  br label %.thread61

.thread61:                                        ; preds = %.lr.ph, %32, %23
  %.149 = phi i64 [ %.04865, %23 ], [ %spec.select, %32 ], [ %.04865, %.lr.ph ]
  %.1 = phi i32 [ %.04766, %23 ], [ %spec.select56, %32 ], [ %.04766, %.lr.ph ]
  %34 = add i32 %.04667, 1
  %.not53 = icmp ugt i32 %34, %0
  br i1 %.not53, label %.loopexit, label %.lr.ph, !llvm.loop !5

.loopexit:                                        ; preds = %27, %.thread61, %19, %12, %10
  %.045 = phi i32 [ %11, %10 ], [ %0, %12 ], [ %.04766, %27 ], [ %.1, %.thread61 ], [ %.04766, %19 ]
  ret i32 %.045
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #1

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

!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"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass