; LLVM IR from thepowersgang/mrustc :: src/hir/hir_ops.ll (ZN14EncodedLiteral10write_uintEmmm)

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

%struct.EncodedLiteral = type { %"class.std::vector.432", %"class.std::vector.437" }
%"class.std::vector.432" = type { %"struct.std::_Vector_base.433" }
%"struct.std::_Vector_base.433" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.437" = type { %"struct.std::_Vector_base.438" }
%"struct.std::_Vector_base.438" = type { %"struct.std::_Vector_base<Reloc, std::allocator<Reloc>>::_Vector_impl" }
%"struct.std::_Vector_base<Reloc, std::allocator<Reloc>>::_Vector_impl" = type { %"struct.std::_Vector_base<Reloc, std::allocator<Reloc>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Reloc, std::allocator<Reloc>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.TargetSpec = type { %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", %struct.BackendOptsC, %struct.TargetArch }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon.284 }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon.284 = type { i64, [8 x i8] }
%struct.BackendOptsC = type { i32, i8, %"class.std::__cxx11::basic_string", %"class.std::vector.228", %"class.std::vector.228", %"class.std::vector.228" }
%"class.std::vector.228" = type { %"struct.std::_Vector_base.229" }
%"struct.std::_Vector_base.229" = type { %"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.TargetArch = type <{ %"class.std::__cxx11::basic_string", i32, i8, %"struct.TargetArch::Atomics", %"struct.TargetArch::Alignments", [7 x i8] }>
%"struct.TargetArch::Atomics" = type { i8, i8, i8, i8, i8 }
%"struct.TargetArch::Alignments" = type { i8, i8, i8, i8, i8, i8, i8 }

@.str.28 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [27 x i8], align 1
@__PRETTY_FUNCTION__._ZN14EncodedLiteral10write_uintEmmm = external hidden unnamed_addr constant [58 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14EncodedLiteral10write_uintEmmm(ptr noundef nonnull align 8 dereferenceable(48) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = add i64 %13, %14
  %16 = getelementptr inbounds %struct.EncodedLiteral, ptr %12, i32 0, i32 0
  %17 = call noundef i64 @_ZNKSt6vectorIhSaIhEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %16) #5
  %18 = icmp ule i64 %15, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  br label %22

20:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.34, ptr noundef @.str.28, i32 noundef 1404, ptr noundef @__PRETTY_FUNCTION__._ZN14EncodedLiteral10write_uintEmmm) #6
  unreachable

21:                                               ; No predecessors!
  br label %22

22:                                               ; preds = %21, %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %59, %22
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %62

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %29 = call noundef nonnull align 8 dereferenceable(264) ptr @_Z17Target_GetCurSpecv()
  %30 = getelementptr inbounds %struct.TargetSpec, ptr %29, i32 0, i32 4
  %31 = getelementptr inbounds %struct.TargetArch, ptr %30, i32 0, i32 2
  %32 = load i8, ptr %31, align 4, !tbaa !11, !range !26, !noundef !27
  %33 = trunc i8 %32 to i1
  br i1 %33, label %34, label %40

34:                                               ; preds = %28
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = sub i64 %35, 1
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = sub i64 %36, %37
  %39 = mul i64 %38, 8
  br label %43

40:                                               ; preds = %28
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = mul i64 %41, 8
  br label %43

43:                                               ; preds = %40, %34
  %44 = phi i64 [ %39, %34 ], [ %42, %40 ]
  store i64 %44, ptr %10, align 8, !tbaa !9
  %45 = load i64, ptr %10, align 8, !tbaa !9
  %46 = icmp ult i64 %45, 64
  br i1 %46, label %47, label %58

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #5
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = lshr i64 %48, %49
  %51 = trunc i64 %50 to i8
  store i8 %51, ptr %11, align 1, !tbaa !28
  %52 = load i8, ptr %11, align 1, !tbaa !28
  %53 = getelementptr inbounds %struct.EncodedLiteral, ptr %12, i32 0, i32 0
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = load i64, ptr %9, align 8, !tbaa !9
  %56 = add i64 %54, %55
  %57 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %53, i64 noundef %56) #5
  store i8 %52, ptr %57, align 1, !tbaa !28
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #5
  br label %58

58:                                               ; preds = %47, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %59

59:                                               ; preds = %58
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = add i64 %60, 1
  store i64 %61, ptr %9, align 8, !tbaa !9
  br label %23, !llvm.loop !29

62:                                               ; preds = %27
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIhSaIhEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

declare noundef nonnull align 8 dereferenceable(264) ptr @_Z17Target_GetCurSpecv() #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { "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 #5 = { nounwind }
attributes #6 = { 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)"}
!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, !17, i64 244}
!12 = !{!"_ZTS10TargetSpec", !13, i64 0, !13, i64 32, !13, i64 64, !15, i64 96, !22, i64 208}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !10, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"_ZTS12BackendOptsC", !16, i64 0, !17, i64 4, !13, i64 8, !18, i64 40, !18, i64 64, !18, i64 88}
!16 = !{!"_ZTS11CodegenMode", !7, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"_ZTSSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!"_ZTS10TargetArch", !13, i64 0, !23, i64 32, !17, i64 36, !24, i64 37, !25, i64 42}
!23 = !{!"int", !7, i64 0}
!24 = !{!"_ZTSN10TargetArch7AtomicsE", !17, i64 0, !17, i64 1, !17, i64 2, !17, i64 3, !17, i64 4}
!25 = !{!"_ZTSN10TargetArch10AlignmentsE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!7, !7, i64 0}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}


; 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.28 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [27 x i8], align 1
@__PRETTY_FUNCTION__._ZN14EncodedLiteral10write_uintEmmm = external hidden unnamed_addr constant [58 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14EncodedLiteral10write_uintEmmm(ptr noundef nonnull align 8 dereferenceable(48) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #1 align 2 {
  %5 = add i64 %2, %1
  %6 = tail call noundef i64 @_ZNKSt6vectorIhSaIhEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  %.not = icmp ugt i64 %5, %6
  br i1 %.not, label %7, label %.preheader

.preheader:                                       ; preds = %4
  %.not17 = icmp eq i64 %2, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

7:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.34, ptr noundef nonnull @.str.28, i32 noundef 1404, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN14EncodedLiteral10write_uintEmmm) #5
  unreachable

._crit_edge:                                      ; preds = %21, %.preheader
  ret void

.lr.ph:                                           ; preds = %.preheader, %21
  %.016 = phi i64 [ %22, %21 ], [ 0, %.preheader ]
  %8 = tail call noundef nonnull align 8 dereferenceable(264) ptr @_Z17Target_GetCurSpecv()
  %9 = getelementptr inbounds i8, ptr %8, i64 244
  %10 = load i8, ptr %9, align 4, !tbaa !5, !range !24, !noundef !25
  %11 = trunc nuw i8 %10 to i1
  %12 = xor i64 %.016, -1
  %13 = add i64 %12, %2
  %.in = select i1 %11, i64 %13, i64 %.016
  %14 = shl i64 %.in, 3
  %15 = icmp ult i64 %14, 64
  br i1 %15, label %16, label %21

16:                                               ; preds = %.lr.ph
  %17 = lshr i64 %3, %14
  %18 = trunc i64 %17 to i8
  %19 = add i64 %.016, %1
  %20 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %19) #4
  store i8 %18, ptr %20, align 1, !tbaa !26
  br label %21

21:                                               ; preds = %16, %.lr.ph
  %22 = add nuw i64 %.016, 1
  %exitcond.not = icmp eq i64 %22, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !27
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIhSaIhEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

declare noundef nonnull align 8 dereferenceable(264) ptr @_Z17Target_GetCurSpecv() local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

attributes #0 = { 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 #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 = { "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 }
attributes #5 = { 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)"}
!5 = !{!6, !15, i64 244}
!6 = !{!"_ZTS10TargetSpec", !7, i64 0, !7, i64 32, !7, i64 64, !13, i64 96, !20, i64 208}
!7 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !8, i64 0, !12, i64 8, !10, i64 16}
!8 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!"_ZTS12BackendOptsC", !14, i64 0, !15, i64 4, !7, i64 8, !16, i64 40, !16, i64 64, !16, i64 88}
!14 = !{!"_ZTS11CodegenMode", !10, i64 0}
!15 = !{!"bool", !10, i64 0}
!16 = !{!"_ZTSSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE17_Vector_impl_dataE", !9, i64 0, !9, i64 8, !9, i64 16}
!20 = !{!"_ZTS10TargetArch", !7, i64 0, !21, i64 32, !15, i64 36, !22, i64 37, !23, i64 42}
!21 = !{!"int", !10, i64 0}
!22 = !{!"_ZTSN10TargetArch7AtomicsE", !15, i64 0, !15, i64 1, !15, i64 2, !15, i64 3, !15, i64 4}
!23 = !{!"_ZTSN10TargetArch10AlignmentsE", !10, i64 0, !10, i64 1, !10, i64 2, !10, i64 3, !10, i64 4, !10, i64 5, !10, i64 6}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = !{!10, !10, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass