; LLVM IR from facebook/hermes :: external/llvh/lib/Demangle/MicrosoftDemangle.ll (Z17guessCharByteSizePKhjj)

; 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 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [98 x i8], align 1
@__PRETTY_FUNCTION__._Z17guessCharByteSizePKhjj = external hidden unnamed_addr constant [76 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z22countTrailingNullBytesPKhi(ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z18countEmbeddedNullsPKhj(ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z17guessCharByteSizePKhjj(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp ugt i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  br label %16

14:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1245, ptr noundef @__PRETTY_FUNCTION__._Z17guessCharByteSizePKhjj) #3
  unreachable

15:                                               ; No predecessors!
  br label %16

16:                                               ; preds = %15, %13
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = urem i32 %17, 2
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  store i32 1, ptr %4, align 4
  br label %55

21:                                               ; preds = %16
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = icmp ult i32 %22, 32
  br i1 %23, label %24, label %37

24:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = call noundef i32 @_Z22countTrailingNullBytesPKhi(ptr noundef %25, i32 noundef %26)
  store i32 %27, ptr %8, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp uge i32 %28, 4
  br i1 %29, label %30, label %31

30:                                               ; preds = %24
  store i32 4, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %36

31:                                               ; preds = %24
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = icmp uge i32 %32, 2
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  store i32 2, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %36

35:                                               ; preds = %31
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %36

36:                                               ; preds = %35, %34, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %55

37:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = call noundef i32 @_Z18countEmbeddedNullsPKhj(ptr noundef %38, i32 noundef %39)
  store i32 %40, ptr %10, align 4, !tbaa !9
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = mul i32 2, %42
  %44 = udiv i32 %43, 3
  %45 = icmp uge i32 %41, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %37
  store i32 4, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %54

47:                                               ; preds = %37
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = udiv i32 %49, 3
  %51 = icmp uge i32 %48, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %47
  store i32 2, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %54

53:                                               ; preds = %47
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %54

54:                                               ; preds = %53, %52, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %55

55:                                               ; preds = %54, %36, %20
  %56 = load i32, ptr %4, align 4
  ret i32 %56
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn nounwind "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 = { noreturn nounwind }
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 = !{!"int", !7, i64 0}


; 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 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [98 x i8], align 1
@__PRETTY_FUNCTION__._Z17guessCharByteSizePKhjj = external hidden unnamed_addr constant [76 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z22countTrailingNullBytesPKhi(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z18countEmbeddedNullsPKhj(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 1, 5) i32 @_Z17guessCharByteSizePKhjj(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %4, label %5

4:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1245, ptr noundef nonnull @__PRETTY_FUNCTION__._Z17guessCharByteSizePKhjj) #2
  unreachable

5:                                                ; preds = %3
  %6 = and i32 %2, 1
  %.not16 = icmp eq i32 %6, 0
  br i1 %.not16, label %7, label %18

7:                                                ; preds = %5
  %8 = icmp ult i32 %2, 32
  br i1 %8, label %9, label %12

9:                                                ; preds = %7
  %10 = tail call noundef i32 @_Z22countTrailingNullBytesPKhi(ptr noundef %0, i32 noundef %1)
  %11 = icmp ugt i32 %10, 1
  %. = select i1 %11, i32 2, i32 1
  %.inv = icmp ult i32 %10, 4
  %.0 = select i1 %.inv, i32 %., i32 4
  br label %18

12:                                               ; preds = %7
  %13 = tail call noundef i32 @_Z18countEmbeddedNullsPKhj(ptr noundef %0, i32 noundef %1)
  %14 = shl i32 %1, 1
  %15 = udiv i32 %14, 3
  %.not17 = icmp ult i32 %13, %15
  br i1 %.not17, label %16, label %18

16:                                               ; preds = %12
  %17 = udiv i32 %1, 3
  %.not18 = icmp ult i32 %13, %17
  %.19 = select i1 %.not18, i32 1, i32 2
  br label %18

18:                                               ; preds = %12, %16, %5, %9
  %.2 = phi i32 [ %.0, %9 ], [ 1, %5 ], [ 4, %12 ], [ %.19, %16 ]
  ret i32 %.2
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { noreturn nounwind "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 = { noreturn 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)"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass