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

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

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

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

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

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

64:                                               ; preds = %59
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds [4096 x i32], ptr %67, i64 0, i64 0
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  call void @LZ4_putPosition(ptr noundef %65, ptr noundef %68, i32 noundef 2, ptr noundef %69)
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 3
  store ptr %71, ptr %10, align 8, !tbaa !5
  br label %59, !llvm.loop !17

72:                                               ; preds = %59
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %73, i32 0, i32 6
  %75 = load i32, ptr %74, align 8, !tbaa !15
  store i32 %75, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %76

76:                                               ; preds = %72, %27
  call void @llvm.lifetime.end.p0(i64 8, 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
  %77 = load i32, ptr %4, align 4
  ret i32 %77
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @LZ4_putPosition(ptr noundef, ptr noundef, i32 noundef, ptr 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 16384}
!12 = !{!"LZ4_stream_t_internal", !7, i64 0, !10, i64 16384, !13, i64 16388, !13, i64 16390, !6, i64 16392, !6, i64 16400, !10, i64 16408}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !6, i64 16392}
!15 = !{!12, !10, i64 16408}
!16 = !{!12, !13, i64 16390}
!17 = distinct !{!17, !18}
!18 = !{!"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 16384
  %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 = zext i32 %6 to i64
  %15 = sub nsw i64 0, %14
  %16 = getelementptr inbounds i8, ptr %10, i64 %15
  %17 = getelementptr inbounds i8, ptr %0, i64 16392
  store ptr %spec.select, ptr %17, align 8, !tbaa !12
  %18 = ptrtoint ptr %spec.select to i64
  %19 = sub i64 %11, %18
  %20 = trunc i64 %19 to i32
  %21 = getelementptr inbounds i8, ptr %0, i64 16408
  store i32 %20, ptr %21, align 8, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %0, i64 16390
  store i16 2, ptr %22, align 2, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %10, i64 -8
  %.not26 = icmp ugt ptr %spec.select, %23
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.127 = phi ptr [ %24, %.lr.ph ], [ %spec.select, %8 ]
  tail call void @LZ4_putPosition(ptr noundef %.127, ptr noundef %0, i32 noundef 2, ptr noundef nonnull %16)
  %24 = getelementptr inbounds i8, ptr %.127, i64 3
  %.not = icmp ugt ptr %24, %23
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !15

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

._crit_edge:                                      ; preds = %8, %._crit_edge.loopexit, %3
  %.0 = phi i32 [ 0, %3 ], [ %.pre, %._crit_edge.loopexit ], [ %20, %8 ]
  ret i32 %.0
}

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


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