; 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_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] }
%struct.lzfse_match = type { i64, i64, i32 }
%struct.lzfse_history_set = type { [4 x i32], [4 x i32] }

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.lzfse_encode_translate = external hidden unnamed_addr constant [64 x i8], align 1

; 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 @lzfse_encode_translate(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = icmp sge i64 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  br label %16

15:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 610, ptr noundef @__PRETTY_FUNCTION__.lzfse_encode_translate) #3
  unreachable

16:                                               ; preds = %14
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  store i32 0, ptr %3, align 4
  br label %107

20:                                               ; preds = %16
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.lzfse_encoder_state, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %24, i64 %21
  store ptr %25, ptr %23, align 8, !tbaa !11
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.lzfse_encoder_state, ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = sub nsw i64 %29, %26
  store i64 %30, ptr %28, align 8, !tbaa !15
  %31 = load i64, ptr %5, align 8, !tbaa !9
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.lzfse_encoder_state, ptr %32, i32 0, i32 3
  %34 = load i64, ptr %33, align 8, !tbaa !16
  %35 = sub nsw i64 %34, %31
  store i64 %35, ptr %33, align 8, !tbaa !16
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.lzfse_encoder_state, ptr %37, i32 0, i32 4
  %39 = load i64, ptr %38, align 8, !tbaa !17
  %40 = sub nsw i64 %39, %36
  store i64 %40, ptr %38, align 8, !tbaa !17
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.lzfse_encoder_state, ptr %42, i32 0, i32 2
  %44 = load i64, ptr %43, align 8, !tbaa !18
  %45 = sub nsw i64 %44, %41
  store i64 %45, ptr %43, align 8, !tbaa !18
  %46 = load i64, ptr %5, align 8, !tbaa !9
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.lzfse_encoder_state, ptr %47, i32 0, i32 8
  %49 = getelementptr inbounds %struct.lzfse_match, ptr %48, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !19
  %51 = sub nsw i64 %50, %46
  store i64 %51, ptr %49, align 8, !tbaa !19
  %52 = load i64, ptr %5, align 8, !tbaa !9
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.lzfse_encoder_state, ptr %53, i32 0, i32 8
  %55 = getelementptr inbounds %struct.lzfse_match, ptr %54, i32 0, i32 1
  %56 = load i64, ptr %55, align 8, !tbaa !20
  %57 = sub nsw i64 %56, %52
  store i64 %57, ptr %55, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 -1048556, ptr %6, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !21
  br label %58

58:                                               ; preds = %103, %20
  %59 = load i32, ptr %7, align 4, !tbaa !21
  %60 = icmp slt i32 %59, 16384
  br i1 %60, label %62, label %61

61:                                               ; preds = %58
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %106

62:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.lzfse_encoder_state, ptr %63, i32 0, i32 15
  %65 = load i32, ptr %7, align 4, !tbaa !21
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [16384 x %struct.lzfse_history_set], ptr %64, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.lzfse_history_set, ptr %67, i32 0, i32 0
  %69 = getelementptr inbounds [4 x i32], ptr %68, i64 0, i64 0
  store ptr %69, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !21
  br label %70

70:                                               ; preds = %99, %62
  %71 = load i32, ptr %10, align 4, !tbaa !21
  %72 = icmp slt i32 %71, 4
  br i1 %72, label %74, label %73

73:                                               ; preds = %70
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %102

74:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = load i32, ptr %10, align 4, !tbaa !21
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr %75, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !21
  %80 = sext i32 %79 to i64
  %81 = load i64, ptr %5, align 8, !tbaa !9
  %82 = sub nsw i64 %80, %81
  store i64 %82, ptr %11, align 8, !tbaa !9
  %83 = load i64, ptr %11, align 8, !tbaa !9
  %84 = load i32, ptr %6, align 4, !tbaa !21
  %85 = sext i32 %84 to i64
  %86 = icmp slt i64 %83, %85
  br i1 %86, label %87, label %90

87:                                               ; preds = %74
  %88 = load i32, ptr %6, align 4, !tbaa !21
  %89 = sext i32 %88 to i64
  br label %92

90:                                               ; preds = %74
  %91 = load i64, ptr %11, align 8, !tbaa !9
  br label %92

92:                                               ; preds = %90, %87
  %93 = phi i64 [ %89, %87 ], [ %91, %90 ]
  %94 = trunc i64 %93 to i32
  %95 = load ptr, ptr %9, align 8, !tbaa !5
  %96 = load i32, ptr %10, align 4, !tbaa !21
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds i32, ptr %95, i64 %97
  store i32 %94, ptr %98, align 4, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %99

99:                                               ; preds = %92
  %100 = load i32, ptr %10, align 4, !tbaa !21
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %10, align 4, !tbaa !21
  br label %70, !llvm.loop !22

102:                                              ; preds = %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %7, align 4, !tbaa !21
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %7, align 4, !tbaa !21
  br label %58, !llvm.loop !24

106:                                              ; preds = %61
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %107

107:                                              ; preds = %106, %19
  %108 = load i32, ptr %3, align 4
  ret i32 %108
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(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 = { noreturn nounwind "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 = { noreturn nounwind }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !13, i64 64, !14, i64 88, !14, i64 92, !7, i64 96, !7, i64 40096, !7, i64 80096, !7, i64 120096, !7, i64 160096}
!13 = !{!"", !10, i64 0, !10, i64 8, !14, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !10, i64 8}
!16 = !{!12, !10, i64 24}
!17 = !{!12, !10, i64 32}
!18 = !{!12, !10, i64 16}
!19 = !{!12, !10, i64 64}
!20 = !{!12, !10, i64 72}
!21 = !{!14, !14, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


; 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] }

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.lzfse_encode_translate = external hidden unnamed_addr constant [64 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @lzfse_encode_translate(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i64 %1, -1
  br i1 %3, label %5, label %4

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 610, ptr noundef nonnull @__PRETTY_FUNCTION__.lzfse_encode_translate) #3
  unreachable

5:                                                ; preds = %2
  %6 = icmp eq i64 %1, 0
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %5
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 %1
  store ptr %9, ptr %0, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load <2 x i64>, ptr %11, align 8, !tbaa !13
  %13 = insertelement <2 x i64> poison, i64 %1, i64 0
  %14 = shufflevector <2 x i64> %13, <2 x i64> poison, <2 x i32> zeroinitializer
  %15 = sub nsw <2 x i64> %12, %14
  store <2 x i64> %15, ptr %11, align 8, !tbaa !13
  %16 = load <2 x i64>, ptr %10, align 8, !tbaa !13
  %17 = sub nsw <2 x i64> %16, %14
  store <2 x i64> %17, ptr %10, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %0, i64 64
  %19 = load <2 x i64>, ptr %18, align 8, !tbaa !13
  %20 = sub nsw <2 x i64> %19, %14
  store <2 x i64> %20, ptr %18, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %0, i64 160096
  br label %22

22:                                               ; preds = %7, %22
  %indvars.iv = phi i64 [ 0, %7 ], [ %indvars.iv.next, %22 ]
  %23 = getelementptr inbounds [16384 x %struct.lzfse_history_set], ptr %21, i64 0, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = sext i32 %24 to i64
  %26 = sub nsw i64 %25, %1
  %27 = tail call i64 @llvm.smax.i64(i64 %26, i64 -1048556)
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr %23, align 4, !tbaa !14
  %29 = getelementptr inbounds i8, ptr %23, i64 4
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %31 = sext i32 %30 to i64
  %32 = sub nsw i64 %31, %1
  %33 = tail call i64 @llvm.smax.i64(i64 %32, i64 -1048556)
  %34 = trunc i64 %33 to i32
  store i32 %34, ptr %29, align 4, !tbaa !14
  %35 = getelementptr inbounds i8, ptr %23, i64 8
  %36 = load i32, ptr %35, align 4, !tbaa !14
  %37 = sext i32 %36 to i64
  %38 = sub nsw i64 %37, %1
  %39 = tail call i64 @llvm.smax.i64(i64 %38, i64 -1048556)
  %40 = trunc i64 %39 to i32
  store i32 %40, ptr %35, align 4, !tbaa !14
  %41 = getelementptr inbounds i8, ptr %23, i64 12
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = sext i32 %42 to i64
  %44 = sub nsw i64 %43, %1
  %45 = tail call i64 @llvm.smax.i64(i64 %44, i64 -1048556)
  %46 = trunc i64 %45 to i32
  store i32 %46, ptr %41, align 4, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 16384
  br i1 %exitcond.not, label %.loopexit, label %22, !llvm.loop !15

.loopexit:                                        ; preds = %22, %5
  ret i32 0
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #2

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 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { noreturn 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, !7, i64 0}
!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 = !{!10, !10, i64 0}
!14 = !{!12, !12, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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