; LLVM IR from catid/Zpng :: zstd (fse_compress)

; 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_symbolCompressionTransform = type { 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
define dso_local i64 @FSE_buildCTable_raw(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = shl i32 1, %16
  store i32 %17, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sub i32 %18, 1
  store i32 %19, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %20 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %20, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %21, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds i16, ptr %22, i64 2
  store ptr %23, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds i32, ptr %24, i64 1
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = lshr i32 %26, 1
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %25, i64 %28
  store ptr %29, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %30, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = icmp ult i32 %31, 1
  br i1 %32, label %33, label %34

33:                                               ; preds = %2
  store i64 -1, ptr %3, align 8
  store i32 1, ptr %14, align 4
  br label %87

34:                                               ; preds = %2
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = trunc i32 %35 to i16
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds i16, ptr %37, i64 -2
  store i16 %36, ptr %38, align 2, !tbaa !11
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = trunc i32 %39 to i16
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds i16, ptr %41, i64 -1
  store i16 %40, ptr %42, align 2, !tbaa !11
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %56, %34
  %44 = load i32, ptr %13, align 4, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = icmp ult i32 %44, %45
  br i1 %46, label %47, label %59

47:                                               ; preds = %43
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = add i32 %48, %49
  %51 = trunc i32 %50 to i16
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds i16, ptr %52, i64 %54
  store i16 %51, ptr %55, align 2, !tbaa !11
  br label %56

56:                                               ; preds = %47
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = add i32 %57, 1
  store i32 %58, ptr %13, align 4, !tbaa !9
  br label %43, !llvm.loop !13

59:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = shl i32 %60, 16
  %62 = load i32, ptr %5, align 4, !tbaa !9
  %63 = shl i32 1, %62
  %64 = sub i32 %61, %63
  store i32 %64, ptr %15, align 4, !tbaa !9
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %83, %59
  %66 = load i32, ptr %13, align 4, !tbaa !9
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = icmp ule i32 %66, %67
  br i1 %68, label %69, label %86

69:                                               ; preds = %65
  %70 = load i32, ptr %15, align 4, !tbaa !9
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  %72 = load i32, ptr %13, align 4, !tbaa !9
  %73 = zext i32 %72 to i64
  %74 = getelementptr inbounds %struct.FSE_symbolCompressionTransform, ptr %71, i64 %73
  %75 = getelementptr inbounds %struct.FSE_symbolCompressionTransform, ptr %74, i32 0, i32 1
  store i32 %70, ptr %75, align 4, !tbaa !15
  %76 = load i32, ptr %13, align 4, !tbaa !9
  %77 = sub i32 %76, 1
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = zext i32 %79 to i64
  %81 = getelementptr inbounds %struct.FSE_symbolCompressionTransform, ptr %78, i64 %80
  %82 = getelementptr inbounds %struct.FSE_symbolCompressionTransform, ptr %81, i32 0, i32 0
  store i32 %77, ptr %82, align 4, !tbaa !17
  br label %83

83:                                               ; preds = %69
  %84 = load i32, ptr %13, align 4, !tbaa !9
  %85 = add i32 %84, 1
  store i32 %85, ptr %13, align 4, !tbaa !9
  br label %65, !llvm.loop !18

86:                                               ; preds = %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  store i64 0, ptr %3, align 8
  store i32 1, ptr %14, align 4
  br label %87

87:                                               ; preds = %86, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %88 = load i64, ptr %3, align 8
  ret i64 %88
}

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 = { 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, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 4}
!16 = !{!"", !10, i64 0, !10, i64 4}
!17 = !{!16, !10, i64 0}
!18 = distinct !{!18, !14}


; 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_symbolCompressionTransform = type { i32, i32 }

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local range(i64 -1, 1) i64 @FSE_buildCTable_raw(ptr nocapture noundef writeonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = shl nuw i32 1, %1
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = lshr i32 %3, 1
  %6 = zext nneg i32 %5 to i64
  %7 = getelementptr inbounds i32, ptr %4, i64 %6
  %8 = icmp eq i32 %1, 0
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %2
  %10 = trunc i32 %1 to i16
  store i16 %10, ptr %0, align 2, !tbaa !5
  %11 = trunc i32 %3 to i16
  %12 = add i16 %11, -1
  %13 = getelementptr inbounds i8, ptr %0, i64 2
  store i16 %12, ptr %13, align 2, !tbaa !5
  %wide.trip.count = zext i32 %3 to i64
  %min.iters.check = icmp ult i32 %1, 4
  br i1 %min.iters.check, label %scalar.ph, label %vector.ph

vector.ph:                                        ; preds = %9
  %n.vec = and i64 %wide.trip.count, 4294967280
  %broadcast.splatinsert = insertelement <8 x i32> poison, i32 %3, i64 0
  %broadcast.splat = shufflevector <8 x i32> %broadcast.splatinsert, <8 x i32> poison, <8 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <8 x i32> [ <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <8 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8, i32 8, i32 8, i32 8, i32 8>
  %14 = add <8 x i32> %broadcast.splat, %vec.ind
  %15 = add <8 x i32> %broadcast.splat, %step.add
  %16 = trunc <8 x i32> %14 to <8 x i16>
  %17 = trunc <8 x i32> %15 to <8 x i16>
  %18 = getelementptr inbounds i16, ptr %4, i64 %index
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  store <8 x i16> %16, ptr %18, align 2, !tbaa !5
  store <8 x i16> %17, ptr %19, align 2, !tbaa !5
  %index.next = add nuw i64 %index, 16
  %vec.ind.next = add <8 x i32> %vec.ind, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
  %20 = icmp eq i64 %index.next, %n.vec
  br i1 %20, label %middle.block, label %vector.body, !llvm.loop !9

scalar.ph:                                        ; preds = %9, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ 0, %9 ]
  %21 = trunc nuw i64 %indvars.iv to i32
  %22 = add i32 %3, %21
  %23 = trunc i32 %22 to i16
  %24 = getelementptr inbounds i16, ptr %4, i64 %indvars.iv
  store i16 %23, ptr %24, align 2, !tbaa !5
  %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 %middle.block, label %scalar.ph, !llvm.loop !13

middle.block:                                     ; preds = %vector.body, %scalar.ph
  %25 = shl i32 %1, 16
  %26 = sub i32 %25, %3
  %min.iters.check46 = icmp eq i32 %1, 1
  br i1 %min.iters.check46, label %scalar.ph45, label %vector.ph47

vector.ph47:                                      ; preds = %middle.block
  %n.vec49 = and i64 %wide.trip.count, 4294967292
  %broadcast.splatinsert57 = insertelement <2 x i32> poison, i32 %26, i64 0
  %broadcast.splat58 = shufflevector <2 x i32> %broadcast.splatinsert57, <2 x i32> poison, <2 x i32> zeroinitializer
  br label %vector.body51

vector.body51:                                    ; preds = %vector.body51, %vector.ph47
  %index52 = phi i64 [ 0, %vector.ph47 ], [ %index.next60, %vector.body51 ]
  %vec.ind53 = phi <2 x i32> [ <i32 0, i32 1>, %vector.ph47 ], [ %vec.ind.next56, %vector.body51 ]
  %27 = or disjoint i64 %index52, 2
  %28 = getelementptr inbounds %struct.FSE_symbolCompressionTransform, ptr %7, i64 %index52
  %29 = getelementptr inbounds %struct.FSE_symbolCompressionTransform, ptr %7, i64 %27
  %30 = add <2 x i32> %vec.ind53, <i32 -1, i32 -1>
  %31 = add <2 x i32> %vec.ind53, <i32 1, i32 1>
  %interleaved.vec = shufflevector <2 x i32> %30, <2 x i32> %broadcast.splat58, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  store <4 x i32> %interleaved.vec, ptr %28, align 4, !tbaa !14
  %interleaved.vec59 = shufflevector <2 x i32> %31, <2 x i32> %broadcast.splat58, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  store <4 x i32> %interleaved.vec59, ptr %29, align 4, !tbaa !14
  %index.next60 = add nuw i64 %index52, 4
  %vec.ind.next56 = add <2 x i32> %vec.ind53, <i32 4, i32 4>
  %32 = icmp eq i64 %index.next60, %n.vec49
  br i1 %32, label %.loopexit, label %vector.body51, !llvm.loop !16

scalar.ph45:                                      ; preds = %middle.block, %scalar.ph45
  %indvars.iv38 = phi i64 [ %indvars.iv.next39, %scalar.ph45 ], [ 0, %middle.block ]
  %33 = getelementptr inbounds %struct.FSE_symbolCompressionTransform, ptr %7, i64 %indvars.iv38
  %34 = getelementptr inbounds i8, ptr %33, i64 4
  store i32 %26, ptr %34, align 4, !tbaa !17
  %35 = trunc nuw i64 %indvars.iv38 to i32
  %36 = add i32 %35, -1
  store i32 %36, ptr %33, align 4, !tbaa !19
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond42 = icmp eq i64 %indvars.iv.next39, %wide.trip.count
  br i1 %exitcond42, label %.loopexit, label %scalar.ph45, !llvm.loop !20

.loopexit:                                        ; preds = %vector.body51, %scalar.ph45, %2
  %.0 = phi i64 [ -1, %2 ], [ 0, %scalar.ph45 ], [ 0, %vector.body51 ]
  ret i64 %.0
}

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

!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 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !10, !11, !12}
!17 = !{!18, !15, i64 4}
!18 = !{!"", !15, i64 0, !15, i64 4}
!19 = !{!18, !15, i64 0}
!20 = distinct !{!20, !10, !12, !11}


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