; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet6do_outER11__mbstate_tPKwS6_RS6_PcS8_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 #2 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
  %23 = 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
  %24 = load ptr, ptr %10, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %25 = call noundef ptr @_ZN5boost10filesystem6detail6detail25get_octet1_modifier_tableEv() #4
  store ptr %25, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  %26 = call noundef signext i32 @_ZNSt14numeric_limitsIwE3maxEv() #4
  store i32 %26, ptr %19, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %117, %8
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = load ptr, ptr %13, align 8, !tbaa !5
  %30 = icmp ne ptr %28, %29
  br i1 %30, label %31, label %35

31:                                               ; preds = %27
  %32 = load ptr, ptr %15, align 8, !tbaa !5
  %33 = load ptr, ptr %16, align 8, !tbaa !5
  %34 = icmp ne ptr %32, %33
  br label %35

35:                                               ; preds = %31, %27
  %36 = phi i1 [ false, %27 ], [ %34, %31 ]
  br i1 %36, label %37, label %118

37:                                               ; preds = %35
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = load i32, ptr %19, align 4, !tbaa !9
  %41 = icmp sgt i32 %39, %40
  br i1 %41, label %42, label %47

42:                                               ; preds = %37
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %43, ptr %44, align 8, !tbaa !5
  %45 = load ptr, ptr %15, align 8, !tbaa !5
  %46 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %45, ptr %46, align 8, !tbaa !5
  store i32 2, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %128

47:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = call noundef i32 @_ZN5boost10filesystem6detail18utf8_codecvt_facet24get_cont_octet_out_countEw(i32 noundef signext %49)
  store i32 %50, ptr %21, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #4
  %51 = load i32, ptr %21, align 4, !tbaa !11
  %52 = mul nsw i32 %51, 6
  store i32 %52, ptr %22, align 4, !tbaa !11
  %53 = load ptr, ptr %18, align 8, !tbaa !5
  %54 = load i32, ptr %21, align 4, !tbaa !11
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %53, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = load i32, ptr %22, align 4, !tbaa !11
  %61 = shl i32 1, %60
  %62 = sdiv i32 %59, %61
  %63 = trunc i32 %62 to i8
  %64 = zext i8 %63 to i32
  %65 = add nsw i32 %57, %64
  %66 = trunc i32 %65 to i8
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i32 1
  store ptr %68, ptr %15, align 8, !tbaa !5
  store i8 %66, ptr %67, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #4
  store i32 0, ptr %23, align 4, !tbaa !11
  br label %69

69:                                               ; preds = %79, %47
  %70 = load i32, ptr %23, align 4, !tbaa !11
  %71 = load i32, ptr %21, align 4, !tbaa !11
  %72 = icmp ne i32 %70, %71
  br i1 %72, label %73, label %77

73:                                               ; preds = %69
  %74 = load ptr, ptr %15, align 8, !tbaa !5
  %75 = load ptr, ptr %16, align 8, !tbaa !5
  %76 = icmp ne ptr %74, %75
  br label %77

77:                                               ; preds = %73, %69
  %78 = phi i1 [ false, %69 ], [ %76, %73 ]
  br i1 %78, label %79, label %94

79:                                               ; preds = %77
  %80 = load i32, ptr %22, align 4, !tbaa !11
  %81 = sub nsw i32 %80, 6
  store i32 %81, ptr %22, align 4, !tbaa !11
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  %83 = load i32, ptr %82, align 4, !tbaa !9
  %84 = load i32, ptr %22, align 4, !tbaa !11
  %85 = shl i32 1, %84
  %86 = sdiv i32 %83, %85
  %87 = srem i32 %86, 64
  %88 = add nsw i32 128, %87
  %89 = trunc i32 %88 to i8
  %90 = load ptr, ptr %15, align 8, !tbaa !5
  %91 = getelementptr inbounds i8, ptr %90, i32 1
  store ptr %91, ptr %15, align 8, !tbaa !5
  store i8 %89, ptr %90, align 1, !tbaa !13
  %92 = load i32, ptr %23, align 4, !tbaa !11
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %23, align 4, !tbaa !11
  br label %69, !llvm.loop !14

94:                                               ; preds = %77
  %95 = load ptr, ptr %15, align 8, !tbaa !5
  %96 = load ptr, ptr %16, align 8, !tbaa !5
  %97 = icmp eq ptr %95, %96
  br i1 %97, label %98, label %112

98:                                               ; preds = %94
  %99 = load i32, ptr %23, align 4, !tbaa !11
  %100 = load i32, ptr %21, align 4, !tbaa !11
  %101 = icmp ne i32 %99, %100
  br i1 %101, label %102, label %112

102:                                              ; preds = %98
  %103 = load ptr, ptr %12, align 8, !tbaa !5
  %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 i32, ptr %23, align 4, !tbaa !11
  %107 = add nsw i32 %106, 1
  %108 = sext i32 %107 to i64
  %109 = sub i64 0, %108
  %110 = getelementptr inbounds i8, ptr %105, i64 %109
  %111 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %110, ptr %111, align 8, !tbaa !5
  store i32 1, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %115

112:                                              ; preds = %98, %94
  %113 = load ptr, ptr %12, align 8, !tbaa !5
  %114 = getelementptr inbounds i32, ptr %113, i32 1
  store ptr %114, ptr %12, align 8, !tbaa !5
  store i32 0, ptr %20, align 4
  br label %115

115:                                              ; preds = %112, %102
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  %116 = load i32, ptr %20, align 4
  switch i32 %116, label %128 [
    i32 0, label %117
  ]

117:                                              ; preds = %115
  br label %27, !llvm.loop !16

118:                                              ; preds = %35
  %119 = load ptr, ptr %12, align 8, !tbaa !5
  %120 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %119, ptr %120, align 8, !tbaa !5
  %121 = load ptr, ptr %15, align 8, !tbaa !5
  %122 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %121, ptr %122, align 8, !tbaa !5
  %123 = load ptr, ptr %12, align 8, !tbaa !5
  %124 = load ptr, ptr %13, align 8, !tbaa !5
  %125 = icmp eq ptr %123, %124
  br i1 %125, label %126, label %127

126:                                              ; preds = %118
  store i32 0, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %128

127:                                              ; preds = %118
  store i32 1, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %128

128:                                              ; preds = %127, %126, %115, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  %129 = load i32, ptr %9, align 4
  ret i32 %129
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i32 @_ZNSt14numeric_limitsIwE3maxEv() #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN5boost10filesystem6detail18utf8_codecvt_facet24get_cont_octet_out_countEw(i32 noundef signext) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"wchar_t", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN5boost10filesystem6detail6detail25get_octet1_modifier_tableEv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK5boost10filesystem6detail18utf8_codecvt_facet6do_outER11__mbstate_tPKwS6_RS6_PcS8_RS8_(ptr nocapture noundef nonnull readnone 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 #1 align 2 {
  %9 = tail call noundef ptr @_ZN5boost10filesystem6detail6detail25get_octet1_modifier_tableEv() #3
  %10 = tail call noundef signext i32 @_ZNSt14numeric_limitsIwE3maxEv() #3
  %11 = icmp ne ptr %2, %3
  %12 = icmp ne ptr %5, %6
  %13 = and i1 %11, %12
  br i1 %13, label %.lr.ph69, label %._crit_edge70

.lr.ph69:                                         ; preds = %8, %47
  %.04767 = phi ptr [ %48, %47 ], [ %2, %8 ]
  %.04966 = phi ptr [ %.150.lcssa, %47 ], [ %5, %8 ]
  %14 = load i32, ptr %.04767, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, %10
  br i1 %15, label %16, label %17

16:                                               ; preds = %.lr.ph69
  store ptr %.04767, ptr %4, align 8, !tbaa !9
  store ptr %.04966, ptr %7, align 8, !tbaa !9
  br label %53

17:                                               ; preds = %.lr.ph69
  %18 = tail call noundef i32 @_ZN5boost10filesystem6detail18utf8_codecvt_facet24get_cont_octet_out_countEw(i32 noundef signext %14)
  %19 = mul nsw i32 %18, 6
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds i32, ptr %9, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = load i32, ptr %.04767, align 4, !tbaa !5
  %24 = shl nuw i32 1, %19
  %25 = sdiv i32 %23, %24
  %26 = add i32 %25, %22
  %27 = trunc i32 %26 to i8
  store i8 %27, ptr %.04966, align 1, !tbaa !11
  %.15060 = getelementptr inbounds i8, ptr %.04966, i64 1
  %28 = icmp ne i32 %18, 0
  %29 = icmp ne ptr %.15060, %6
  %30 = select i1 %28, i1 %29, i1 false
  br i1 %30, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %17, %.lr.ph
  %.15063 = phi ptr [ %.150, %.lr.ph ], [ %.15060, %17 ]
  %.062 = phi i32 [ %38, %.lr.ph ], [ 0, %17 ]
  %.04461 = phi i32 [ %31, %.lr.ph ], [ %19, %17 ]
  %31 = add nsw i32 %.04461, -6
  %32 = load i32, ptr %.04767, align 4, !tbaa !5
  %33 = shl nuw i32 1, %31
  %34 = sdiv i32 %32, %33
  %35 = srem i32 %34, 64
  %36 = trunc nsw i32 %35 to i8
  %37 = xor i8 %36, -128
  store i8 %37, ptr %.15063, align 1, !tbaa !11
  %38 = add nuw nsw i32 %.062, 1
  %.150 = getelementptr inbounds i8, ptr %.15063, i64 1
  %39 = icmp ne i32 %38, %18
  %40 = icmp ne ptr %.150, %6
  %41 = select i1 %39, i1 %40, i1 false
  br i1 %41, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %17
  %.0.lcssa = phi i32 [ 0, %17 ], [ %38, %.lr.ph ]
  %.150.lcssa = phi ptr [ %.15060, %17 ], [ %.150, %.lr.ph ]
  %.lcssa = phi i1 [ %28, %17 ], [ %39, %.lr.ph ]
  %42 = icmp eq ptr %.150.lcssa, %6
  %brmerge.not = and i1 %42, %.lcssa
  br i1 %brmerge.not, label %.thread, label %47

.thread:                                          ; preds = %._crit_edge
  store ptr %.04767, ptr %4, align 8, !tbaa !9
  %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 %.150.lcssa, i64 %45
  store ptr %46, ptr %7, align 8, !tbaa !9
  br label %53

47:                                               ; preds = %._crit_edge
  %48 = getelementptr inbounds i8, ptr %.04767, i64 4
  %49 = icmp ne ptr %48, %3
  %50 = icmp ne ptr %.150.lcssa, %6
  %51 = and i1 %49, %50
  br i1 %51, label %.lr.ph69, label %._crit_edge70, !llvm.loop !14

._crit_edge70:                                    ; preds = %47, %8
  %.049.lcssa = phi ptr [ %5, %8 ], [ %.150.lcssa, %47 ]
  %.047.lcssa = phi ptr [ %2, %8 ], [ %48, %47 ]
  store ptr %.047.lcssa, ptr %4, align 8, !tbaa !9
  store ptr %.049.lcssa, ptr %7, align 8, !tbaa !9
  %52 = icmp ne ptr %.047.lcssa, %3
  %. = zext i1 %52 to i32
  br label %53

53:                                               ; preds = %.thread, %._crit_edge70, %16
  %.2 = phi i32 [ 2, %16 ], [ %., %._crit_edge70 ], [ 1, %.thread ]
  ret i32 %.2
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i32 @_ZNSt14numeric_limitsIwE3maxEv() local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN5boost10filesystem6detail18utf8_codecvt_facet24get_cont_octet_out_countEw(i32 noundef signext) local_unnamed_addr #1 align 2

attributes #0 = { 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 #1 = { 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 #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 }

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


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