; 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.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: nounwind uwtable
define dso_local void @LZ4_resetStreamHC_fast(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %6, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.LZ4HC_CCtx_internal, ptr %7, i32 0, i32 10
  %9 = load i8, ptr %8, align 1, !tbaa !11
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call ptr @LZ4_initStreamHC(ptr noundef %12, i64 noundef 262200)
  br label %35

14:                                               ; preds = %2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.LZ4HC_CCtx_internal, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.LZ4HC_CCtx_internal, ptr %18, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = ptrtoint ptr %17 to i64
  %22 = ptrtoint ptr %20 to i64
  %23 = sub i64 %21, %22
  %24 = trunc i64 %23 to i32
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.LZ4HC_CCtx_internal, ptr %25, i32 0, i32 5
  %27 = load i32, ptr %26, align 8, !tbaa !16
  %28 = add i32 %27, %24
  store i32 %28, ptr %26, align 8, !tbaa !16
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.LZ4HC_CCtx_internal, ptr %29, i32 0, i32 3
  store ptr null, ptr %30, align 8, !tbaa !15
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.LZ4HC_CCtx_internal, ptr %31, i32 0, i32 2
  store ptr null, ptr %32, align 8, !tbaa !14
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.LZ4HC_CCtx_internal, ptr %33, i32 0, i32 11
  store ptr null, ptr %34, align 8, !tbaa !17
  br label %35

35:                                               ; preds = %14, %11
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !9
  call void @LZ4_setCompressionLevel(ptr noundef %36, i32 noundef %37)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @LZ4_setCompressionLevel(ptr 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 = { 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, !7, i64 262183}
!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 = !{!12, !6, i64 262144}
!15 = !{!12, !6, i64 262152}
!16 = !{!12, !10, i64 262168}
!17 = !{!12, !6, i64 262184}


; 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 @LZ4_resetStreamHC_fast(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 262183
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %7, label %5

5:                                                ; preds = %2
  %6 = tail call ptr @LZ4_initStreamHC(ptr noundef nonnull %0, i64 noundef 262200)
  br label %20

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 262144
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %0, i64 262152
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = ptrtoint ptr %9 to i64
  %13 = ptrtoint ptr %11 to i64
  %14 = sub i64 %12, %13
  %15 = trunc i64 %14 to i32
  %16 = getelementptr inbounds i8, ptr %0, i64 262168
  %17 = load i32, ptr %16, align 8, !tbaa !14
  %18 = add i32 %17, %15
  store i32 %18, ptr %16, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %0, i64 262184
  store ptr null, ptr %19, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %8, i8 0, i64 16, i1 false)
  br label %20

20:                                               ; preds = %7, %5
  tail call void @LZ4_setCompressionLevel(ptr noundef nonnull %0, i32 noundef %1)
  ret void
}

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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, !7, i64 262183}
!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}
!13 = !{!6, !9, i64 262152}
!14 = !{!6, !10, i64 262168}
!15 = !{!6, !9, i64 262184}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,ReassociatePass,SROAPass,TailCallElimPass