; LLVM IR from catid/Zpng :: zstd (zstd_double_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_fillDoubleHashTable(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 i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i64, align 8
  %21 = alloca i64, align 8
  %22 = 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
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ZSTD_matchState_t, ptr %23, i32 0, i32 5
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  store ptr %25, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 4, !tbaa !15
  store i32 %28, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %29, i32 0, i32 4
  %31 = load i32, ptr %30, align 4, !tbaa !17
  store i32 %31, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ZSTD_matchState_t, ptr %32, i32 0, i32 7
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  store ptr %34, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !19
  store i32 %37, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ZSTD_matchState_t, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds %struct.ZSTD_window_t, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !20
  store ptr %41, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %42 = load ptr, ptr %14, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ZSTD_matchState_t, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !21
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %42, i64 %46
  store ptr %47, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i64 -8
  store ptr %49, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 3, ptr %17, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %117, %4
  %51 = load ptr, ptr %15, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 3
  %53 = getelementptr inbounds i8, ptr %52, i64 -1
  %54 = load ptr, ptr %16, align 8, !tbaa !5
  %55 = icmp ule ptr %53, %54
  br i1 %55, label %56, label %120

56:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %57 = load ptr, ptr %15, align 8, !tbaa !5
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = ptrtoint ptr %57 to i64
  %60 = ptrtoint ptr %58 to i64
  %61 = sub i64 %59, %60
  %62 = trunc i64 %61 to i32
  store i32 %62, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %113, %56
  %64 = load i32, ptr %19, align 4, !tbaa !9
  %65 = icmp ult i32 %64, 3
  br i1 %65, label %66, label %116

66:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  %68 = load i32, ptr %19, align 4, !tbaa !9
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %67, i64 %69
  %71 = load i32, ptr %13, align 4, !tbaa !9
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = call i64 @ZSTD_hashPtr(ptr noundef %70, i32 noundef %71, i32 noundef %72)
  store i64 %73, ptr %20, align 8, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  %74 = load ptr, ptr %15, align 8, !tbaa !5
  %75 = load i32, ptr %19, align 4, !tbaa !9
  %76 = zext i32 %75 to i64
  %77 = getelementptr inbounds i8, ptr %74, i64 %76
  %78 = load i32, ptr %10, align 4, !tbaa !9
  %79 = call i64 @ZSTD_hashPtr(ptr noundef %77, i32 noundef %78, i32 noundef 8)
  store i64 %79, ptr %21, align 8, !tbaa !22
  %80 = load i32, ptr %19, align 4, !tbaa !9
  %81 = icmp eq i32 %80, 0
  br i1 %81, label %82, label %89

82:                                               ; preds = %66
  %83 = load i32, ptr %18, align 4, !tbaa !9
  %84 = load i32, ptr %19, align 4, !tbaa !9
  %85 = add i32 %83, %84
  %86 = load ptr, ptr %12, align 8, !tbaa !5
  %87 = load i64, ptr %20, align 8, !tbaa !22
  %88 = getelementptr inbounds i32, ptr %86, i64 %87
  store i32 %85, ptr %88, align 4, !tbaa !9
  br label %89

89:                                               ; preds = %82, %66
  %90 = load i32, ptr %19, align 4, !tbaa !9
  %91 = icmp eq i32 %90, 0
  br i1 %91, label %98, label %92

92:                                               ; preds = %89
  %93 = load ptr, ptr %9, align 8, !tbaa !5
  %94 = load i64, ptr %21, align 8, !tbaa !22
  %95 = getelementptr inbounds i32, ptr %93, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !9
  %97 = icmp eq i32 %96, 0
  br i1 %97, label %98, label %105

98:                                               ; preds = %92, %89
  %99 = load i32, ptr %18, align 4, !tbaa !9
  %100 = load i32, ptr %19, align 4, !tbaa !9
  %101 = add i32 %99, %100
  %102 = load ptr, ptr %9, align 8, !tbaa !5
  %103 = load i64, ptr %21, align 8, !tbaa !22
  %104 = getelementptr inbounds i32, ptr %102, i64 %103
  store i32 %101, ptr %104, align 4, !tbaa !9
  br label %105

105:                                              ; preds = %98, %92
  %106 = load i32, ptr %8, align 4, !tbaa !9
  %107 = icmp eq i32 %106, 0
  br i1 %107, label %108, label %109

108:                                              ; preds = %105
  store i32 5, ptr %22, align 4
  br label %110

109:                                              ; preds = %105
  store i32 0, ptr %22, align 4
  br label %110

110:                                              ; preds = %109, %108
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  %111 = load i32, ptr %22, align 4
  switch i32 %111, label %121 [
    i32 0, label %112
    i32 5, label %116
  ]

112:                                              ; preds = %110
  br label %113

113:                                              ; preds = %112
  %114 = load i32, ptr %19, align 4, !tbaa !9
  %115 = add i32 %114, 1
  store i32 %115, ptr %19, align 4, !tbaa !9
  br label %63, !llvm.loop !24

116:                                              ; preds = %110, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  br label %117

117:                                              ; preds = %116
  %118 = load ptr, ptr %15, align 8, !tbaa !5
  %119 = getelementptr inbounds i8, ptr %118, i64 3
  store ptr %119, ptr %15, align 8, !tbaa !5
  br label %50, !llvm.loop !26

120:                                              ; preds = %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, 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

121:                                              ; preds = %110
  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 64}
!19 = !{!16, !10, i64 4}
!20 = !{!12, !6, i64 8}
!21 = !{!12, !10, i64 36}
!22 = !{!23, !23, i64 0}
!23 = !{!"long", !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}


; 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_fillDoubleHashTable(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 64
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %1, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %0, i64 36
  %18 = load i32, ptr %17, align 4, !tbaa !19
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %16, i64 %19
  %21 = getelementptr inbounds i8, ptr %2, i64 -8
  %22 = getelementptr inbounds i8, ptr %20, i64 2
  %.not41 = icmp ugt ptr %22, %21
  br i1 %.not41, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %23 = getelementptr inbounds i8, ptr %20, i64 3
  %24 = ptrtoint ptr %16 to i64
  %25 = icmp eq i32 %3, 0
  br i1 %25, label %.split.us.us, label %.critedge.1

.split.us.us:                                     ; preds = %.lr.ph, %.split.us.us
  %26 = phi ptr [ %34, %.split.us.us ], [ %23, %.lr.ph ]
  %.03642.us = phi ptr [ %26, %.split.us.us ], [ %20, %.lr.ph ]
  %27 = ptrtoint ptr %.03642.us to i64
  %28 = sub i64 %27, %24
  %29 = trunc i64 %28 to i32
  %30 = tail call i64 @ZSTD_hashPtr(ptr noundef %.03642.us, i32 noundef %14, i32 noundef %10)
  %31 = tail call i64 @ZSTD_hashPtr(ptr noundef %.03642.us, i32 noundef %8, i32 noundef 8)
  %32 = getelementptr inbounds i32, ptr %12, i64 %30
  store i32 %29, ptr %32, align 4, !tbaa !20
  %33 = getelementptr inbounds i32, ptr %6, i64 %31
  store i32 %29, ptr %33, align 4, !tbaa !20
  %34 = getelementptr inbounds i8, ptr %26, i64 3
  %35 = getelementptr inbounds i8, ptr %26, i64 2
  %.not.us = icmp ugt ptr %35, %21
  br i1 %.not.us, label %._crit_edge, label %.split.us.us, !llvm.loop !21

.critedge.1:                                      ; preds = %.lr.ph, %.split40
  %36 = phi ptr [ %62, %.split40 ], [ %23, %.lr.ph ]
  %.03642 = phi ptr [ %36, %.split40 ], [ %20, %.lr.ph ]
  %37 = ptrtoint ptr %.03642 to i64
  %38 = sub i64 %37, %24
  %39 = trunc i64 %38 to i32
  %40 = tail call i64 @ZSTD_hashPtr(ptr noundef %.03642, i32 noundef %14, i32 noundef %10)
  %41 = tail call i64 @ZSTD_hashPtr(ptr noundef %.03642, i32 noundef %8, i32 noundef 8)
  %42 = getelementptr inbounds i32, ptr %12, i64 %40
  store i32 %39, ptr %42, align 4, !tbaa !20
  %43 = getelementptr inbounds i32, ptr %6, i64 %41
  store i32 %39, ptr %43, align 4, !tbaa !20
  %44 = getelementptr inbounds i8, ptr %.03642, i64 1
  %45 = tail call i64 @ZSTD_hashPtr(ptr noundef nonnull %44, i32 noundef %14, i32 noundef %10)
  %46 = tail call i64 @ZSTD_hashPtr(ptr noundef nonnull %44, i32 noundef %8, i32 noundef 8)
  %47 = getelementptr inbounds i32, ptr %6, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !20
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %.critedge.2

50:                                               ; preds = %.critedge.1
  %51 = add i32 %39, 1
  %52 = getelementptr inbounds i32, ptr %6, i64 %46
  store i32 %51, ptr %52, align 4, !tbaa !20
  br label %.critedge.2

.critedge.2:                                      ; preds = %.critedge.1, %50
  %53 = getelementptr inbounds i8, ptr %.03642, i64 2
  %54 = tail call i64 @ZSTD_hashPtr(ptr noundef nonnull %53, i32 noundef %14, i32 noundef %10)
  %55 = tail call i64 @ZSTD_hashPtr(ptr noundef nonnull %53, i32 noundef %8, i32 noundef 8)
  %56 = getelementptr inbounds i32, ptr %6, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !20
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %.split40

59:                                               ; preds = %.critedge.2
  %60 = add i32 %39, 2
  %61 = getelementptr inbounds i32, ptr %6, i64 %55
  store i32 %60, ptr %61, align 4, !tbaa !20
  br label %.split40

.split40:                                         ; preds = %59, %.critedge.2
  %62 = getelementptr inbounds i8, ptr %36, i64 3
  %63 = getelementptr inbounds i8, ptr %36, i64 2
  %.not = icmp ugt ptr %63, %21
  br i1 %.not, label %._crit_edge, label %.critedge.1, !llvm.loop !21

._crit_edge:                                      ; preds = %.split40, %.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 64}
!17 = !{!14, !11, i64 4}
!18 = !{!6, !8, i64 8}
!19 = !{!6, !11, i64 36}
!20 = !{!11, !11, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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