; LLVM IR from stan-dev/math :: lib/boost_1.84.0/libs/filesystem/src (utf8_codecvt_facet)

; 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: mustprogress uwtable
define dso_local noundef i32 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet5do_inER11__mbstate_tPKcS6_RS6_PwS8_RS8_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, ptr noundef %2, ptr noundef %3, ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef %5, ptr noundef %6, ptr noundef nonnull align 8 dereferenceable(8) %7) unnamed_addr #0 align 2 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store ptr %2, ptr %12, align 8, !tbaa !5
  store ptr %3, ptr %13, align 8, !tbaa !5
  store ptr %4, ptr %14, align 8, !tbaa !5
  store ptr %5, ptr %15, align 8, !tbaa !5
  store ptr %6, ptr %16, align 8, !tbaa !5
  store ptr %7, ptr %17, align 8, !tbaa !5
  %23 = load ptr, ptr %10, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %24 = call noundef ptr @_ZN5boost10filesystem6detail6detail25get_octet1_modifier_tableEv() #4
  store ptr %24, ptr %18, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %113, %8
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  %28 = icmp ne ptr %26, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %25
  %30 = load ptr, ptr %15, align 8, !tbaa !5
  %31 = load ptr, ptr %16, align 8, !tbaa !5
  %32 = icmp ne ptr %30, %31
  br label %33

33:                                               ; preds = %29, %25
  %34 = phi i1 [ false, %25 ], [ %32, %29 ]
  br i1 %34, label %35, label %114

35:                                               ; preds = %33
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = call noundef zeroext i1 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet21invalid_leading_octetEh(ptr noundef nonnull align 8 dereferenceable(24) %23, i8 noundef zeroext %37)
  br i1 %38, label %39, label %44

39:                                               ; preds = %35
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %40, ptr %41, align 8, !tbaa !5
  %42 = load ptr, ptr %15, align 8, !tbaa !5
  %43 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %42, ptr %43, align 8, !tbaa !5
  store i32 2, ptr %9, align 4
  store i32 1, ptr %19, align 4
  br label %124

44:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = call noundef i32 @_ZN5boost10filesystem6detail18utf8_codecvt_facet20get_cont_octet_countEh(i8 noundef zeroext %46)
  store i32 %47, ptr %20, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %12, align 8, !tbaa !5
  %50 = load i8, ptr %48, align 1, !tbaa !9
  %51 = zext i8 %50 to i32
  %52 = load ptr, ptr %18, align 8, !tbaa !5
  %53 = load i32, ptr %20, align 4, !tbaa !10
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !12
  %57 = sub nsw i32 %51, %56
  store i32 %57, ptr %21, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #4
  store i32 0, ptr %22, align 4, !tbaa !10
  br label %58

58:                                               ; preds = %77, %44
  %59 = load i32, ptr %22, align 4, !tbaa !10
  %60 = load i32, ptr %20, align 4, !tbaa !10
  %61 = icmp ne i32 %59, %60
  br i1 %61, label %62, label %66

62:                                               ; preds = %58
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = load ptr, ptr %13, align 8, !tbaa !5
  %65 = icmp ne ptr %63, %64
  br label %66

66:                                               ; preds = %62, %58
  %67 = phi i1 [ false, %58 ], [ %65, %62 ]
  br i1 %67, label %68, label %89

68:                                               ; preds = %66
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = load i8, ptr %69, align 1, !tbaa !9
  %71 = call noundef zeroext i1 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet24invalid_continuing_octetEh(ptr noundef nonnull align 8 dereferenceable(24) %23, i8 noundef zeroext %70)
  br i1 %71, label %72, label %77

72:                                               ; preds = %68
  %73 = load ptr, ptr %12, align 8, !tbaa !5
  %74 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %73, ptr %74, align 8, !tbaa !5
  %75 = load ptr, ptr %15, align 8, !tbaa !5
  %76 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %75, ptr %76, align 8, !tbaa !5
  store i32 2, ptr %9, align 4
  store i32 1, ptr %19, align 4
  br label %111

77:                                               ; preds = %68
  %78 = load i32, ptr %21, align 4, !tbaa !12
  %79 = mul nsw i32 %78, 64
  store i32 %79, ptr %21, align 4, !tbaa !12
  %80 = load ptr, ptr %12, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i32 1
  store ptr %81, ptr %12, align 8, !tbaa !5
  %82 = load i8, ptr %80, align 1, !tbaa !9
  %83 = zext i8 %82 to i32
  %84 = sub nsw i32 %83, 128
  %85 = load i32, ptr %21, align 4, !tbaa !12
  %86 = add nsw i32 %85, %84
  store i32 %86, ptr %21, align 4, !tbaa !12
  %87 = load i32, ptr %22, align 4, !tbaa !10
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %22, align 4, !tbaa !10
  br label %58, !llvm.loop !14

89:                                               ; preds = %66
  %90 = load ptr, ptr %12, align 8, !tbaa !5
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = icmp eq ptr %90, %91
  br i1 %92, label %93, label %107

93:                                               ; preds = %89
  %94 = load i32, ptr %22, align 4, !tbaa !10
  %95 = load i32, ptr %20, align 4, !tbaa !10
  %96 = icmp ne i32 %94, %95
  br i1 %96, label %97, label %107

97:                                               ; preds = %93
  %98 = load ptr, ptr %12, align 8, !tbaa !5
  %99 = load i32, ptr %22, align 4, !tbaa !10
  %100 = add nsw i32 %99, 1
  %101 = sext i32 %100 to i64
  %102 = sub i64 0, %101
  %103 = getelementptr inbounds i8, ptr %98, i64 %102
  %104 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %103, ptr %104, align 8, !tbaa !5
  %105 = load ptr, ptr %15, align 8, !tbaa !5
  %106 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %105, ptr %106, align 8, !tbaa !5
  store i32 1, ptr %9, align 4
  store i32 1, ptr %19, align 4
  br label %111

107:                                              ; preds = %93, %89
  %108 = load i32, ptr %21, align 4, !tbaa !12
  %109 = load ptr, ptr %15, align 8, !tbaa !5
  %110 = getelementptr inbounds i32, ptr %109, i32 1
  store ptr %110, ptr %15, align 8, !tbaa !5
  store i32 %108, ptr %109, align 4, !tbaa !12
  store i32 0, ptr %19, align 4
  br label %111

111:                                              ; preds = %107, %97, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  %112 = load i32, ptr %19, align 4
  switch i32 %112, label %124 [
    i32 0, label %113
  ]

113:                                              ; preds = %111
  br label %25, !llvm.loop !16

114:                                              ; preds = %33
  %115 = load ptr, ptr %12, align 8, !tbaa !5
  %116 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %115, ptr %116, align 8, !tbaa !5
  %117 = load ptr, ptr %15, align 8, !tbaa !5
  %118 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %117, ptr %118, align 8, !tbaa !5
  %119 = load ptr, ptr %12, align 8, !tbaa !5
  %120 = load ptr, ptr %13, align 8, !tbaa !5
  %121 = icmp eq ptr %119, %120
  br i1 %121, label %122, label %123

122:                                              ; preds = %114
  store i32 0, ptr %9, align 4
  store i32 1, ptr %19, align 4
  br label %124

123:                                              ; preds = %114
  store i32 1, ptr %9, align 4
  store i32 1, ptr %19, align 4
  br label %124

124:                                              ; preds = %123, %122, %111, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  %125 = load i32, ptr %9, align 4
  ret i32 %125
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN5boost10filesystem6detail6detail25get_octet1_modifier_tableEv() #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet21invalid_leading_octetEh(ptr noundef nonnull align 8 dereferenceable(24), i8 noundef zeroext) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5boost10filesystem6detail18utf8_codecvt_facet20get_cont_octet_countEh(i8 noundef zeroext) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet24invalid_continuing_octetEh(ptr noundef nonnull align 8 dereferenceable(24), i8 noundef zeroext) #3 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress 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 = { inlinehint 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 = { 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 #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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"wchar_t", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet5do_inER11__mbstate_tPKcS6_RS6_PwS8_RS8_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr nocapture noundef nonnull readnone align 4 dereferenceable(8) %1, ptr noundef %2, ptr noundef readnone %3, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %4, ptr noundef %5, ptr noundef readnone %6, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %7) unnamed_addr #0 align 2 {
  %9 = tail call noundef ptr @_ZN5boost10filesystem6detail6detail25get_octet1_modifier_tableEv() #2
  %10 = icmp ne ptr %2, %3
  %11 = icmp ne ptr %5, %6
  %12 = and i1 %10, %11
  br i1 %12, label %.lr.ph77, label %._crit_edge78

.lr.ph77:                                         ; preds = %8, %47
  %.04875 = phi ptr [ %.149.lcssa, %47 ], [ %2, %8 ]
  %.05074 = phi ptr [ %48, %47 ], [ %5, %8 ]
  %13 = load i8, ptr %.04875, align 1, !tbaa !5
  %14 = tail call noundef zeroext i1 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet21invalid_leading_octetEh(ptr noundef nonnull align 8 dereferenceable(24) %0, i8 noundef zeroext %13)
  br i1 %14, label %15, label %16

15:                                               ; preds = %.lr.ph77
  store ptr %.04875, ptr %4, align 8, !tbaa !8
  store ptr %.05074, ptr %7, align 8, !tbaa !8
  br label %.thread

16:                                               ; preds = %.lr.ph77
  %17 = load i8, ptr %.04875, align 1, !tbaa !5
  %18 = tail call noundef i32 @_ZN5boost10filesystem6detail18utf8_codecvt_facet20get_cont_octet_countEh(i8 noundef zeroext %17)
  %19 = load i8, ptr %.04875, align 1, !tbaa !5
  %20 = zext i8 %19 to i32
  %21 = sext i32 %18 to i64
  %22 = getelementptr inbounds i32, ptr %9, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !10
  %24 = sub nsw i32 %20, %23
  %.14967 = getelementptr inbounds i8, ptr %.04875, i64 1
  %25 = icmp ne i32 %18, 0
  %26 = icmp ne ptr %.14967, %3
  %27 = select i1 %25, i1 %26, i1 false
  br i1 %27, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %16, %31
  %.14970 = phi ptr [ %.149, %31 ], [ %.14967, %16 ]
  %.069 = phi i32 [ %37, %31 ], [ 0, %16 ]
  %.04568 = phi i32 [ %36, %31 ], [ %24, %16 ]
  %28 = load i8, ptr %.14970, align 1, !tbaa !5
  %29 = tail call noundef zeroext i1 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet24invalid_continuing_octetEh(ptr noundef nonnull align 8 dereferenceable(24) %0, i8 noundef zeroext %28)
  br i1 %29, label %30, label %31

30:                                               ; preds = %.lr.ph
  store ptr %.14970, ptr %4, align 8, !tbaa !8
  store ptr %.05074, ptr %7, align 8, !tbaa !8
  br label %.thread

31:                                               ; preds = %.lr.ph
  %32 = shl nsw i32 %.04568, 6
  %33 = load i8, ptr %.14970, align 1, !tbaa !5
  %34 = zext i8 %33 to i32
  %35 = add i32 %32, -128
  %36 = add i32 %35, %34
  %37 = add nuw nsw i32 %.069, 1
  %.149 = getelementptr inbounds i8, ptr %.14970, i64 1
  %38 = icmp ne i32 %37, %18
  %39 = icmp ne ptr %.149, %3
  %40 = select i1 %38, i1 %39, i1 false
  br i1 %40, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %31, %16
  %.045.lcssa = phi i32 [ %24, %16 ], [ %36, %31 ]
  %.0.lcssa = phi i32 [ 0, %16 ], [ %37, %31 ]
  %.149.lcssa = phi ptr [ %.14967, %16 ], [ %.149, %31 ]
  %.lcssa = phi i1 [ %25, %16 ], [ %38, %31 ]
  %41 = icmp eq ptr %.149.lcssa, %3
  %brmerge.not = and i1 %41, %.lcssa
  br i1 %brmerge.not, label %42, label %47

42:                                               ; preds = %._crit_edge
  %43 = add nuw nsw i32 %.0.lcssa, 1
  %44 = zext nneg i32 %43 to i64
  %45 = sub nsw i64 0, %44
  %46 = getelementptr inbounds i8, ptr %.149.lcssa, i64 %45
  store ptr %46, ptr %4, align 8, !tbaa !8
  store ptr %.05074, ptr %7, align 8, !tbaa !8
  br label %.thread

47:                                               ; preds = %._crit_edge
  %48 = getelementptr inbounds i8, ptr %.05074, i64 4
  store i32 %.045.lcssa, ptr %.05074, align 4, !tbaa !10
  %49 = icmp ne ptr %.149.lcssa, %3
  %50 = icmp ne ptr %48, %6
  %51 = select i1 %49, i1 %50, i1 false
  br i1 %51, label %.lr.ph77, label %._crit_edge78, !llvm.loop !14

._crit_edge78:                                    ; preds = %47, %8
  %.050.lcssa = phi ptr [ %5, %8 ], [ %48, %47 ]
  %.048.lcssa = phi ptr [ %2, %8 ], [ %.149.lcssa, %47 ]
  store ptr %.048.lcssa, ptr %4, align 8, !tbaa !8
  store ptr %.050.lcssa, ptr %7, align 8, !tbaa !8
  %52 = icmp ne ptr %.048.lcssa, %3
  %. = zext i1 %52 to i32
  br label %.thread

.thread:                                          ; preds = %42, %30, %._crit_edge78, %15
  %.2 = phi i32 [ 2, %15 ], [ %., %._crit_edge78 ], [ 1, %42 ], [ 2, %30 ]
  ret i32 %.2
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN5boost10filesystem6detail6detail25get_octet1_modifier_tableEv() local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet21invalid_leading_octetEh(ptr noundef nonnull align 8 dereferenceable(24), i8 noundef zeroext) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5boost10filesystem6detail18utf8_codecvt_facet20get_cont_octet_countEh(i8 noundef zeroext) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet24invalid_continuing_octetEh(ptr noundef nonnull align 8 dereferenceable(24), i8 noundef zeroext) local_unnamed_addr #0 align 2

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 = { inlinehint 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 }

!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++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"wchar_t", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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