; LLVM IR from lzfse/lzfse :: src (lzfse_encode_base)

; 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.lzfse_match = type { i64, i64, i32 }
%struct.lzfse_history_set = type { [4 x i32], [4 x i32] }
%struct.lzfse_encoder_state = type { ptr, i64, i64, i64, i64, ptr, ptr, ptr, %struct.lzfse_match, i32, i32, [10000 x i32], [10000 x i32], [10000 x i32], [40000 x i8], [16384 x %struct.lzfse_history_set] }

; Function Attrs: nounwind uwtable
define dso_local i32 @lzfse_encode_init(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.lzfse_match, align 8
  %4 = alloca %struct.lzfse_history_set, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #4
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %20, %1
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 4
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %23

11:                                               ; preds = %7
  %12 = getelementptr inbounds %struct.lzfse_history_set, ptr %4, i32 0, i32 0
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 %14
  store i32 -1048556, ptr %15, align 4, !tbaa !9
  %16 = getelementptr inbounds %struct.lzfse_history_set, ptr %4, i32 0, i32 1
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [4 x i32], ptr %16, i64 0, i64 %18
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %11
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !11

23:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %34, %23
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 16384
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %37

28:                                               ; preds = %24
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.lzfse_encoder_state, ptr %29, i32 0, i32 15
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [16384 x %struct.lzfse_history_set], ptr %30, i64 0, i64 %32
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %33, ptr align 4 %4, i64 32, i1 false), !tbaa.struct !13
  br label %34

34:                                               ; preds = %28
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %6, align 4, !tbaa !9
  br label %24, !llvm.loop !15

37:                                               ; preds = %27
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.lzfse_encoder_state, ptr %38, i32 0, i32 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %39, ptr align 8 %3, i64 24, i1 false), !tbaa.struct !16
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.lzfse_encoder_state, ptr %40, i32 0, i32 2
  store i64 0, ptr %41, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #4
  ret i32 0
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; 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) #3

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i64 0, i64 16, !14, i64 16, i64 16, !14}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !12}
!16 = !{i64 0, i64 8, !17, i64 8, i64 8, !17, i64 16, i64 4, !9}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!20, !18, i64 16}
!20 = !{!"", !6, i64 0, !18, i64 8, !18, i64 16, !18, i64 24, !18, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !21, i64 64, !10, i64 88, !10, i64 92, !7, i64 96, !7, i64 40096, !7, i64 80096, !7, i64 120096, !7, i64 160096}
!21 = !{!"", !18, i64 0, !18, i64 8, !10, i64 16}


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

%struct.lzfse_history_set = type { [4 x i32], [4 x i32] }

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local noundef i32 @lzfse_encode_init(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
.preheader:
  %1 = getelementptr inbounds i8, ptr %0, i64 160096
  br label %5

2:                                                ; preds = %5
  %3 = getelementptr inbounds i8, ptr %0, i64 64
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %3, i8 0, i64 24, i1 false)
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 0, ptr %4, align 8, !tbaa !5
  ret i32 0

5:                                                ; preds = %5, %.preheader
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next.3, %5 ]
  %6 = getelementptr inbounds [16384 x %struct.lzfse_history_set], ptr %1, i64 0, i64 %indvars.iv
  store <4 x i32> <i32 -1048556, i32 -1048556, i32 -1048556, i32 -1048556>, ptr %6, align 8
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 16
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %.sroa.7.0..sroa_idx, i8 0, i64 16, i1 false)
  %7 = getelementptr inbounds [16384 x %struct.lzfse_history_set], ptr %1, i64 0, i64 %indvars.iv.next
  store <4 x i32> <i32 -1048556, i32 -1048556, i32 -1048556, i32 -1048556>, ptr %7, align 8
  %.sroa.7.0..sroa_idx.1 = getelementptr inbounds i8, ptr %7, i64 16
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %.sroa.7.0..sroa_idx.1, i8 0, i64 16, i1 false)
  %8 = getelementptr inbounds [16384 x %struct.lzfse_history_set], ptr %1, i64 0, i64 %indvars.iv.next.1
  store <4 x i32> <i32 -1048556, i32 -1048556, i32 -1048556, i32 -1048556>, ptr %8, align 8
  %.sroa.7.0..sroa_idx.2 = getelementptr inbounds i8, ptr %8, i64 16
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %.sroa.7.0..sroa_idx.2, i8 0, i64 16, i1 false)
  %9 = getelementptr inbounds [16384 x %struct.lzfse_history_set], ptr %1, i64 0, i64 %indvars.iv.next.2
  store <4 x i32> <i32 -1048556, i32 -1048556, i32 -1048556, i32 -1048556>, ptr %9, align 8
  %.sroa.7.0..sroa_idx.3 = getelementptr inbounds i8, ptr %9, i64 16
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 16384
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %.sroa.7.0..sroa_idx.3, i8 0, i64 16, i1 false)
  br i1 %exitcond.not.3, label %2, label %5, !llvm.loop !13
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: write) 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 = { mustprogress 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, !10, i64 16}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !11, i64 64, !12, i64 88, !12, i64 92, !8, i64 96, !8, i64 40096, !8, i64 80096, !8, i64 120096, !8, i64 160096}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"", !10, i64 0, !10, i64 8, !12, i64 16}
!12 = !{!"int", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass