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

%struct.seqStore_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i32, i32 }
%struct.ZSTD_CCtx_params_s = type { i32, %struct.ZSTD_compressionParameters, %struct.ZSTD_frameParameters, i32, i32, i64, i32, i32, i32, i32, i64, i32, i32, %struct.ldmParams_t, i32, i32, i32, i32, i32, i32, i32, i32, %struct.ZSTD_customMem, i32, i32, ptr, ptr, i64, i32 }
%struct.ZSTD_compressionParameters = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_frameParameters = type { i32, i32, i32 }
%struct.ldmParams_t = type { i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_customMem = type { ptr, ptr, ptr }
%struct.ZSTD_entropyCTables_t = type { %struct.ZSTD_hufCTables_t, %struct.ZSTD_fseCTables_t }
%struct.ZSTD_hufCTables_t = type { [257 x i64], i32 }
%struct.ZSTD_fseCTables_t = type { [193 x i32], [363 x i32], [329 x i32], i32, i32, i32 }
%struct.ZSTD_entropyCTablesMetadata_t = type { %struct.ZSTD_hufCTablesMetadata_t, %struct.ZSTD_fseCTablesMetadata_t }
%struct.ZSTD_hufCTablesMetadata_t = type { i32, [128 x i8], i64 }
%struct.ZSTD_fseCTablesMetadata_t = type { i32, i32, i32, [133 x i8], i64, i64 }

; 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
define dso_local i64 @ZSTD_buildBlockEntropyStats(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6) #0 {
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i64, align 8
  %20 = alloca i32, align 4
  %21 = alloca i64, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i64 %6, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.seqStore_t, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.seqStore_t, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = ptrtoint ptr %24 to i64
  %29 = ptrtoint ptr %27 to i64
  %30 = sub i64 %28, %29
  store i64 %30, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %32, i32 0, i32 6
  %34 = load i32, ptr %33, align 4, !tbaa !15
  %35 = icmp uge i32 %34, 8
  %36 = zext i1 %35 to i32
  store i32 %36, ptr %17, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %37 = load i32, ptr %17, align 4, !tbaa !21
  %38 = icmp ne i32 %37, 0
  %39 = zext i1 %38 to i64
  %40 = select i1 %38, i32 2, i32 0
  store i32 %40, ptr %18, align 4, !tbaa !21
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.seqStore_t, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = load i64, ptr %16, align 8, !tbaa !9
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ZSTD_entropyCTables_t, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ZSTD_entropyCTables_t, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %13, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ZSTD_entropyCTablesMetadata_t, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = call i32 @ZSTD_literalsCompressionIsDisabled(ptr noundef %51)
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  %54 = load i64, ptr %15, align 8, !tbaa !9
  %55 = load i32, ptr %18, align 4, !tbaa !21
  %56 = call i64 @ZSTD_buildBlockEntropyStats_literals(ptr noundef %43, i64 noundef %44, ptr noundef %46, ptr noundef %48, ptr noundef %50, i32 noundef %52, ptr noundef %53, i64 noundef %54, i32 noundef %55)
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ZSTD_entropyCTablesMetadata_t, ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds %struct.ZSTD_hufCTablesMetadata_t, ptr %58, i32 0, i32 2
  store i64 %56, ptr %59, align 8, !tbaa !22
  br label %60

60:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %61 = load ptr, ptr %13, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ZSTD_entropyCTablesMetadata_t, ptr %61, i32 0, i32 0
  %63 = getelementptr inbounds %struct.ZSTD_hufCTablesMetadata_t, ptr %62, i32 0, i32 2
  %64 = load i64, ptr %63, align 8, !tbaa !22
  store i64 %64, ptr %19, align 8, !tbaa !9
  %65 = load i64, ptr %19, align 8, !tbaa !9
  %66 = call i32 @ERR_isError(i64 noundef %65)
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %82

68:                                               ; preds = %60
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  %81 = load i64, ptr %19, align 8, !tbaa !9
  store i64 %81, ptr %8, align 8
  store i32 1, ptr %20, align 4
  br label %83

82:                                               ; preds = %60
  store i32 0, ptr %20, align 4
  br label %83

83:                                               ; preds = %82, %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  %84 = load i32, ptr %20, align 4
  switch i32 %84, label %130 [
    i32 0, label %85
  ]

85:                                               ; preds = %83
  br label %86

86:                                               ; preds = %85
  br label %87

87:                                               ; preds = %86
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.ZSTD_entropyCTables_t, ptr %89, i32 0, i32 1
  %91 = load ptr, ptr %11, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.ZSTD_entropyCTables_t, ptr %91, i32 0, i32 1
  %93 = load ptr, ptr %12, align 8, !tbaa !5
  %94 = load ptr, ptr %13, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.ZSTD_entropyCTablesMetadata_t, ptr %94, i32 0, i32 1
  %96 = load ptr, ptr %14, align 8, !tbaa !5
  %97 = load i64, ptr %15, align 8, !tbaa !9
  %98 = call i64 @ZSTD_buildBlockEntropyStats_sequences(ptr noundef %88, ptr noundef %90, ptr noundef %92, ptr noundef %93, ptr noundef %95, ptr noundef %96, i64 noundef %97)
  %99 = load ptr, ptr %13, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.ZSTD_entropyCTablesMetadata_t, ptr %99, i32 0, i32 1
  %101 = getelementptr inbounds %struct.ZSTD_fseCTablesMetadata_t, ptr %100, i32 0, i32 4
  store i64 %98, ptr %101, align 8, !tbaa !26
  br label %102

102:                                              ; preds = %87
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  %103 = load ptr, ptr %13, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.ZSTD_entropyCTablesMetadata_t, ptr %103, i32 0, i32 1
  %105 = getelementptr inbounds %struct.ZSTD_fseCTablesMetadata_t, ptr %104, i32 0, i32 4
  %106 = load i64, ptr %105, align 8, !tbaa !26
  store i64 %106, ptr %21, align 8, !tbaa !9
  %107 = load i64, ptr %21, align 8, !tbaa !9
  %108 = call i32 @ERR_isError(i64 noundef %107)
  %109 = icmp ne i32 %108, 0
  br i1 %109, label %110, label %124

110:                                              ; preds = %102
  br label %111

111:                                              ; preds = %110
  br label %112

112:                                              ; preds = %111
  br label %113

113:                                              ; preds = %112
  br label %114

114:                                              ; preds = %113
  br label %115

115:                                              ; preds = %114
  br label %116

116:                                              ; preds = %115
  br label %117

117:                                              ; preds = %116
  br label %118

118:                                              ; preds = %117
  br label %119

119:                                              ; preds = %118
  br label %120

120:                                              ; preds = %119
  br label %121

121:                                              ; preds = %120
  br label %122

122:                                              ; preds = %121
  %123 = load i64, ptr %21, align 8, !tbaa !9
  store i64 %123, ptr %8, align 8
  store i32 1, ptr %20, align 4
  br label %125

124:                                              ; preds = %102
  store i32 0, ptr %20, align 4
  br label %125

125:                                              ; preds = %124, %122
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  %126 = load i32, ptr %20, align 4
  switch i32 %126, label %130 [
    i32 0, label %127
  ]

127:                                              ; preds = %125
  br label %128

128:                                              ; preds = %127
  br label %129

129:                                              ; preds = %128
  store i64 0, ptr %8, align 8
  store i32 1, ptr %20, align 4
  br label %130

130:                                              ; preds = %129, %125, %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  %131 = load i64, ptr %8, align 8
  ret i64 %131
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ZSTD_literalsCompressionIsDisabled(ptr noundef) #2

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

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 = { inlinehint 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 }

!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, !6, i64 24}
!12 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 64, !13, i64 72, !13, i64 76}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!16, !13, i64 28}
!16 = !{!"ZSTD_CCtx_params_s", !13, i64 0, !17, i64 4, !18, i64 32, !13, i64 44, !13, i64 48, !10, i64 56, !13, i64 64, !13, i64 68, !13, i64 72, !13, i64 76, !10, i64 80, !13, i64 88, !13, i64 92, !19, i64 96, !13, i64 120, !13, i64 124, !13, i64 128, !13, i64 132, !13, i64 136, !13, i64 140, !13, i64 144, !13, i64 148, !20, i64 152, !13, i64 176, !13, i64 180, !6, i64 184, !6, i64 192, !10, i64 200, !13, i64 208}
!17 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24}
!18 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8}
!19 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!20 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!13, !13, i64 0}
!22 = !{!23, !10, i64 136}
!23 = !{!"", !24, i64 0, !25, i64 144}
!24 = !{!"", !13, i64 0, !7, i64 4, !10, i64 136}
!25 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !7, i64 12, !10, i64 152, !10, i64 160}
!26 = !{!23, !10, i64 296}


; 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
define dso_local i64 @ZSTD_buildBlockEntropyStats(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6) local_unnamed_addr #0 {
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = ptrtoint ptr %9 to i64
  %13 = ptrtoint ptr %11 to i64
  %14 = sub i64 %12, %13
  %15 = getelementptr inbounds i8, ptr %3, i64 28
  %16 = load i32, ptr %15, align 4, !tbaa !13
  %17 = icmp ugt i32 %16, 7
  %18 = select i1 %17, i32 2, i32 0
  %19 = tail call i32 @ZSTD_literalsCompressionIsDisabled(ptr noundef %3)
  %20 = tail call i64 @ZSTD_buildBlockEntropyStats_literals(ptr noundef %11, i64 noundef %14, ptr noundef %1, ptr noundef %2, ptr noundef %4, i32 noundef %19, ptr noundef %5, i64 noundef %6, i32 noundef %18)
  %21 = getelementptr inbounds i8, ptr %4, i64 136
  store i64 %20, ptr %21, align 8, !tbaa !19
  %22 = tail call i32 @ERR_isError(i64 noundef %20)
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %23, label %30

23:                                               ; preds = %7
  %24 = getelementptr inbounds i8, ptr %1, i64 2064
  %25 = getelementptr inbounds i8, ptr %2, i64 2064
  %26 = getelementptr inbounds i8, ptr %4, i64 144
  %27 = tail call i64 @ZSTD_buildBlockEntropyStats_sequences(ptr noundef nonnull %0, ptr noundef nonnull %24, ptr noundef nonnull %25, ptr noundef nonnull %3, ptr noundef nonnull %26, ptr noundef %5, i64 noundef %6)
  %28 = getelementptr inbounds i8, ptr %4, i64 296
  store i64 %27, ptr %28, align 8, !tbaa !23
  %29 = tail call i32 @ERR_isError(i64 noundef %27)
  %.not33 = icmp eq i32 %29, 0
  %spec.select = select i1 %.not33, i64 0, i64 %27
  br label %30

30:                                               ; preds = %23, %7
  %.2 = phi i64 [ %20, %7 ], [ %spec.select, %23 ]
  ret i64 %.2
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ZSTD_literalsCompressionIsDisabled(ptr noundef) local_unnamed_addr #1

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

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 = { inlinehint 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, !7, i64 24}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !10, i64 64, !11, i64 72, !11, i64 76}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 16}
!13 = !{!14, !11, i64 28}
!14 = !{!"ZSTD_CCtx_params_s", !11, i64 0, !15, i64 4, !16, i64 32, !11, i64 44, !11, i64 48, !10, i64 56, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !10, i64 80, !11, i64 88, !11, i64 92, !17, i64 96, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !11, i64 148, !18, i64 152, !11, i64 176, !11, i64 180, !7, i64 184, !7, i64 192, !10, i64 200, !11, i64 208}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!16 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!17 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!18 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!19 = !{!20, !10, i64 136}
!20 = !{!"", !21, i64 0, !22, i64 144}
!21 = !{!"", !11, i64 0, !8, i64 4, !10, i64 136}
!22 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !8, i64 12, !10, i64 152, !10, i64 160}
!23 = !{!20, !10, i64 296}


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