; LLVM IR from vczh/herodb :: Kernel/Source/Vlpp.ll (ZN2vl6stream12TestEncodingEPhlRNS0_10BomEncoder8EncodingERb)

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

@.str.576 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.577 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.578 = external hidden unnamed_addr constant [3 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 willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2vl6stream9CanBeMbcsEPhl(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2vl6stream9CanBeUtf8EPhl(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2vl6stream10CanBeUtf16EPhl(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2vl6stream12CanBeUtf16BEEPhl(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2vl6stream12TestEncodingEPhlRNS0_10BomEncoder8EncodingERb(ptr noundef %0, i64 noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 1 dereferenceable(1) %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp sge i64 %13, 3
  br i1 %14, label %15, label %22

15:                                               ; preds = %4
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call i32 @strncmp(ptr noundef %16, ptr noundef @.str.576, i64 noundef 3) #3
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %15
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 1, ptr %20, align 4, !tbaa !11
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 1, ptr %21, align 1, !tbaa !13
  br label %83

22:                                               ; preds = %15, %4
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = icmp sge i64 %23, 2
  br i1 %24, label %25, label %32

25:                                               ; preds = %22
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i32 @strncmp(ptr noundef %26, ptr noundef @.str.577, i64 noundef 2) #3
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %32

29:                                               ; preds = %25
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 2, ptr %30, align 4, !tbaa !11
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 1, ptr %31, align 1, !tbaa !13
  br label %82

32:                                               ; preds = %25, %22
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = icmp sge i64 %33, 2
  br i1 %34, label %35, label %42

35:                                               ; preds = %32
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call i32 @strncmp(ptr noundef %36, ptr noundef @.str.578, i64 noundef 2) #3
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %35
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 3, ptr %40, align 4, !tbaa !11
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 1, ptr %41, align 1, !tbaa !13
  br label %81

42:                                               ; preds = %35, %32
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %43, align 4, !tbaa !11
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 1, ptr %44, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = call noundef zeroext i1 @_ZN2vl6stream9CanBeMbcsEPhl(ptr noundef %45, i64 noundef %46)
  %48 = zext i1 %47 to i8
  store i8 %48, ptr %9, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = call noundef zeroext i1 @_ZN2vl6stream9CanBeUtf8EPhl(ptr noundef %49, i64 noundef %50)
  %52 = zext i1 %51 to i8
  store i8 %52, ptr %10, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #4
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = call noundef zeroext i1 @_ZN2vl6stream10CanBeUtf16EPhl(ptr noundef %53, i64 noundef %54)
  %56 = zext i1 %55 to i8
  store i8 %56, ptr %11, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #4
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load i64, ptr %6, align 8, !tbaa !9
  %59 = call noundef zeroext i1 @_ZN2vl6stream12CanBeUtf16BEEPhl(ptr noundef %57, i64 noundef %58)
  %60 = zext i1 %59 to i8
  store i8 %60, ptr %12, align 1, !tbaa !13
  %61 = load i8, ptr %10, align 1, !tbaa !13, !range !15, !noundef !16
  %62 = trunc i8 %61 to i1
  br i1 %62, label %63, label %65

63:                                               ; preds = %42
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 1, ptr %64, align 4, !tbaa !11
  br label %65

65:                                               ; preds = %63, %42
  %66 = load i8, ptr %11, align 1, !tbaa !13, !range !15, !noundef !16
  %67 = trunc i8 %66 to i1
  br i1 %67, label %68, label %70

68:                                               ; preds = %65
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 2, ptr %69, align 4, !tbaa !11
  br label %70

70:                                               ; preds = %68, %65
  %71 = load i8, ptr %12, align 1, !tbaa !13, !range !15, !noundef !16
  %72 = trunc i8 %71 to i1
  br i1 %72, label %73, label %75

73:                                               ; preds = %70
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 3, ptr %74, align 4, !tbaa !11
  br label %75

75:                                               ; preds = %73, %70
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = load i32, ptr %76, align 4, !tbaa !11
  %78 = icmp eq i32 %77, 0
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = zext i1 %78 to i8
  store i8 %80, ptr %79, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  br label %81

81:                                               ; preds = %75, %39
  br label %82

82:                                               ; preds = %81, %29
  br label %83

83:                                               ; preds = %82, %19
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 = { mustprogress 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 #3 = { nounwind willreturn memory(read) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTSN2vl6stream10BomEncoder8EncodingE", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}


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

@.str.576 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.577 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.578 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2vl6stream9CanBeMbcsEPhl(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2vl6stream9CanBeUtf8EPhl(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2vl6stream10CanBeUtf16EPhl(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2vl6stream12CanBeUtf16BEEPhl(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2vl6stream12TestEncodingEPhlRNS0_10BomEncoder8EncodingERb(ptr noundef %0, i64 noundef %1, ptr nocapture noundef nonnull align 4 dereferenceable(4) %2, ptr nocapture noundef nonnull writeonly align 1 dereferenceable(1) %3) local_unnamed_addr #1 {
  %5 = icmp sgt i64 %1, 2
  br i1 %5, label %6, label %10

6:                                                ; preds = %4
  %7 = tail call i32 @strncmp(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str.576, i64 noundef 3) #2
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %.thread

9:                                                ; preds = %6
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %28

10:                                               ; preds = %4
  %11 = icmp eq i64 %1, 2
  br i1 %11, label %.thread, label %.critedge

.thread:                                          ; preds = %6, %10
  %12 = tail call i32 @strncmp(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str.577, i64 noundef 2) #2
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %.thread
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %28

15:                                               ; preds = %.thread
  %16 = tail call i32 @strncmp(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str.578, i64 noundef 2) #2
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %.critedge

18:                                               ; preds = %15
  store i32 3, ptr %2, align 4, !tbaa !5
  br label %28

.critedge:                                        ; preds = %10, %15
  store i32 0, ptr %2, align 4, !tbaa !5
  store i8 1, ptr %3, align 1, !tbaa !9
  %19 = tail call noundef zeroext i1 @_ZN2vl6stream9CanBeMbcsEPhl(ptr noundef %0, i64 noundef %1)
  %20 = tail call noundef zeroext i1 @_ZN2vl6stream9CanBeUtf8EPhl(ptr noundef %0, i64 noundef %1)
  %21 = tail call noundef zeroext i1 @_ZN2vl6stream10CanBeUtf16EPhl(ptr noundef %0, i64 noundef %1)
  %22 = tail call noundef zeroext i1 @_ZN2vl6stream12CanBeUtf16BEEPhl(ptr noundef %0, i64 noundef %1)
  %23 = or i1 %20, %21
  %24 = or i1 %23, %22
  br i1 %24, label %27, label %.critedge._crit_edge

.critedge._crit_edge:                             ; preds = %.critedge
  %.pre = load i32, ptr %2, align 4, !tbaa !5
  %25 = icmp eq i32 %.pre, 0
  %26 = zext i1 %25 to i8
  br label %28

27:                                               ; preds = %.critedge
  %spec.select = select i1 %21, i32 2, i32 1
  %spec.select29 = select i1 %22, i32 3, i32 %spec.select
  store i32 %spec.select29, ptr %2, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %27, %.critedge._crit_edge, %14, %18, %9
  %.sink = phi i8 [ 1, %14 ], [ 1, %18 ], [ 1, %9 ], [ %26, %.critedge._crit_edge ], [ 0, %27 ]
  store i8 %.sink, ptr %3, align 1, !tbaa !9
  ret void
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 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 willreturn memory(read) }

!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 = !{!"_ZTSN2vl6stream10BomEncoder8EncodingE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass