; LLVM IR from catid/Zpng :: zstd (zdict)

; 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.ZDICT_params_t = type { i32, i32, i32 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @ZDICT_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: inlinehint nounwind uwtable
declare hidden void @MEM_writeLE32(ptr noundef, i32 noundef) #2

declare i64 @XXH64(ptr noundef, i64 noundef, i64 noundef) #3

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

declare i32 @fflush(ptr noundef) #3

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #5

; Function Attrs: nounwind uwtable
define dso_local i64 @ZDICT_addEntropyTablesFromBuffer_advanced(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef byval(%struct.ZDICT_params_t) align 8 %6) #0 {
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca i32, align 4
  %20 = alloca i64, align 8
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i64 %1, ptr %10, align 8, !tbaa !9
  store i64 %2, ptr %11, align 8, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store i32 %5, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  %23 = getelementptr inbounds %struct.ZDICT_params_t, ptr %6, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !13
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %7
  br label %30

27:                                               ; preds = %7
  %28 = getelementptr inbounds %struct.ZDICT_params_t, ptr %6, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !13
  br label %30

30:                                               ; preds = %27, %26
  %31 = phi i32 [ 3, %26 ], [ %29, %27 ]
  store i32 %31, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  %32 = getelementptr inbounds %struct.ZDICT_params_t, ptr %6, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !15
  store i32 %33, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  store i64 8, ptr %17, align 8, !tbaa !9
  %34 = load i32, ptr %16, align 4, !tbaa !11
  %35 = icmp uge i32 %34, 2
  br i1 %35, label %36, label %41

36:                                               ; preds = %30
  %37 = load ptr, ptr @stderr, align 8, !tbaa !5
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef @.str, ptr noundef @.str.1) #6
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = call i32 @fflush(ptr noundef %39)
  br label %41

41:                                               ; preds = %36, %30
  %42 = load i32, ptr %16, align 4, !tbaa !11
  %43 = icmp uge i32 %42, 2
  br i1 %43, label %44, label %49

44:                                               ; preds = %41
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.2) #6
  %47 = load ptr, ptr @stderr, align 8, !tbaa !5
  %48 = call i32 @fflush(ptr noundef %47)
  br label %49

49:                                               ; preds = %44, %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = load i64, ptr %17, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  %53 = load i64, ptr %11, align 8, !tbaa !9
  %54 = load i64, ptr %17, align 8, !tbaa !9
  %55 = sub i64 %53, %54
  %56 = load i32, ptr %15, align 4, !tbaa !11
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load i32, ptr %14, align 4, !tbaa !11
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load i64, ptr %11, align 8, !tbaa !9
  %62 = getelementptr inbounds i8, ptr %60, i64 %61
  %63 = load i64, ptr %10, align 8, !tbaa !9
  %64 = sub i64 0, %63
  %65 = getelementptr inbounds i8, ptr %62, i64 %64
  %66 = load i64, ptr %10, align 8, !tbaa !9
  %67 = load i32, ptr %16, align 4, !tbaa !11
  %68 = call i64 @ZDICT_analyzeEntropy(ptr noundef %52, i64 noundef %55, i32 noundef %56, ptr noundef %57, ptr noundef %58, i32 noundef %59, ptr noundef %65, i64 noundef %66, i32 noundef %67)
  store i64 %68, ptr %18, align 8, !tbaa !9
  %69 = load i64, ptr %18, align 8, !tbaa !9
  %70 = call i32 @ZDICT_isError(i64 noundef %69)
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %74

72:                                               ; preds = %49
  %73 = load i64, ptr %18, align 8, !tbaa !9
  store i64 %73, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %78

74:                                               ; preds = %49
  %75 = load i64, ptr %18, align 8, !tbaa !9
  %76 = load i64, ptr %17, align 8, !tbaa !9
  %77 = add i64 %76, %75
  store i64 %77, ptr %17, align 8, !tbaa !9
  store i32 0, ptr %19, align 4
  br label %78

78:                                               ; preds = %74, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  %79 = load i32, ptr %19, align 4
  switch i32 %79, label %137 [
    i32 0, label %80
  ]

80:                                               ; preds = %78
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  call void @MEM_writeLE32(ptr noundef %81, i32 noundef -332356553)
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #6
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = load i64, ptr %11, align 8, !tbaa !9
  %84 = getelementptr inbounds i8, ptr %82, i64 %83
  %85 = load i64, ptr %10, align 8, !tbaa !9
  %86 = sub i64 0, %85
  %87 = getelementptr inbounds i8, ptr %84, i64 %86
  %88 = load i64, ptr %10, align 8, !tbaa !9
  %89 = call i64 @XXH64(ptr noundef %87, i64 noundef %88, i64 noundef 0)
  store i64 %89, ptr %20, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #6
  %90 = load i64, ptr %20, align 8, !tbaa !9
  %91 = urem i64 %90, 2147450880
  %92 = add i64 %91, 32768
  %93 = trunc i64 %92 to i32
  store i32 %93, ptr %21, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #6
  %94 = getelementptr inbounds %struct.ZDICT_params_t, ptr %6, i32 0, i32 2
  %95 = load i32, ptr %94, align 8, !tbaa !16
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %100

97:                                               ; preds = %80
  %98 = getelementptr inbounds %struct.ZDICT_params_t, ptr %6, i32 0, i32 2
  %99 = load i32, ptr %98, align 8, !tbaa !16
  br label %102

100:                                              ; preds = %80
  %101 = load i32, ptr %21, align 4, !tbaa !11
  br label %102

102:                                              ; preds = %100, %97
  %103 = phi i32 [ %99, %97 ], [ %101, %100 ]
  store i32 %103, ptr %22, align 4, !tbaa !11
  %104 = load ptr, ptr %9, align 8, !tbaa !5
  %105 = getelementptr inbounds i8, ptr %104, i64 4
  %106 = load i32, ptr %22, align 4, !tbaa !11
  call void @MEM_writeLE32(ptr noundef %105, i32 noundef %106)
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #6
  %107 = load i64, ptr %17, align 8, !tbaa !9
  %108 = load i64, ptr %10, align 8, !tbaa !9
  %109 = add i64 %107, %108
  %110 = load i64, ptr %11, align 8, !tbaa !9
  %111 = icmp ult i64 %109, %110
  br i1 %111, label %112, label %123

112:                                              ; preds = %102
  %113 = load ptr, ptr %9, align 8, !tbaa !5
  %114 = load i64, ptr %17, align 8, !tbaa !9
  %115 = getelementptr inbounds i8, ptr %113, i64 %114
  %116 = load ptr, ptr %9, align 8, !tbaa !5
  %117 = load i64, ptr %11, align 8, !tbaa !9
  %118 = getelementptr inbounds i8, ptr %116, i64 %117
  %119 = load i64, ptr %10, align 8, !tbaa !9
  %120 = sub i64 0, %119
  %121 = getelementptr inbounds i8, ptr %118, i64 %120
  %122 = load i64, ptr %10, align 8, !tbaa !9
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %115, ptr align 1 %121, i64 %122, i1 false)
  br label %123

123:                                              ; preds = %112, %102
  %124 = load i64, ptr %11, align 8, !tbaa !9
  %125 = load i64, ptr %17, align 8, !tbaa !9
  %126 = load i64, ptr %10, align 8, !tbaa !9
  %127 = add i64 %125, %126
  %128 = icmp ult i64 %124, %127
  br i1 %128, label %129, label %131

129:                                              ; preds = %123
  %130 = load i64, ptr %11, align 8, !tbaa !9
  br label %135

131:                                              ; preds = %123
  %132 = load i64, ptr %17, align 8, !tbaa !9
  %133 = load i64, ptr %10, align 8, !tbaa !9
  %134 = add i64 %132, %133
  br label %135

135:                                              ; preds = %131, %129
  %136 = phi i64 [ %130, %129 ], [ %134, %131 ]
  store i64 %136, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %137

137:                                              ; preds = %135, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  %138 = load i64, ptr %8, align 8
  ret i64 %138
}

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 = { "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 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!15 = !{!14, !12, i64 4}
!16 = !{!14, !12, i64 8}


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

%struct.ZDICT_params_t = type { i32, i32, i32 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1

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

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

declare i64 @XXH64(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #3

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @ZDICT_addEntropyTablesFromBuffer_advanced(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, ptr nocapture noundef readonly byval(%struct.ZDICT_params_t) align 8 %6) local_unnamed_addr #0 {
  %8 = load i32, ptr %6, align 8
  %9 = icmp eq i32 %8, 0
  %10 = select i1 %9, i32 3, i32 %8
  %11 = getelementptr inbounds i8, ptr %6, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp ugt i32 %12, 1
  br i1 %13, label %14, label %.critedge

14:                                               ; preds = %7
  %15 = load ptr, ptr @stderr, align 8, !tbaa !10
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1) #6
  %17 = load ptr, ptr @stderr, align 8, !tbaa !10
  %18 = tail call i32 @fflush(ptr noundef %17)
  %19 = load ptr, ptr @stderr, align 8, !tbaa !10
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.2) #6
  %21 = load ptr, ptr @stderr, align 8, !tbaa !10
  %22 = tail call i32 @fflush(ptr noundef %21)
  br label %.critedge

.critedge:                                        ; preds = %7, %14
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = add i64 %2, -8
  %25 = getelementptr inbounds i8, ptr %0, i64 %2
  %26 = sub i64 0, %1
  %27 = getelementptr inbounds i8, ptr %25, i64 %26
  %28 = tail call i64 @ZDICT_analyzeEntropy(ptr noundef nonnull %23, i64 noundef %24, i32 noundef %10, ptr noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef %27, i64 noundef %1, i32 noundef %12)
  %29 = tail call i32 @ZDICT_isError(i64 noundef %28)
  %.not = icmp eq i32 %29, 0
  %30 = add i64 %28, 8
  br i1 %.not, label %31, label %46

31:                                               ; preds = %.critedge
  tail call void @MEM_writeLE32(ptr noundef %0, i32 noundef -332356553)
  %32 = tail call i64 @XXH64(ptr noundef %27, i64 noundef %1, i64 noundef 0) #7
  %33 = urem i64 %32, 2147450880
  %34 = trunc nuw nsw i64 %33 to i32
  %35 = add nuw nsw i32 %34, 32768
  %36 = getelementptr inbounds i8, ptr %6, i64 8
  %37 = load i32, ptr %36, align 8
  %.not46 = icmp eq i32 %37, 0
  %38 = select i1 %.not46, i32 %35, i32 %37
  %39 = getelementptr inbounds i8, ptr %0, i64 4
  tail call void @MEM_writeLE32(ptr noundef nonnull %39, i32 noundef %38)
  %40 = add i64 %30, %1
  %41 = icmp ult i64 %40, %2
  br i1 %41, label %42, label %44

42:                                               ; preds = %31
  %43 = getelementptr inbounds i8, ptr %0, i64 %30
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %43, ptr nonnull align 1 %27, i64 %1, i1 false)
  br label %44

44:                                               ; preds = %42, %31
  %45 = tail call i64 @llvm.umin.i64(i64 %40, i64 %2)
  br label %46

46:                                               ; preds = %.critedge, %44
  %.1 = phi i64 [ %45, %44 ], [ %28, %.critedge ]
  ret i64 %.1
}

; 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 = { 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 #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 = { nofree 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { cold nounwind }
attributes #7 = { 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, !7, i64 4}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, i64 0}


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