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

; 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
define dso_local i32 @LZ4_compress_HC_extStateHC_fastReset(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %16, ptr %14, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = call i64 @LZ4_streamHC_t_alignment()
  %19 = call i32 @LZ4_isAligned(ptr noundef %17, i64 noundef %18)
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %6
  store i32 0, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %45

22:                                               ; preds = %6
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load i32, ptr %13, align 4, !tbaa !9
  call void @LZ4_resetStreamHC_fast(ptr noundef %23, i32 noundef %24)
  %25 = load ptr, ptr %14, align 8, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  call void @LZ4HC_init_internal(ptr noundef %25, ptr noundef %26)
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = call i32 @LZ4_compressBound(i32 noundef %28)
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %31, label %38

31:                                               ; preds = %22
  %32 = load ptr, ptr %14, align 8, !tbaa !5
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = load i32, ptr %12, align 4, !tbaa !9
  %36 = load i32, ptr %13, align 4, !tbaa !9
  %37 = call i32 @LZ4HC_compress_generic(ptr noundef %32, ptr noundef %33, ptr noundef %34, ptr noundef %11, i32 noundef %35, i32 noundef %36, i32 noundef 1)
  store i32 %37, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %45

38:                                               ; preds = %22
  %39 = load ptr, ptr %14, align 8, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = load i32, ptr %13, align 4, !tbaa !9
  %44 = call i32 @LZ4HC_compress_generic(ptr noundef %39, ptr noundef %40, ptr noundef %41, ptr noundef %11, i32 noundef %42, i32 noundef %43, i32 noundef 0)
  store i32 %44, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %45

45:                                               ; preds = %38, %31, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %46 = load i32, ptr %7, align 4
  ret i32 %46
}

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

; Function Attrs: nounwind uwtable
declare hidden i64 @LZ4_streamHC_t_alignment() #1

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

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

declare i32 @LZ4_compressBound(i32 noundef) #2

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

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 = { "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}


; 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 i32 @LZ4_compress_HC_extStateHC_fastReset(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = alloca i32, align 4
  store i32 %3, ptr %7, align 4, !tbaa !5
  %8 = tail call i64 @LZ4_streamHC_t_alignment()
  %9 = tail call i32 @LZ4_isAligned(ptr noundef %0, i64 noundef %8)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %13, label %.sink.split

.sink.split:                                      ; preds = %6
  tail call void @LZ4_resetStreamHC_fast(ptr noundef %0, i32 noundef %5)
  tail call void @LZ4HC_init_internal(ptr noundef %0, ptr noundef %1)
  %10 = tail call i32 @LZ4_compressBound(i32 noundef %3) #2
  %11 = icmp sgt i32 %10, %4
  %. = zext i1 %11 to i32
  %12 = call i32 @LZ4HC_compress_generic(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef nonnull %7, i32 noundef %4, i32 noundef %5, i32 noundef %.)
  br label %13

13:                                               ; preds = %.sink.split, %6
  %.0 = phi i32 [ 0, %6 ], [ %12, %.sink.split ]
  ret i32 %.0
}

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

; Function Attrs: nounwind uwtable
declare hidden i64 @LZ4_streamHC_t_alignment() local_unnamed_addr #0

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

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

declare i32 @LZ4_compressBound(i32 noundef) local_unnamed_addr #1

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

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 = { "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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass