; LLVM IR from xhub/reshop :: external/itostr (itostr)

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

@unsignedwcsconv_impl.charcodes = external hidden constant [37 x i32], align 16

; 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 uwtable
define dso_local i64 @unsignedwcsconv_impl(i64 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store i64 %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !11
  %16 = load i32, ptr %9, align 4, !tbaa !11
  %17 = icmp slt i32 %16, 2
  br i1 %17, label %21, label %18

18:                                               ; preds = %4
  %19 = load i32, ptr %9, align 4, !tbaa !11
  %20 = icmp sgt i32 %19, 36
  br i1 %20, label %21, label %23

21:                                               ; preds = %18, %4
  %22 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %22, align 4, !tbaa !11
  store i64 0, ptr %5, align 8
  br label %77

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %24 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %24, ptr %10, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %48, %23
  %26 = load i64, ptr %8, align 8, !tbaa !5
  %27 = sub i64 %26, 1
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %25
  %30 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %30, align 4, !tbaa !11
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %76

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %32 = load i64, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = udiv i64 %32, %34
  store i64 %35, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %36 = load i64, ptr %6, align 8, !tbaa !5
  %37 = load i64, ptr %12, align 8, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = mul i64 %37, %39
  %41 = sub i64 %36, %40
  store i64 %41, ptr %13, align 8, !tbaa !5
  %42 = load i64, ptr %12, align 8, !tbaa !5
  store i64 %42, ptr %6, align 8, !tbaa !5
  %43 = load i64, ptr %13, align 8, !tbaa !5
  %44 = getelementptr inbounds [37 x i32], ptr @unsignedwcsconv_impl.charcodes, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = load ptr, ptr %10, align 8, !tbaa !9
  %47 = getelementptr inbounds i32, ptr %46, i32 1
  store ptr %47, ptr %10, align 8, !tbaa !9
  store i32 %45, ptr %46, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %48

48:                                               ; preds = %31
  %49 = load i64, ptr %6, align 8, !tbaa !5
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %25, label %51, !llvm.loop !13

51:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %52 = load ptr, ptr %10, align 8, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  %54 = ptrtoint ptr %52 to i64
  %55 = ptrtoint ptr %53 to i64
  %56 = sub i64 %54, %55
  %57 = sdiv exact i64 %56, 4
  store i64 %57, ptr %14, align 8, !tbaa !5
  %58 = load ptr, ptr %10, align 8, !tbaa !9
  %59 = getelementptr inbounds i32, ptr %58, i32 -1
  store ptr %59, ptr %10, align 8, !tbaa !9
  store i32 0, ptr %58, align 4, !tbaa !11
  br label %60

60:                                               ; preds = %64, %51
  %61 = load ptr, ptr %7, align 8, !tbaa !9
  %62 = load ptr, ptr %10, align 8, !tbaa !9
  %63 = icmp ult ptr %61, %62
  br i1 %63, label %64, label %74

64:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  %65 = load ptr, ptr %10, align 8, !tbaa !9
  %66 = load i32, ptr %65, align 4, !tbaa !11
  store i32 %66, ptr %15, align 4, !tbaa !11
  %67 = load ptr, ptr %7, align 8, !tbaa !9
  %68 = load i32, ptr %67, align 4, !tbaa !11
  %69 = load ptr, ptr %10, align 8, !tbaa !9
  %70 = getelementptr inbounds i32, ptr %69, i32 -1
  store ptr %70, ptr %10, align 8, !tbaa !9
  store i32 %68, ptr %69, align 4, !tbaa !11
  %71 = load i32, ptr %15, align 4, !tbaa !11
  %72 = load ptr, ptr %7, align 8, !tbaa !9
  %73 = getelementptr inbounds i32, ptr %72, i32 1
  store ptr %73, ptr %7, align 8, !tbaa !9
  store i32 %71, ptr %72, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  br label %60, !llvm.loop !15

74:                                               ; preds = %60
  %75 = load i64, ptr %14, align 8, !tbaa !5
  store i64 %75, ptr %5, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  br label %76

76:                                               ; preds = %74, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %77

77:                                               ; preds = %76, %21
  %78 = load i64, ptr %5, align 8
  ret i64 %78
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@unsignedwcsconv_impl.charcodes = external hidden local_unnamed_addr constant [37 x i32], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local range(i64 -2305843009213693952, 2305843009213693952) i64 @unsignedwcsconv_impl(i64 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = add i32 %3, -37
  %or.cond = icmp ult i32 %5, -35
  br i1 %or.cond, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %4
  %6 = icmp eq i64 %2, 1
  %7 = zext nneg i32 %3 to i64
  br i1 %6, label %.loopexit.sink.split, label %.preheader.split

.preheader.split:                                 ; preds = %.preheader, %.preheader.split
  %.029 = phi ptr [ %12, %.preheader.split ], [ %1, %.preheader ]
  %.027 = phi i64 [ %8, %.preheader.split ], [ %0, %.preheader ]
  %8 = udiv i64 %.027, %7
  %9 = mul i64 %8, %7
  %.recomposed = urem i64 %.027, %7
  %10 = getelementptr inbounds [37 x i32], ptr @unsignedwcsconv_impl.charcodes, i64 0, i64 %.recomposed
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.029, i64 4
  store i32 %11, ptr %.029, align 4, !tbaa !5
  %.not = icmp ult i64 %.027, %7
  br i1 %.not, label %13, label %.preheader.split, !llvm.loop !9

13:                                               ; preds = %.preheader.split
  %14 = ptrtoint ptr %12 to i64
  %15 = ptrtoint ptr %1 to i64
  %16 = sub i64 %14, %15
  %17 = ashr exact i64 %16, 2
  store i32 0, ptr %12, align 4, !tbaa !5
  %18 = icmp ugt ptr %.029, %1
  br i1 %18, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.02835 = phi ptr [ %22, %.lr.ph ], [ %1, %13 ]
  %.13034 = phi ptr [ %21, %.lr.ph ], [ %.029, %13 ]
  %19 = load i32, ptr %.13034, align 4, !tbaa !5
  %20 = load i32, ptr %.02835, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.13034, i64 -4
  store i32 %20, ptr %.13034, align 4, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.02835, i64 4
  store i32 %19, ptr %.02835, align 4, !tbaa !5
  %23 = icmp ult ptr %22, %21
  br i1 %23, label %.lr.ph, label %.loopexit, !llvm.loop !11

.loopexit.sink.split:                             ; preds = %.preheader, %4
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.loopexit.sink.split, %13
  %.1 = phi i64 [ %17, %13 ], [ 0, %.loopexit.sink.split ], [ %17, %.lr.ph ]
  ret i64 %.1
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: 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 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass