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

; 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.ZSTD_matchState_t = type { %struct.ZSTD_window_t, i32, i32, i32, i32, ptr, ptr, ptr, %struct.optState_t }
%struct.ZSTD_window_t = type { ptr, ptr, ptr, i32, i32 }
%struct.optState_t = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_compressionParameters = type { i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @ZSTD_fillHashTable(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ZSTD_matchState_t, ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  store ptr %22, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !15
  store i32 %25, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %26, i32 0, i32 4
  %28 = load i32, ptr %27, align 4, !tbaa !17
  store i32 %28, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ZSTD_matchState_t, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds %struct.ZSTD_window_t, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  store ptr %32, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %33 = load ptr, ptr %12, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ZSTD_matchState_t, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !19
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %33, i64 %37
  store ptr %38, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 -8
  store ptr %40, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 3, ptr %15, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %92, %4
  %42 = load ptr, ptr %13, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 3
  %44 = getelementptr inbounds i8, ptr %43, i64 -1
  %45 = load ptr, ptr %14, align 8, !tbaa !5
  %46 = icmp ule ptr %44, %45
  br i1 %46, label %47, label %95

47:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %48 = load ptr, ptr %13, align 8, !tbaa !5
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = ptrtoint ptr %48 to i64
  %51 = ptrtoint ptr %49 to i64
  %52 = sub i64 %50, %51
  %53 = trunc i64 %52 to i32
  store i32 %53, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %88, %47
  %55 = load i32, ptr %17, align 4, !tbaa !9
  %56 = icmp ult i32 %55, 3
  br i1 %56, label %57, label %91

57:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load i32, ptr %17, align 4, !tbaa !9
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %58, i64 %60
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = call i64 @ZSTD_hashPtr(ptr noundef %61, i32 noundef %62, i32 noundef %63)
  store i64 %64, ptr %18, align 8, !tbaa !20
  %65 = load i32, ptr %17, align 4, !tbaa !9
  %66 = icmp eq i32 %65, 0
  br i1 %66, label %73, label %67

67:                                               ; preds = %57
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load i64, ptr %18, align 8, !tbaa !20
  %70 = getelementptr inbounds i32, ptr %68, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = icmp eq i32 %71, 0
  br i1 %72, label %73, label %80

73:                                               ; preds = %67, %57
  %74 = load i32, ptr %16, align 4, !tbaa !9
  %75 = load i32, ptr %17, align 4, !tbaa !9
  %76 = add i32 %74, %75
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load i64, ptr %18, align 8, !tbaa !20
  %79 = getelementptr inbounds i32, ptr %77, i64 %78
  store i32 %76, ptr %79, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %73, %67
  %81 = load i32, ptr %8, align 4, !tbaa !9
  %82 = icmp eq i32 %81, 0
  br i1 %82, label %83, label %84

83:                                               ; preds = %80
  store i32 5, ptr %19, align 4
  br label %85

84:                                               ; preds = %80
  store i32 0, ptr %19, align 4
  br label %85

85:                                               ; preds = %84, %83
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  %86 = load i32, ptr %19, align 4
  switch i32 %86, label %96 [
    i32 0, label %87
    i32 5, label %91
  ]

87:                                               ; preds = %85
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %17, align 4, !tbaa !9
  %90 = add i32 %89, 1
  store i32 %90, ptr %17, align 4, !tbaa !9
  br label %54, !llvm.loop !22

91:                                               ; preds = %85, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %92

92:                                               ; preds = %91
  %93 = load ptr, ptr %13, align 8, !tbaa !5
  %94 = getelementptr inbounds i8, ptr %93, i64 3
  store ptr %94, ptr %13, align 8, !tbaa !5
  br label %41, !llvm.loop !24

95:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void

96:                                               ; preds = %85
  unreachable
}

; 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 i64 @ZSTD_hashPtr(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 48}
!12 = !{!"", !13, i64 0, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !14, i64 72}
!13 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80}
!15 = !{!16, !10, i64 8}
!16 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!17 = !{!16, !10, i64 16}
!18 = !{!12, !6, i64 8}
!19 = !{!12, !10, i64 36}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


; 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
define dso_local void @ZSTD_fillHashTable(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr noundef readnone %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = load i32, ptr %9, align 4, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %0, i64 36
  %14 = load i32, ptr %13, align 4, !tbaa !17
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %12, i64 %15
  %17 = getelementptr inbounds i8, ptr %2, i64 -8
  %18 = getelementptr inbounds i8, ptr %16, i64 2
  %.not31 = icmp ugt ptr %18, %17
  br i1 %.not31, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %19 = getelementptr inbounds i8, ptr %16, i64 3
  %20 = ptrtoint ptr %12 to i64
  %21 = icmp eq i32 %3, 0
  br i1 %21, label %.split.us.us, label %.split.preheader

.split.us.us:                                     ; preds = %.lr.ph, %.split.us.us
  %22 = phi ptr [ %28, %.split.us.us ], [ %19, %.lr.ph ]
  %.02632.us = phi ptr [ %22, %.split.us.us ], [ %16, %.lr.ph ]
  %23 = ptrtoint ptr %.02632.us to i64
  %24 = sub i64 %23, %20
  %25 = trunc i64 %24 to i32
  %26 = tail call i64 @ZSTD_hashPtr(ptr noundef %.02632.us, i32 noundef %8, i32 noundef %10)
  %27 = getelementptr inbounds i32, ptr %6, i64 %26
  store i32 %25, ptr %27, align 4, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %22, i64 3
  %29 = getelementptr inbounds i8, ptr %22, i64 2
  %.not.us = icmp ugt ptr %29, %17
  br i1 %.not.us, label %._crit_edge, label %.split.us.us, !llvm.loop !19

.split.preheader:                                 ; preds = %.lr.ph, %.split30
  %30 = phi ptr [ %53, %.split30 ], [ %19, %.lr.ph ]
  %.02632 = phi ptr [ %30, %.split30 ], [ %16, %.lr.ph ]
  %31 = ptrtoint ptr %.02632 to i64
  %32 = sub i64 %31, %20
  %33 = trunc i64 %32 to i32
  %34 = tail call i64 @ZSTD_hashPtr(ptr noundef %.02632, i32 noundef %8, i32 noundef %10)
  %35 = getelementptr inbounds i32, ptr %6, i64 %34
  store i32 %33, ptr %35, align 4, !tbaa !18
  %36 = getelementptr inbounds i8, ptr %.02632, i64 1
  %37 = tail call i64 @ZSTD_hashPtr(ptr noundef nonnull %36, i32 noundef %8, i32 noundef %10)
  %38 = getelementptr inbounds i32, ptr %6, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !18
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %.split.preheader
  %42 = add i32 %33, 1
  %43 = getelementptr inbounds i32, ptr %6, i64 %37
  store i32 %42, ptr %43, align 4, !tbaa !18
  br label %44

44:                                               ; preds = %.split.preheader, %41
  %45 = getelementptr inbounds i8, ptr %.02632, i64 2
  %46 = tail call i64 @ZSTD_hashPtr(ptr noundef nonnull %45, i32 noundef %8, i32 noundef %10)
  %47 = getelementptr inbounds i32, ptr %6, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !18
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %.split30

50:                                               ; preds = %44
  %51 = add i32 %33, 2
  %52 = getelementptr inbounds i32, ptr %6, i64 %46
  store i32 %51, ptr %52, align 4, !tbaa !18
  br label %.split30

.split30:                                         ; preds = %50, %44
  %53 = getelementptr inbounds i8, ptr %30, i64 3
  %54 = getelementptr inbounds i8, ptr %30, i64 2
  %.not = icmp ugt ptr %54, %17
  br i1 %.not, label %._crit_edge, label %.split.preheader, !llvm.loop !19

._crit_edge:                                      ; preds = %.split30, %.split.us.us, %4
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @ZSTD_hashPtr(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #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 = { 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, !8, i64 48}
!6 = !{!"", !7, i64 0, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !8, i64 48, !8, i64 56, !8, i64 64, !12, i64 72}
!7 = !{!"", !8, i64 0, !8, i64 8, !8, i64 16, !11, i64 24, !11, i64 28}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80}
!13 = !{!14, !11, i64 8}
!14 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!15 = !{!14, !11, i64 16}
!16 = !{!6, !8, i64 8}
!17 = !{!6, !11, i64 36}
!18 = !{!11, !11, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass