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

; 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.cParams_t = type { i32, i32, i32 }
%struct.LZ4HC_CCtx_internal = type { [32768 x i32], [65536 x i16], ptr, ptr, ptr, i32, i32, i32, i16, i8, i8, ptr }

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @LZ4_initStreamHC(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @LZ4_setCompressionLevel(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @LZ4_loadDictHC(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca %struct.cParams_t, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.cParams_t, align 4
  %11 = alloca { i64, i32 }, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %8) #4
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp sgt i32 %13, 65536
  br i1 %14, label %15, label %21

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = sub i64 %17, 65536
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 %18
  store ptr %20, ptr %5, align 8, !tbaa !5
  store i32 65536, ptr %6, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %15, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.LZ4HC_CCtx_internal, ptr %22, i32 0, i32 8
  %24 = load i16, ptr %23, align 4, !tbaa !11
  %25 = sext i16 %24 to i32
  store i32 %25, ptr %9, align 4, !tbaa !9
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call ptr @LZ4_initStreamHC(ptr noundef %26, i64 noundef 262200)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !9
  call void @LZ4_setCompressionLevel(ptr noundef %28, i32 noundef %29)
  call void @llvm.lifetime.start.p0(i64 12, ptr %10) #4
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = call { i64, i32 } @LZ4HC_getCLevelParams(i32 noundef %30)
  store { i64, i32 } %31, ptr %11, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 8 %11, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %10, i64 12, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 12, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  call void @LZ4HC_init_internal(ptr noundef %32, ptr noundef %33)
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %34, i64 %36
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.LZ4HC_CCtx_internal, ptr %38, i32 0, i32 2
  store ptr %37, ptr %39, align 8, !tbaa !15
  %40 = getelementptr inbounds %struct.cParams_t, ptr %8, i32 0, i32 0
  %41 = load i32, ptr %40, align 4, !tbaa !16
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %48

43:                                               ; preds = %21
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  call void @LZ4MID_fillHTable(ptr noundef %44, ptr noundef %45, i64 noundef %47)
  br label %58

48:                                               ; preds = %21
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = icmp sge i32 %49, 4
  br i1 %50, label %51, label %57

51:                                               ; preds = %48
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.LZ4HC_CCtx_internal, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  %56 = getelementptr inbounds i8, ptr %55, i64 -3
  call void @LZ4HC_Insert(ptr noundef %52, ptr noundef %56)
  br label %57

57:                                               ; preds = %51, %48
  br label %58

58:                                               ; preds = %57, %43
  %59 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 12, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i32 %59
}

; Function Attrs: nounwind uwtable
declare hidden { i64, i32 } @LZ4HC_getCLevelParams(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @LZ4MID_fillHTable(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @LZ4HC_Insert(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 #4 = { 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, !13, i64 262180}
!12 = !{!"LZ4HC_CCtx_internal", !7, i64 0, !7, i64 131072, !6, i64 262144, !6, i64 262152, !6, i64 262160, !10, i64 262168, !10, i64 262172, !10, i64 262176, !13, i64 262180, !7, i64 262182, !7, i64 262183, !6, i64 262184}
!13 = !{!"short", !7, i64 0}
!14 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9}
!15 = !{!12, !6, i64 262144}
!16 = !{!17, !10, i64 0}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, 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"

; Function Attrs: nounwind uwtable
declare hidden void @LZ4HC_init_internal(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @LZ4_initStreamHC(ptr noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef range(i32 -2147483648, 65537) i32 @LZ4_loadDictHC(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %2, 65536
  %5 = zext nneg i32 %2 to i64
  %6 = getelementptr i8, ptr %1, i64 %5
  %7 = getelementptr i8, ptr %6, i64 -65536
  %.023 = tail call i32 @llvm.smin.i32(i32 %2, i32 65536)
  %.0 = select i1 %4, ptr %7, ptr %1
  %8 = getelementptr inbounds i8, ptr %0, i64 262180
  %9 = load i16, ptr %8, align 4, !tbaa !5
  %10 = sext i16 %9 to i32
  %11 = tail call ptr @LZ4_initStreamHC(ptr noundef %0, i64 noundef 262200)
  tail call void @LZ4_setCompressionLevel(ptr noundef %0, i32 noundef %10)
  %12 = tail call { i64, i32 } @LZ4HC_getCLevelParams(i32 noundef %10)
  %.fca.0.extract = extractvalue { i64, i32 } %12, 0
  tail call void @LZ4HC_init_internal(ptr noundef %0, ptr noundef %.0)
  %13 = sext i32 %.023 to i64
  %14 = getelementptr inbounds i8, ptr %.0, i64 %13
  %15 = getelementptr inbounds i8, ptr %0, i64 262144
  store ptr %14, ptr %15, align 8, !tbaa !12
  %16 = and i64 %.fca.0.extract, 4294967295
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  tail call void @LZ4MID_fillHTable(ptr noundef nonnull %0, ptr noundef %.0, i64 noundef %13)
  br label %23

19:                                               ; preds = %3
  %20 = icmp sgt i32 %2, 3
  br i1 %20, label %21, label %23

21:                                               ; preds = %19
  %22 = getelementptr inbounds i8, ptr %14, i64 -3
  tail call void @LZ4HC_Insert(ptr noundef nonnull %0, ptr noundef nonnull %22)
  br label %23

23:                                               ; preds = %19, %21, %18
  ret i32 %.023
}

; Function Attrs: nounwind uwtable
declare hidden { i64, i32 } @LZ4HC_getCLevelParams(i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !11, i64 262180}
!6 = !{!"LZ4HC_CCtx_internal", !7, i64 0, !7, i64 131072, !9, i64 262144, !9, i64 262152, !9, i64 262160, !10, i64 262168, !10, i64 262172, !10, i64 262176, !11, i64 262180, !7, i64 262182, !7, i64 262183, !9, i64 262184}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!6, !9, i64 262144}


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