; LLVM IR from sylefeb/Silixel :: src/fstapi (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(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %15, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 2, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %16, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %17, i64 %19
  store ptr %20, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  call void @LZ4_resetStream(ptr noundef %21)
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = add i32 %24, 65536
  store i32 %25, ptr %23, align 8, !tbaa !11
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 8
  br i1 %27, label %28, label %29

28:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %81

29:                                               ; preds = %3
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = ptrtoint ptr %30 to i64
  %33 = ptrtoint ptr %31 to i64
  %34 = sub i64 %32, %33
  %35 = icmp sgt i64 %34, 65536
  br i1 %35, label %36, label %39

36:                                               ; preds = %29
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 -65536
  store ptr %38, ptr %10, align 8, !tbaa !5
  br label %39

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

60:                                               ; preds = %65, %39
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 -8
  %64 = icmp ule ptr %61, %63
  br i1 %64, label %65, label %77

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

77:                                               ; preds = %60
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %78, i32 0, i32 5
  %80 = load i32, ptr %79, align 8, !tbaa !14
  store i32 %80, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %81

81:                                               ; preds = %77, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %82 = load i32, ptr %4, align 4
  ret i32 %82
}

; 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

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


; 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(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  tail call void @LZ4_resetStream(ptr noundef %0)
  %4 = getelementptr inbounds i8, ptr %0, i64 16400
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = add i32 %5, 65536
  store i32 %6, ptr %4, align 8, !tbaa !5
  %7 = icmp slt i32 %2, 8
  br i1 %7, label %._crit_edge, label %8

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

.lr.ph.preheader:                                 ; preds = %8
  %21 = sub i32 %6, %17
  br label %.lr.ph

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

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

._crit_edge:                                      ; preds = %8, %._crit_edge.loopexit, %3
  %.0 = phi i32 [ 0, %3 ], [ %.pre, %._crit_edge.loopexit ], [ %17, %8 ]
  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

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


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