; LLVM IR from DanEngelbrecht/longtail :: lib/lz4/ext (lz4)

; 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.LZ4_stream_t_internal = type { [4096 x i32], ptr, ptr, i32, i32, i32 }

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @LZ4_resetStream(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @LZ4_loadDict_internal(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %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 i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %19, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 2, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %20, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %21 = load ptr, ptr %12, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  store ptr %24, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  call void @LZ4_resetStream(ptr noundef %25)
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 8, !tbaa !11
  %29 = add i32 %28, 65536
  store i32 %29, ptr %27, align 8, !tbaa !11
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = icmp slt i32 %30, 8
  br i1 %31, label %32, label %33

32:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %130

33:                                               ; preds = %4
  %34 = load ptr, ptr %13, align 8, !tbaa !5
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = ptrtoint ptr %34 to i64
  %37 = ptrtoint ptr %35 to i64
  %38 = sub i64 %36, %37
  %39 = icmp sgt i64 %38, 65536
  br i1 %39, label %40, label %43

40:                                               ; preds = %33
  %41 = load ptr, ptr %13, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 -65536
  store ptr %42, ptr %12, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %40, %33
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %45, i32 0, i32 1
  store ptr %44, ptr %46, align 8, !tbaa !13
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = ptrtoint ptr %47 to i64
  %50 = ptrtoint ptr %48 to i64
  %51 = sub i64 %49, %50
  %52 = trunc i64 %51 to i32
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %53, i32 0, i32 5
  store i32 %52, ptr %54, align 8, !tbaa !14
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %55, i32 0, i32 4
  store i32 2, ptr %56, align 4, !tbaa !15
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %57, i32 0, i32 3
  %59 = load i32, ptr %58, align 8, !tbaa !11
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %60, i32 0, i32 5
  %62 = load i32, ptr %61, align 8, !tbaa !14
  %63 = sub i32 %59, %62
  store i32 %63, ptr %14, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %69, %43
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 -8
  %68 = icmp ule ptr %65, %67
  br i1 %68, label %69, label %81

69:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = call i32 @LZ4_hashPosition(ptr noundef %70, i32 noundef 2)
  store i32 %71, ptr %16, align 4, !tbaa !9
  %72 = load i32, ptr %14, align 4, !tbaa !9
  %73 = load i32, ptr %16, align 4, !tbaa !9
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %74, i32 0, i32 0
  %76 = getelementptr inbounds [4096 x i32], ptr %75, i64 0, i64 0
  call void @LZ4_putIndexOnHash(i32 noundef %72, i32 noundef %73, ptr noundef %76, i32 noundef 2)
  %77 = load ptr, ptr %12, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i64 3
  store ptr %78, ptr %12, align 8, !tbaa !5
  %79 = load i32, ptr %14, align 4, !tbaa !9
  %80 = add i32 %79, 3
  store i32 %80, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %64, !llvm.loop !16

81:                                               ; preds = %64
  %82 = load i32, ptr %9, align 4, !tbaa !9
  %83 = icmp eq i32 %82, 1
  br i1 %83, label %84, label %126

84:                                               ; preds = %81
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %85, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !13
  store ptr %87, ptr %12, align 8, !tbaa !5
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %88, i32 0, i32 3
  %90 = load i32, ptr %89, align 8, !tbaa !11
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %91, i32 0, i32 5
  %93 = load i32, ptr %92, align 8, !tbaa !14
  %94 = sub i32 %90, %93
  store i32 %94, ptr %14, align 4, !tbaa !9
  br label %95

95:                                               ; preds = %120, %84
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = load ptr, ptr %13, align 8, !tbaa !5
  %98 = getelementptr inbounds i8, ptr %97, i64 -8
  %99 = icmp ule ptr %96, %98
  br i1 %99, label %100, label %125

100:                                              ; preds = %95
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %101 = load ptr, ptr %12, align 8, !tbaa !5
  %102 = call i32 @LZ4_hashPosition(ptr noundef %101, i32 noundef 2)
  store i32 %102, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %103, i32 0, i32 3
  %105 = load i32, ptr %104, align 8, !tbaa !11
  %106 = sub i32 %105, 65536
  store i32 %106, ptr %18, align 4, !tbaa !9
  %107 = load i32, ptr %17, align 4, !tbaa !9
  %108 = load ptr, ptr %10, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %108, i32 0, i32 0
  %110 = getelementptr inbounds [4096 x i32], ptr %109, i64 0, i64 0
  %111 = call i32 @LZ4_getIndexOnHash(i32 noundef %107, ptr noundef %110, i32 noundef 2)
  %112 = load i32, ptr %18, align 4, !tbaa !9
  %113 = icmp ule i32 %111, %112
  br i1 %113, label %114, label %120

114:                                              ; preds = %100
  %115 = load i32, ptr %14, align 4, !tbaa !9
  %116 = load i32, ptr %17, align 4, !tbaa !9
  %117 = load ptr, ptr %10, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %117, i32 0, i32 0
  %119 = getelementptr inbounds [4096 x i32], ptr %118, i64 0, i64 0
  call void @LZ4_putIndexOnHash(i32 noundef %115, i32 noundef %116, ptr noundef %119, i32 noundef 2)
  br label %120

120:                                              ; preds = %114, %100
  %121 = load ptr, ptr %12, align 8, !tbaa !5
  %122 = getelementptr inbounds i8, ptr %121, i32 1
  store ptr %122, ptr %12, align 8, !tbaa !5
  %123 = load i32, ptr %14, align 4, !tbaa !9
  %124 = add i32 %123, 1
  store i32 %124, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %95, !llvm.loop !18

125:                                              ; preds = %95
  br label %126

126:                                              ; preds = %125, %81
  %127 = load ptr, ptr %10, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %127, i32 0, i32 5
  %129 = load i32, ptr %128, align 8, !tbaa !14
  store i32 %129, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %130

130:                                              ; preds = %126, %32
  call void @llvm.lifetime.end.p0(i64 4, 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 8, ptr %10) #3
  %131 = load i32, ptr %5, align 4
  ret i32 %131
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @LZ4_hashPosition(ptr noundef, i32 noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @LZ4_putIndexOnHash(i32 noundef, i32 noundef, ptr noundef, i32 noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @LZ4_getIndexOnHash(i32 noundef, ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { alwaysinline 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, !10, i64 16400}
!12 = !{!"LZ4_stream_t_internal", !7, i64 0, !6, i64 16384, !6, i64 16392, !10, i64 16400, !10, i64 16404, !10, i64 16408}
!13 = !{!12, !6, i64 16384}
!14 = !{!12, !10, i64 16408}
!15 = !{!12, !10, i64 16404}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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

; Function Attrs: nounwind uwtable
define dso_local i32 @LZ4_loadDict_internal(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  tail call void @LZ4_resetStream(ptr noundef %0)
  %5 = getelementptr inbounds i8, ptr %0, i64 16400
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = add i32 %6, 65536
  store i32 %7, ptr %5, align 8, !tbaa !5
  %8 = icmp slt i32 %2, 8
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %4
  %10 = zext nneg i32 %2 to i64
  %11 = getelementptr inbounds i8, ptr %1, i64 %10
  %12 = ptrtoint ptr %11 to i64
  %13 = icmp ugt i32 %2, 65536
  %14 = getelementptr inbounds i8, ptr %11, i64 -65536
  %spec.select = select i1 %13, ptr %14, ptr %1
  %15 = getelementptr inbounds i8, ptr %0, i64 16384
  store ptr %spec.select, ptr %15, align 8, !tbaa !11
  %16 = ptrtoint ptr %spec.select to i64
  %17 = sub i64 %12, %16
  %18 = trunc i64 %17 to i32
  %19 = getelementptr inbounds i8, ptr %0, i64 16408
  store i32 %18, ptr %19, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %0, i64 16404
  store i32 2, ptr %20, align 4, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %11, i64 -8
  %.not49 = icmp ugt ptr %spec.select, %21
  br i1 %.not49, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %9
  %22 = sub i32 %7, %18
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.151 = phi ptr [ %24, %.lr.ph ], [ %spec.select, %.lr.ph.preheader ]
  %.04450 = phi i32 [ %25, %.lr.ph ], [ %22, %.lr.ph.preheader ]
  %23 = tail call i32 @LZ4_hashPosition(ptr noundef %.151, i32 noundef 2)
  tail call void @LZ4_putIndexOnHash(i32 noundef %.04450, i32 noundef %23, ptr noundef %0, i32 noundef 2)
  %24 = getelementptr inbounds i8, ptr %.151, i64 3
  %25 = add i32 %.04450, 3
  %.not = icmp ugt ptr %24, %21
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !14

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre57.pre = load i32, ptr %19, align 8, !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %9
  %.pre57 = phi i32 [ %.pre57.pre, %._crit_edge.loopexit ], [ %18, %9 ]
  %26 = icmp eq i32 %3, 1
  br i1 %26, label %27, label %.loopexit

27:                                               ; preds = %._crit_edge
  %28 = load ptr, ptr %15, align 8, !tbaa !11
  %.not4752 = icmp ugt ptr %28, %21
  br i1 %.not4752, label %.loopexit, label %.lr.ph56.preheader

.lr.ph56.preheader:                               ; preds = %27
  %29 = load i32, ptr %5, align 8, !tbaa !5
  %30 = sub i32 %29, %.pre57
  br label %.lr.ph56

.lr.ph56:                                         ; preds = %.lr.ph56.preheader, %36
  %.254 = phi ptr [ %37, %36 ], [ %28, %.lr.ph56.preheader ]
  %.14553 = phi i32 [ %38, %36 ], [ %30, %.lr.ph56.preheader ]
  %31 = tail call i32 @LZ4_hashPosition(ptr noundef %.254, i32 noundef 2)
  %32 = load i32, ptr %5, align 8, !tbaa !5
  %33 = add i32 %32, -65536
  %34 = tail call i32 @LZ4_getIndexOnHash(i32 noundef %31, ptr noundef nonnull %0, i32 noundef 2)
  %.not48 = icmp ugt i32 %34, %33
  br i1 %.not48, label %36, label %35

35:                                               ; preds = %.lr.ph56
  tail call void @LZ4_putIndexOnHash(i32 noundef %.14553, i32 noundef %31, ptr noundef nonnull %0, i32 noundef 2)
  br label %36

36:                                               ; preds = %35, %.lr.ph56
  %37 = getelementptr inbounds i8, ptr %.254, i64 1
  %38 = add i32 %.14553, 1
  %.not47 = icmp ugt ptr %37, %21
  br i1 %.not47, label %.loopexit.loopexit, label %.lr.ph56, !llvm.loop !16

.loopexit.loopexit:                               ; preds = %36
  %.pre = load i32, ptr %19, align 8, !tbaa !12
  br label %.loopexit

.loopexit:                                        ; preds = %._crit_edge, %27, %.loopexit.loopexit, %4
  %.0 = phi i32 [ 0, %4 ], [ %.pre, %.loopexit.loopexit ], [ %.pre57, %27 ], [ %.pre57, %._crit_edge ]
  ret i32 %.0
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @LZ4_hashPosition(ptr noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @LZ4_getIndexOnHash(i32 noundef, ptr 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 = { alwaysinline 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, !10, i64 16400}
!6 = !{!"LZ4_stream_t_internal", !7, i64 0, !9, i64 16384, !9, i64 16392, !10, i64 16400, !10, i64 16404, !10, i64 16408}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!6, !9, i64 16384}
!12 = !{!6, !10, i64 16408}
!13 = !{!6, !10, i64 16404}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass