; LLVM IR from sylefeb/Silixel :: src/fstapi (fstapi)

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

; 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 @fstUtilityBinToEscConvertedLen(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %47, %2
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %50

13:                                               ; preds = %9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = zext i8 %18 to i32
  switch i32 %19, label %23 [
    i32 7, label %20
    i32 8, label %20
    i32 12, label %20
    i32 10, label %20
    i32 13, label %20
    i32 9, label %20
    i32 11, label %20
    i32 39, label %20
    i32 34, label %20
    i32 92, label %20
    i32 63, label %20
  ]

20:                                               ; preds = %13, %13, %13, %13, %13, %13, %13, %13, %13, %13, %13
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = add nsw i32 %21, 2
  store i32 %22, ptr %6, align 4, !tbaa !9
  br label %46

23:                                               ; preds = %13
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = zext i8 %28 to i32
  %30 = icmp sgt i32 %29, 32
  br i1 %30, label %31, label %42

31:                                               ; preds = %23
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %32, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = zext i8 %36 to i32
  %38 = icmp sle i32 %37, 126
  br i1 %38, label %39, label %42

39:                                               ; preds = %31
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %6, align 4, !tbaa !9
  br label %45

42:                                               ; preds = %31, %23
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = add nsw i32 %43, 4
  store i32 %44, ptr %6, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %42, %39
  br label %46

46:                                               ; preds = %45, %20
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %7, align 4, !tbaa !9
  br label %9, !llvm.loop !12

50:                                               ; preds = %9
  %51 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i32 %51
}

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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i32 @fstUtilityBinToEscConvertedLen(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 0
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %4 = icmp eq i32 %1, 1
  br i1 %4, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph

.lr.ph:                                           ; preds = %14, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %14 ]
  %.01315 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %15, %14 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %14 ]
  %5 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %6 = load i8, ptr %5, align 1, !tbaa !5
  switch i8 %6, label %7 [
    i8 7, label %.lr.ph.1
    i8 8, label %.lr.ph.1
    i8 12, label %.lr.ph.1
    i8 10, label %.lr.ph.1
    i8 13, label %.lr.ph.1
    i8 9, label %.lr.ph.1
    i8 11, label %.lr.ph.1
    i8 39, label %.lr.ph.1
    i8 34, label %.lr.ph.1
    i8 92, label %.lr.ph.1
    i8 63, label %.lr.ph.1
  ]

7:                                                ; preds = %.lr.ph
  %8 = add i8 %6, -33
  %or.cond = icmp ult i8 %8, 94
  %. = select i1 %or.cond, i32 1, i32 4
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %7, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph
  %.sink = phi i32 [ 2, %.lr.ph ], [ 2, %.lr.ph ], [ 2, %.lr.ph ], [ 2, %.lr.ph ], [ 2, %.lr.ph ], [ 2, %.lr.ph ], [ 2, %.lr.ph ], [ 2, %.lr.ph ], [ 2, %.lr.ph ], [ 2, %.lr.ph ], [ 2, %.lr.ph ], [ %., %7 ]
  %9 = add nuw nsw i32 %.01315, %.sink
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %10 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %11 = load i8, ptr %10, align 1, !tbaa !5
  switch i8 %11, label %12 [
    i8 7, label %14
    i8 8, label %14
    i8 12, label %14
    i8 10, label %14
    i8 13, label %14
    i8 9, label %14
    i8 11, label %14
    i8 39, label %14
    i8 34, label %14
    i8 92, label %14
    i8 63, label %14
  ]

12:                                               ; preds = %.lr.ph.1
  %13 = add i8 %11, -33
  %or.cond.1 = icmp ult i8 %13, 94
  %..1 = select i1 %or.cond.1, i32 1, i32 4
  br label %14

14:                                               ; preds = %12, %.lr.ph.1, %.lr.ph.1, %.lr.ph.1, %.lr.ph.1, %.lr.ph.1, %.lr.ph.1, %.lr.ph.1, %.lr.ph.1, %.lr.ph.1, %.lr.ph.1, %.lr.ph.1
  %.sink.1 = phi i32 [ 2, %.lr.ph.1 ], [ 2, %.lr.ph.1 ], [ 2, %.lr.ph.1 ], [ 2, %.lr.ph.1 ], [ 2, %.lr.ph.1 ], [ 2, %.lr.ph.1 ], [ 2, %.lr.ph.1 ], [ 2, %.lr.ph.1 ], [ 2, %.lr.ph.1 ], [ 2, %.lr.ph.1 ], [ 2, %.lr.ph.1 ], [ %..1, %12 ]
  %15 = add nuw nsw i32 %9, %.sink.1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !8

._crit_edge.loopexit.unr-lcssa:                   ; preds = %14, %.lr.ph.preheader
  %.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %15, %14 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %14 ]
  %.01315.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %15, %14 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %16 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.unr
  %17 = load i8, ptr %16, align 1, !tbaa !5
  switch i8 %17, label %18 [
    i8 7, label %._crit_edge.loopexit.epilog-lcssa
    i8 8, label %._crit_edge.loopexit.epilog-lcssa
    i8 12, label %._crit_edge.loopexit.epilog-lcssa
    i8 10, label %._crit_edge.loopexit.epilog-lcssa
    i8 13, label %._crit_edge.loopexit.epilog-lcssa
    i8 9, label %._crit_edge.loopexit.epilog-lcssa
    i8 11, label %._crit_edge.loopexit.epilog-lcssa
    i8 39, label %._crit_edge.loopexit.epilog-lcssa
    i8 34, label %._crit_edge.loopexit.epilog-lcssa
    i8 92, label %._crit_edge.loopexit.epilog-lcssa
    i8 63, label %._crit_edge.loopexit.epilog-lcssa
  ]

18:                                               ; preds = %.lr.ph.epil
  %19 = add i8 %17, -33
  %or.cond.epil = icmp ult i8 %19, 94
  %..epil = select i1 %or.cond.epil, i32 1, i32 4
  br label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %18, %.lr.ph.epil, %.lr.ph.epil, %.lr.ph.epil, %.lr.ph.epil, %.lr.ph.epil, %.lr.ph.epil, %.lr.ph.epil, %.lr.ph.epil, %.lr.ph.epil, %.lr.ph.epil, %.lr.ph.epil
  %.sink.epil = phi i32 [ 2, %.lr.ph.epil ], [ 2, %.lr.ph.epil ], [ 2, %.lr.ph.epil ], [ 2, %.lr.ph.epil ], [ 2, %.lr.ph.epil ], [ 2, %.lr.ph.epil ], [ 2, %.lr.ph.epil ], [ 2, %.lr.ph.epil ], [ 2, %.lr.ph.epil ], [ 2, %.lr.ph.epil ], [ 2, %.lr.ph.epil ], [ %..epil, %18 ]
  %20 = add nuw nsw i32 %.01315.unr, %.sink.epil
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %2
  %.013.lcssa = phi i32 [ 0, %2 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %20, %._crit_edge.loopexit.epilog-lcssa ]
  ret i32 %.013.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass