; LLVM IR from IOsonata/IOsonata :: src (utf8)

; 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: nounwind uwtable
define dso_local i32 @uft8towcs_octetcount(i8 noundef signext %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i8 %0, ptr %3, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  store i8 -4, ptr %4, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 6, ptr %5, align 4, !tbaa !8
  %7 = load i8, ptr %3, align 1, !tbaa !5
  %8 = sext i8 %7 to i32
  %9 = and i32 %8, 128
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %36

12:                                               ; preds = %1
  br label %13

13:                                               ; preds = %27, %12
  %14 = load i8, ptr %3, align 1, !tbaa !5
  %15 = sext i8 %14 to i32
  %16 = load i8, ptr %4, align 1, !tbaa !5
  %17 = sext i8 %16 to i32
  %18 = and i32 %15, %17
  %19 = load i8, ptr %4, align 1, !tbaa !5
  %20 = sext i8 %19 to i32
  %21 = icmp ne i32 %18, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %13
  %23 = load i32, ptr %5, align 4, !tbaa !8
  %24 = icmp sgt i32 %23, 0
  br label %25

25:                                               ; preds = %22, %13
  %26 = phi i1 [ false, %13 ], [ %24, %22 ]
  br i1 %26, label %27, label %34

27:                                               ; preds = %25
  %28 = load i32, ptr %5, align 4, !tbaa !8
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr %5, align 4, !tbaa !8
  %30 = load i8, ptr %4, align 1, !tbaa !5
  %31 = sext i8 %30 to i32
  %32 = shl i32 %31, 1
  %33 = trunc i32 %32 to i8
  store i8 %33, ptr %4, align 1, !tbaa !5
  br label %13, !llvm.loop !10

34:                                               ; preds = %25
  %35 = load i32, ptr %5, align 4, !tbaa !8
  store i32 %35, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %36

36:                                               ; preds = %34, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  %37 = load i32, ptr %2, align 4
  ret i32 %37
}

; 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 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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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(none) uwtable
define dso_local i32 @uft8towcs_octetcount(i8 noundef signext %0) local_unnamed_addr #0 {
  %2 = icmp sgt i8 %0, -1
  br i1 %2, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %.not = icmp ugt i8 %0, -5
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %.not14 = icmp ugt i8 %0, -9
  br i1 %.not14, label %.loopexit, label %.lr.ph.1, !llvm.loop !5

.lr.ph.1:                                         ; preds = %.lr.ph
  %.not15 = icmp ugt i8 %0, -17
  br i1 %.not15, label %.loopexit, label %.lr.ph.2, !llvm.loop !5

.lr.ph.2:                                         ; preds = %.lr.ph.1
  %.not16 = icmp ugt i8 %0, -33
  br i1 %.not16, label %.loopexit, label %.lr.ph.3, !llvm.loop !5

.lr.ph.3:                                         ; preds = %.lr.ph.2
  %.not17 = icmp ugt i8 %0, -65
  %spec.select = select i1 %.not17, i32 2, i32 1
  br label %.loopexit, !llvm.loop !5

.loopexit:                                        ; preds = %.lr.ph.3, %.lr.ph, %.lr.ph.1, %.lr.ph.2, %.preheader, %1
  %.010 = phi i32 [ 1, %1 ], [ 6, %.preheader ], [ 5, %.lr.ph ], [ 4, %.lr.ph.1 ], [ 3, %.lr.ph.2 ], [ %spec.select, %.lr.ph.3 ]
  ret i32 %.010
}

attributes #0 = { nofree norecurse nosync nounwind memory(none) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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