; LLVM IR from ybubnov/libhuffman :: src (encoder)

; 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.__huf_encoder = type { ptr, %struct.__huf_bit_read_writer, ptr, ptr, ptr, ptr, ptr }
%struct.__huf_bit_read_writer = type { i8, i8 }
%struct.__huf_encoder_config = type { i64, i64, i64, i64, ptr, ptr }

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

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

declare i32 @huf_malloc(ptr noundef, i64 noundef, i64 noundef) #2

; 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 @huf_encoder_free(ptr noundef) #0

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @huf_encode(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [1024 x i16], align 16
  %9 = alloca i16, align 2
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2048, ptr %8) #5
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 2048, i1 false)
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #5
  store i16 0, ptr %9, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !13
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call i32 @huf_encoder_init(ptr noundef %6, ptr noundef %14)
  store i32 %15, ptr %5, align 4, !tbaa !9
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %1
  br label %19

19:                                               ; preds = %18
  %20 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %20, ptr %4, align 4, !tbaa !9
  br label %235

21:                                               ; No predecessors!
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22, %1
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.__huf_encoder, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = getelementptr inbounds %struct.__huf_encoder_config, ptr %26, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !18
  %29 = call i32 @huf_malloc(ptr noundef %7, i64 noundef 1, i64 noundef %28)
  store i32 %29, ptr %5, align 4, !tbaa !9
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %37

32:                                               ; preds = %23
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %34, ptr %4, align 4, !tbaa !9
  br label %235

35:                                               ; No predecessors!
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36, %23
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.__huf_encoder, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = getelementptr inbounds %struct.__huf_encoder_config, ptr %40, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !20
  store i64 %42, ptr %11, align 8, !tbaa !13
  br label %43

43:                                               ; preds = %221, %184, %37
  %44 = load i64, ptr %11, align 8, !tbaa !13
  %45 = icmp ugt i64 %44, 0
  br i1 %45, label %46, label %222

46:                                               ; preds = %43
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.__huf_encoder, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = getelementptr inbounds %struct.__huf_encoder_config, ptr %49, i32 0, i32 1
  %51 = load i64, ptr %50, align 8, !tbaa !18
  store i64 %51, ptr %12, align 8, !tbaa !13
  %52 = load i64, ptr %11, align 8, !tbaa !13
  %53 = load i64, ptr %12, align 8, !tbaa !13
  %54 = icmp ult i64 %52, %53
  br i1 %54, label %55, label %57

55:                                               ; preds = %46
  %56 = load i64, ptr %11, align 8, !tbaa !13
  store i64 %56, ptr %12, align 8, !tbaa !13
  br label %57

57:                                               ; preds = %55, %46
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.__huf_encoder, ptr %58, i32 0, i32 6
  %60 = load ptr, ptr %59, align 8, !tbaa !21
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load i64, ptr %12, align 8, !tbaa !13
  %63 = call i32 @huf_bufio_read(ptr noundef %60, ptr noundef %61, i64 noundef %62)
  store i32 %63, ptr %5, align 4, !tbaa !9
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %71

66:                                               ; preds = %57
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %68, ptr %4, align 4, !tbaa !9
  br label %235

69:                                               ; No predecessors!
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70, %57
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.__huf_encoder, ptr %72, i32 0, i32 4
  %74 = load ptr, ptr %73, align 8, !tbaa !22
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = load i64, ptr %12, align 8, !tbaa !13
  %77 = call i32 @huf_histogram_populate(ptr noundef %74, ptr noundef %75, i64 noundef %76)
  store i32 %77, ptr %5, align 4, !tbaa !9
  %78 = load i32, ptr %5, align 4, !tbaa !9
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %80, label %85

80:                                               ; preds = %71
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %82, ptr %4, align 4, !tbaa !9
  br label %235

83:                                               ; No predecessors!
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84, %71
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.__huf_encoder, ptr %86, i32 0, i32 2
  %88 = load ptr, ptr %87, align 8, !tbaa !23
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.__huf_encoder, ptr %89, i32 0, i32 4
  %91 = load ptr, ptr %90, align 8, !tbaa !22
  %92 = call i32 @huf_tree_from_histogram(ptr noundef %88, ptr noundef %91)
  store i32 %92, ptr %5, align 4, !tbaa !9
  %93 = load i32, ptr %5, align 4, !tbaa !9
  %94 = icmp ne i32 %93, 0
  br i1 %94, label %95, label %100

95:                                               ; preds = %85
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %97, ptr %4, align 4, !tbaa !9
  br label %235

98:                                               ; No predecessors!
  br label %99

99:                                               ; preds = %98
  br label %100

100:                                              ; preds = %99, %85
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = call i32 @__huf_create_char_coding(ptr noundef %101)
  store i32 %102, ptr %5, align 4, !tbaa !9
  %103 = load i32, ptr %5, align 4, !tbaa !9
  %104 = icmp ne i32 %103, 0
  br i1 %104, label %105, label %110

105:                                              ; preds = %100
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %107, ptr %4, align 4, !tbaa !9
  br label %235

108:                                              ; No predecessors!
  br label %109

109:                                              ; preds = %108
  br label %110

110:                                              ; preds = %109, %100
  %111 = load ptr, ptr %6, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.__huf_encoder, ptr %111, i32 0, i32 2
  %113 = load ptr, ptr %112, align 8, !tbaa !23
  %114 = getelementptr inbounds [1024 x i16], ptr %8, i64 0, i64 0
  %115 = call i32 @huf_tree_serialize(ptr noundef %113, ptr noundef %114, ptr noundef %10)
  store i32 %115, ptr %5, align 4, !tbaa !9
  %116 = load i32, ptr %5, align 4, !tbaa !9
  %117 = icmp ne i32 %116, 0
  br i1 %117, label %118, label %123

118:                                              ; preds = %110
  br label %119

119:                                              ; preds = %118
  %120 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %120, ptr %4, align 4, !tbaa !9
  br label %235

121:                                              ; No predecessors!
  br label %122

122:                                              ; preds = %121
  br label %123

123:                                              ; preds = %122, %110
  %124 = load i64, ptr %10, align 8, !tbaa !13
  %125 = trunc i64 %124 to i16
  store i16 %125, ptr %9, align 2, !tbaa !11
  %126 = load ptr, ptr %6, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.__huf_encoder, ptr %126, i32 0, i32 5
  %128 = load ptr, ptr %127, align 8, !tbaa !24
  %129 = call i32 @huf_bufio_write(ptr noundef %128, ptr noundef %12, i64 noundef 8)
  store i32 %129, ptr %5, align 4, !tbaa !9
  %130 = load i32, ptr %5, align 4, !tbaa !9
  %131 = icmp ne i32 %130, 0
  br i1 %131, label %132, label %137

132:                                              ; preds = %123
  br label %133

133:                                              ; preds = %132
  %134 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %134, ptr %4, align 4, !tbaa !9
  br label %235

135:                                              ; No predecessors!
  br label %136

136:                                              ; preds = %135
  br label %137

137:                                              ; preds = %136, %123
  %138 = load ptr, ptr %6, align 8, !tbaa !5
  %139 = getelementptr inbounds %struct.__huf_encoder, ptr %138, i32 0, i32 5
  %140 = load ptr, ptr %139, align 8, !tbaa !24
  %141 = call i32 @huf_bufio_write(ptr noundef %140, ptr noundef %9, i64 noundef 2)
  store i32 %141, ptr %5, align 4, !tbaa !9
  %142 = load i32, ptr %5, align 4, !tbaa !9
  %143 = icmp ne i32 %142, 0
  br i1 %143, label %144, label %149

144:                                              ; preds = %137
  br label %145

145:                                              ; preds = %144
  %146 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %146, ptr %4, align 4, !tbaa !9
  br label %235

147:                                              ; No predecessors!
  br label %148

148:                                              ; preds = %147
  br label %149

149:                                              ; preds = %148, %137
  %150 = load ptr, ptr %6, align 8, !tbaa !5
  %151 = getelementptr inbounds %struct.__huf_encoder, ptr %150, i32 0, i32 5
  %152 = load ptr, ptr %151, align 8, !tbaa !24
  %153 = getelementptr inbounds [1024 x i16], ptr %8, i64 0, i64 0
  %154 = load i64, ptr %10, align 8, !tbaa !13
  %155 = mul i64 %154, 2
  %156 = call i32 @huf_bufio_write(ptr noundef %152, ptr noundef %153, i64 noundef %155)
  store i32 %156, ptr %5, align 4, !tbaa !9
  %157 = load i32, ptr %5, align 4, !tbaa !9
  %158 = icmp ne i32 %157, 0
  br i1 %158, label %159, label %164

159:                                              ; preds = %149
  br label %160

160:                                              ; preds = %159
  %161 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %161, ptr %4, align 4, !tbaa !9
  br label %235

162:                                              ; No predecessors!
  br label %163

163:                                              ; preds = %162
  br label %164

164:                                              ; preds = %163, %149
  %165 = load ptr, ptr %6, align 8, !tbaa !5
  %166 = getelementptr inbounds %struct.__huf_encoder, ptr %165, i32 0, i32 1
  call void @huf_bit_read_writer_reset(ptr noundef %166)
  %167 = load ptr, ptr %6, align 8, !tbaa !5
  %168 = load ptr, ptr %7, align 8, !tbaa !5
  %169 = load i64, ptr %12, align 8, !tbaa !13
  %170 = call i32 @__huf_encode_block(ptr noundef %167, ptr noundef %168, i64 noundef %169)
  store i32 %170, ptr %5, align 4, !tbaa !9
  %171 = load i32, ptr %5, align 4, !tbaa !9
  %172 = icmp ne i32 %171, 0
  br i1 %172, label %173, label %178

173:                                              ; preds = %164
  br label %174

174:                                              ; preds = %173
  %175 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %175, ptr %4, align 4, !tbaa !9
  br label %235

176:                                              ; No predecessors!
  br label %177

177:                                              ; preds = %176
  br label %178

178:                                              ; preds = %177, %164
  %179 = load i64, ptr %12, align 8, !tbaa !13
  %180 = load i64, ptr %11, align 8, !tbaa !13
  %181 = sub i64 %180, %179
  store i64 %181, ptr %11, align 8, !tbaa !13
  %182 = load i64, ptr %11, align 8, !tbaa !13
  %183 = icmp ne i64 %182, 0
  br i1 %183, label %185, label %184

184:                                              ; preds = %178
  br label %43, !llvm.loop !25

185:                                              ; preds = %178
  %186 = load ptr, ptr %6, align 8, !tbaa !5
  %187 = getelementptr inbounds %struct.__huf_encoder, ptr %186, i32 0, i32 2
  %188 = load ptr, ptr %187, align 8, !tbaa !23
  %189 = call i32 @huf_tree_reset(ptr noundef %188)
  store i32 %189, ptr %5, align 4, !tbaa !9
  %190 = load i32, ptr %5, align 4, !tbaa !9
  %191 = icmp ne i32 %190, 0
  br i1 %191, label %192, label %197

192:                                              ; preds = %185
  br label %193

193:                                              ; preds = %192
  %194 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %194, ptr %4, align 4, !tbaa !9
  br label %235

195:                                              ; No predecessors!
  br label %196

196:                                              ; preds = %195
  br label %197

197:                                              ; preds = %196, %185
  %198 = load ptr, ptr %6, align 8, !tbaa !5
  %199 = getelementptr inbounds %struct.__huf_encoder, ptr %198, i32 0, i32 4
  %200 = load ptr, ptr %199, align 8, !tbaa !22
  %201 = call i32 @huf_histogram_reset(ptr noundef %200)
  store i32 %201, ptr %5, align 4, !tbaa !9
  %202 = load i32, ptr %5, align 4, !tbaa !9
  %203 = icmp ne i32 %202, 0
  br i1 %203, label %204, label %209

204:                                              ; preds = %197
  br label %205

205:                                              ; preds = %204
  %206 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %206, ptr %4, align 4, !tbaa !9
  br label %235

207:                                              ; No predecessors!
  br label %208

208:                                              ; preds = %207
  br label %209

209:                                              ; preds = %208, %197
  %210 = load ptr, ptr %6, align 8, !tbaa !5
  %211 = getelementptr inbounds %struct.__huf_encoder, ptr %210, i32 0, i32 3
  %212 = load ptr, ptr %211, align 8, !tbaa !27
  %213 = call i32 @huf_symbol_mapping_reset(ptr noundef %212)
  store i32 %213, ptr %5, align 4, !tbaa !9
  %214 = load i32, ptr %5, align 4, !tbaa !9
  %215 = icmp ne i32 %214, 0
  br i1 %215, label %216, label %221

216:                                              ; preds = %209
  br label %217

217:                                              ; preds = %216
  %218 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %218, ptr %4, align 4, !tbaa !9
  br label %235

219:                                              ; No predecessors!
  br label %220

220:                                              ; preds = %219
  br label %221

221:                                              ; preds = %220, %209
  br label %43, !llvm.loop !25

222:                                              ; preds = %43
  %223 = load ptr, ptr %6, align 8, !tbaa !5
  %224 = getelementptr inbounds %struct.__huf_encoder, ptr %223, i32 0, i32 5
  %225 = load ptr, ptr %224, align 8, !tbaa !24
  %226 = call i32 @huf_bufio_read_writer_flush(ptr noundef %225)
  store i32 %226, ptr %5, align 4, !tbaa !9
  %227 = load i32, ptr %5, align 4, !tbaa !9
  %228 = icmp ne i32 %227, 0
  br i1 %228, label %229, label %234

229:                                              ; preds = %222
  br label %230

230:                                              ; preds = %229
  %231 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %231, ptr %4, align 4, !tbaa !9
  br label %235

232:                                              ; No predecessors!
  br label %233

233:                                              ; preds = %232
  br label %234

234:                                              ; preds = %233, %222
  br label %235

235:                                              ; preds = %234, %230, %217, %205, %193, %174, %160, %145, %133, %119, %106, %96, %81, %67, %33, %19
  %236 = call i32 @huf_encoder_free(ptr noundef %6)
  %237 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %237) #5
  br label %238

238:                                              ; preds = %235
  %239 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %239, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %242

240:                                              ; No predecessors!
  br label %241

241:                                              ; preds = %240
  store i32 0, ptr %13, align 4
  br label %242

242:                                              ; preds = %241, %238
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 2048, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %243 = load i32, ptr %13, align 4
  switch i32 %243, label %246 [
    i32 0, label %244
    i32 1, label %244
  ]

244:                                              ; preds = %242, %242
  %245 = load i32, ptr %2, align 4
  ret i32 %245

246:                                              ; preds = %242
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

declare i32 @huf_bufio_read(ptr noundef, ptr noundef, i64 noundef) #2

declare i32 @huf_histogram_populate(ptr noundef, ptr noundef, i64 noundef) #2

declare i32 @huf_tree_from_histogram(ptr noundef, ptr noundef) #2

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

declare i32 @huf_tree_serialize(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @huf_bufio_write(ptr noundef, ptr noundef, i64 noundef) #2

declare void @huf_bit_read_writer_reset(ptr noundef) #2

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

declare i32 @huf_tree_reset(ptr noundef) #2

declare i32 @huf_histogram_reset(ptr noundef) #2

declare i32 @huf_symbol_mapping_reset(ptr noundef) #2

declare i32 @huf_bufio_read_writer_flush(ptr noundef) #2

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 = { "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 "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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"__huf_encoder", !6, i64 0, !17, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!17 = !{!"__huf_bit_read_writer", !7, i64 0, !7, i64 1}
!18 = !{!19, !14, i64 8}
!19 = !{!"__huf_encoder_config", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !6, i64 32, !6, i64 40}
!20 = !{!19, !14, i64 0}
!21 = !{!16, !6, i64 48}
!22 = !{!16, !6, i64 32}
!23 = !{!16, !6, i64 16}
!24 = !{!16, !6, i64 40}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!16, !6, i64 24}


; 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 i32 @huf_encoder_init(ptr noundef, 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

declare i32 @huf_malloc(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 @huf_encoder_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @huf_encode(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca [1024 x i16], align 16
  %5 = alloca i16, align 2
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #6
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #6
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %4) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2048) %4, i8 0, i64 2048, i1 false)
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %5) #6
  store i16 0, ptr %5, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #6
  store i64 0, ptr %6, align 8, !tbaa !11
  %8 = call i32 @huf_encoder_init(ptr noundef nonnull %2, ptr noundef %0)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %.loopexit

9:                                                ; preds = %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !16
  %14 = call i32 @huf_malloc(ptr noundef nonnull %3, i64 noundef 1, i64 noundef %13) #6
  %.not54 = icmp eq i32 %14, 0
  br i1 %.not54, label %15, label %.loopexit

15:                                               ; preds = %9
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = load i64, ptr %17, align 8, !tbaa !18
  %.not5571 = icmp eq i64 %18, 0
  br i1 %.not5571, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %87
  %.03772 = phi i64 [ %77, %87 ], [ %18, %15 ]
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %20, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !16
  %spec.select = call i64 @llvm.umin.i64(i64 %.03772, i64 %22)
  store i64 %spec.select, ptr %7, align 8, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %19, i64 48
  %24 = load ptr, ptr %23, align 8, !tbaa !19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = call i32 @huf_bufio_read(ptr noundef %24, ptr noundef %25, i64 noundef %spec.select) #6
  %.not57 = icmp eq i32 %26, 0
  br i1 %.not57, label %27, label %.loopexit

27:                                               ; preds = %.lr.ph
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 32
  %30 = load ptr, ptr %29, align 8, !tbaa !20
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load i64, ptr %7, align 8, !tbaa !11
  %33 = call i32 @huf_histogram_populate(ptr noundef %30, ptr noundef %31, i64 noundef %32) #6
  %.not58 = icmp eq i32 %33, 0
  br i1 %.not58, label %34, label %.loopexit

34:                                               ; preds = %27
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 16
  %37 = load ptr, ptr %36, align 8, !tbaa !21
  %38 = getelementptr inbounds i8, ptr %35, i64 32
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  %40 = call i32 @huf_tree_from_histogram(ptr noundef %37, ptr noundef %39) #6
  %.not59 = icmp eq i32 %40, 0
  br i1 %.not59, label %41, label %.loopexit

41:                                               ; preds = %34
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = call i32 @__huf_create_char_coding(ptr noundef %42)
  %.not60 = icmp eq i32 %43, 0
  br i1 %.not60, label %44, label %.loopexit

44:                                               ; preds = %41
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 16
  %47 = load ptr, ptr %46, align 8, !tbaa !21
  %48 = call i32 @huf_tree_serialize(ptr noundef %47, ptr noundef nonnull %4, ptr noundef nonnull %6) #6
  %.not61 = icmp eq i32 %48, 0
  br i1 %.not61, label %49, label %.loopexit

49:                                               ; preds = %44
  %50 = load i64, ptr %6, align 8, !tbaa !11
  %51 = trunc i64 %50 to i16
  store i16 %51, ptr %5, align 2, !tbaa !9
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 40
  %54 = load ptr, ptr %53, align 8, !tbaa !22
  %55 = call i32 @huf_bufio_write(ptr noundef %54, ptr noundef nonnull %7, i64 noundef 8) #6
  %.not62 = icmp eq i32 %55, 0
  br i1 %.not62, label %56, label %.loopexit

56:                                               ; preds = %49
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i64 40
  %59 = load ptr, ptr %58, align 8, !tbaa !22
  %60 = call i32 @huf_bufio_write(ptr noundef %59, ptr noundef nonnull %5, i64 noundef 2) #6
  %.not63 = icmp eq i32 %60, 0
  br i1 %.not63, label %61, label %.loopexit

61:                                               ; preds = %56
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 40
  %64 = load ptr, ptr %63, align 8, !tbaa !22
  %65 = load i64, ptr %6, align 8, !tbaa !11
  %66 = shl i64 %65, 1
  %67 = call i32 @huf_bufio_write(ptr noundef %64, ptr noundef nonnull %4, i64 noundef %66) #6
  %.not64 = icmp eq i32 %67, 0
  br i1 %.not64, label %68, label %.loopexit

68:                                               ; preds = %61
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %69, i64 8
  call void @huf_bit_read_writer_reset(ptr noundef nonnull %70) #6
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = load i64, ptr %7, align 8, !tbaa !11
  %74 = call i32 @__huf_encode_block(ptr noundef %71, ptr noundef %72, i64 noundef %73)
  %.not65 = icmp eq i32 %74, 0
  br i1 %.not65, label %75, label %.loopexit

75:                                               ; preds = %68
  %76 = load i64, ptr %7, align 8, !tbaa !11
  %77 = sub i64 %.03772, %76
  %.not66 = icmp eq i64 %77, 0
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  br i1 %.not66, label %._crit_edge, label %78

78:                                               ; preds = %75
  %79 = getelementptr inbounds i8, ptr %.pre, i64 16
  %80 = load ptr, ptr %79, align 8, !tbaa !21
  %81 = call i32 @huf_tree_reset(ptr noundef %80) #6
  %.not67 = icmp eq i32 %81, 0
  br i1 %.not67, label %82, label %.loopexit

82:                                               ; preds = %78
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds i8, ptr %83, i64 32
  %85 = load ptr, ptr %84, align 8, !tbaa !20
  %86 = call i32 @huf_histogram_reset(ptr noundef %85) #6
  %.not68 = icmp eq i32 %86, 0
  br i1 %.not68, label %87, label %.loopexit

87:                                               ; preds = %82
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds i8, ptr %88, i64 24
  %90 = load ptr, ptr %89, align 8, !tbaa !23
  %91 = call i32 @huf_symbol_mapping_reset(ptr noundef %90) #6
  %.not69 = icmp eq i32 %91, 0
  br i1 %.not69, label %.lr.ph, label %.loopexit, !llvm.loop !24

._crit_edge:                                      ; preds = %75, %15
  %92 = phi ptr [ %16, %15 ], [ %.pre, %75 ]
  %93 = getelementptr inbounds i8, ptr %92, i64 40
  %94 = load ptr, ptr %93, align 8, !tbaa !22
  %95 = call i32 @huf_bufio_read_writer_flush(ptr noundef %94) #6
  br label %.loopexit

.loopexit:                                        ; preds = %87, %82, %78, %68, %61, %56, %49, %44, %41, %34, %27, %.lr.ph, %._crit_edge, %9, %1
  %.0 = phi i32 [ %8, %1 ], [ %14, %9 ], [ %95, %._crit_edge ], [ %91, %87 ], [ %86, %82 ], [ %81, %78 ], [ %74, %68 ], [ %67, %61 ], [ %60, %56 ], [ %55, %49 ], [ %48, %44 ], [ %43, %41 ], [ %40, %34 ], [ %33, %27 ], [ %26, %.lr.ph ]
  %96 = call i32 @huf_encoder_free(ptr noundef nonnull %2)
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %97) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

declare i32 @huf_bufio_read(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @huf_histogram_populate(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @huf_tree_from_histogram(ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare i32 @huf_tree_serialize(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @huf_bufio_write(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @huf_bit_read_writer_reset(ptr noundef) local_unnamed_addr #2

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

declare i32 @huf_tree_reset(ptr noundef) local_unnamed_addr #2

declare i32 @huf_histogram_reset(ptr noundef) local_unnamed_addr #2

declare i32 @huf_symbol_mapping_reset(ptr noundef) local_unnamed_addr #2

declare i32 @huf_bufio_read_writer_flush(ptr noundef) local_unnamed_addr #2

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

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 = { 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"__huf_encoder", !6, i64 0, !15, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!15 = !{!"__huf_bit_read_writer", !7, i64 0, !7, i64 1}
!16 = !{!17, !12, i64 8}
!17 = !{!"__huf_encoder_config", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!17, !12, i64 0}
!19 = !{!14, !6, i64 48}
!20 = !{!14, !6, i64 32}
!21 = !{!14, !6, i64 16}
!22 = !{!14, !6, i64 40}
!23 = !{!14, !6, i64 24}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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