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

; 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.fse_encoder_entry = type { i16, i16, i16, i16 }

; Function Attrs: nounwind uwtable
define dso_local void @fse_init_encoder_table(i32 noundef %0, i32 noundef %1, ptr noalias noundef %2, ptr noalias noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = call i32 @llvm.ctlz.i32(i32 %15, i1 true)
  store i32 %16, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %88, %4
  %18 = load i32, ptr %11, align 4, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %91

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %23 = load ptr, ptr %7, align 8, !tbaa !9
  %24 = load i32, ptr %11, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i16, ptr %23, i64 %25
  %27 = load i16, ptr %26, align 2, !tbaa !11
  %28 = zext i16 %27 to i32
  store i32 %28, ptr %13, align 4, !tbaa !5
  %29 = load i32, ptr %13, align 4, !tbaa !5
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %22
  store i32 4, ptr %12, align 4
  br label %85

32:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %33 = load i32, ptr %13, align 4, !tbaa !5
  %34 = call i32 @llvm.ctlz.i32(i32 %33, i1 true)
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = sub nsw i32 %34, %35
  store i32 %36, ptr %14, align 4, !tbaa !5
  %37 = load i32, ptr %13, align 4, !tbaa !5
  %38 = load i32, ptr %14, align 4, !tbaa !5
  %39 = shl i32 %37, %38
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sub nsw i32 %39, %40
  %42 = trunc i32 %41 to i16
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = load i32, ptr %11, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds %struct.fse_encoder_entry, ptr %43, i64 %45
  %47 = getelementptr inbounds %struct.fse_encoder_entry, ptr %46, i32 0, i32 0
  store i16 %42, ptr %47, align 2, !tbaa !13
  %48 = load i32, ptr %14, align 4, !tbaa !5
  %49 = trunc i32 %48 to i16
  %50 = load ptr, ptr %8, align 8, !tbaa !9
  %51 = load i32, ptr %11, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.fse_encoder_entry, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.fse_encoder_entry, ptr %53, i32 0, i32 1
  store i16 %49, ptr %54, align 2, !tbaa !15
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = load i32, ptr %13, align 4, !tbaa !5
  %57 = sub nsw i32 %55, %56
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = load i32, ptr %14, align 4, !tbaa !5
  %60 = ashr i32 %58, %59
  %61 = add nsw i32 %57, %60
  %62 = trunc i32 %61 to i16
  %63 = load ptr, ptr %8, align 8, !tbaa !9
  %64 = load i32, ptr %11, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %struct.fse_encoder_entry, ptr %63, i64 %65
  %67 = getelementptr inbounds %struct.fse_encoder_entry, ptr %66, i32 0, i32 2
  store i16 %62, ptr %67, align 2, !tbaa !16
  %68 = load i32, ptr %9, align 4, !tbaa !5
  %69 = load i32, ptr %13, align 4, !tbaa !5
  %70 = sub nsw i32 %68, %69
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = load i32, ptr %14, align 4, !tbaa !5
  %73 = sub nsw i32 %72, 1
  %74 = ashr i32 %71, %73
  %75 = add nsw i32 %70, %74
  %76 = trunc i32 %75 to i16
  %77 = load ptr, ptr %8, align 8, !tbaa !9
  %78 = load i32, ptr %11, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds %struct.fse_encoder_entry, ptr %77, i64 %79
  %81 = getelementptr inbounds %struct.fse_encoder_entry, ptr %80, i32 0, i32 3
  store i16 %76, ptr %81, align 2, !tbaa !17
  %82 = load i32, ptr %13, align 4, !tbaa !5
  %83 = load i32, ptr %9, align 4, !tbaa !5
  %84 = add nsw i32 %83, %82
  store i32 %84, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  store i32 0, ptr %12, align 4
  br label %85

85:                                               ; preds = %32, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  %86 = load i32, ptr %12, align 4
  switch i32 %86, label %92 [
    i32 0, label %87
    i32 4, label %88
  ]

87:                                               ; preds = %85
  br label %88

88:                                               ; preds = %87, %85
  %89 = load i32, ptr %11, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %11, align 4, !tbaa !5
  br label %17, !llvm.loop !18

91:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void

92:                                               ; preds = %85
  unreachable
}

; 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 nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctlz.i32(i32, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 2, !12, i64 4, !12, i64 6}
!15 = !{!14, !12, i64 2}
!16 = !{!14, !12, i64 4}
!17 = !{!14, !12, i64 6}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.fse_encoder_entry = type { i16, i16, i16, i16 }

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @fse_init_encoder_table(i32 noundef %0, i32 noundef %1, ptr noalias nocapture noundef readonly %2, ptr noalias nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %0, i1 true)
  %6 = icmp sgt i32 %1, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %31, %4
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %31
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %31 ]
  %.033 = phi i32 [ 0, %.lr.ph.preheader ], [ %.1, %31 ]
  %7 = getelementptr inbounds i16, ptr %2, i64 %indvars.iv
  %8 = load i16, ptr %7, align 2, !tbaa !5
  %9 = icmp eq i16 %8, 0
  br i1 %9, label %31, label %10

10:                                               ; preds = %.lr.ph
  %11 = zext i16 %8 to i32
  %12 = tail call range(i32 16, 33) i32 @llvm.ctlz.i32(i32 %11, i1 true)
  %13 = sub nsw i32 %12, %5
  %14 = shl i32 %11, %13
  %15 = sub nsw i32 %14, %0
  %16 = trunc i32 %15 to i16
  %17 = getelementptr inbounds %struct.fse_encoder_entry, ptr %3, i64 %indvars.iv
  store i16 %16, ptr %17, align 2, !tbaa !9
  %18 = trunc nsw i32 %13 to i16
  %19 = getelementptr inbounds i8, ptr %17, i64 2
  store i16 %18, ptr %19, align 2, !tbaa !11
  %20 = sub nsw i32 %.033, %11
  %21 = ashr i32 %0, %13
  %22 = add nsw i32 %21, %20
  %23 = trunc i32 %22 to i16
  %24 = getelementptr inbounds i8, ptr %17, i64 4
  store i16 %23, ptr %24, align 2, !tbaa !12
  %25 = add nsw i32 %13, -1
  %26 = ashr i32 %0, %25
  %27 = add nsw i32 %26, %20
  %28 = trunc i32 %27 to i16
  %29 = getelementptr inbounds i8, ptr %17, i64 6
  store i16 %28, ptr %29, align 2, !tbaa !13
  %30 = add nsw i32 %.033, %11
  br label %31

31:                                               ; preds = %.lr.ph, %10
  %.1 = phi i32 [ %30, %10 ], [ %.033, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctlz.i32(i32, i1 immarg) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 2, !6, i64 4, !6, i64 6}
!11 = !{!10, !6, i64 2}
!12 = !{!10, !6, i64 4}
!13 = !{!10, !6, i64 6}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass