; LLVM IR from vergecurrency/verge :: src/arith_uint256.ll (Z14ArithToUint256RK13arith_uint256)

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

%class.uint256 = type { %class.base_blob }
%class.base_blob = type { [32 x i8] }
%class.base_uint = type { [8 x i32] }

; 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 uwtable
define dso_local void @_Z14ArithToUint256RK13arith_uint256(ptr dead_on_unwind noalias writable sret(%class.uint256) align 1 %0, ptr noundef nonnull align 4 dereferenceable(32) %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %1, ptr %3, align 8, !tbaa !5
  call void @_ZN7uint256C2Ev(ptr noundef nonnull align 1 dereferenceable(32) %0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %22, %2
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp slt i32 %6, 8
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %25

10:                                               ; preds = %5
  %11 = call noundef ptr @_ZN9base_blobILj256EE5beginEv(ptr noundef nonnull align 1 dereferenceable(32) %0)
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = mul nsw i32 %12, 4
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %11, i64 %14
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %class.base_uint, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [8 x i32], ptr %17, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !9
  call void @_ZL9WriteLE32Phj(ptr noundef %15, i32 noundef %21)
  br label %22

22:                                               ; preds = %10
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %4, align 4, !tbaa !9
  br label %5, !llvm.loop !11

25:                                               ; preds = %9
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7uint256C2Ev(ptr noundef nonnull align 1 dereferenceable(32)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @_ZL9WriteLE32Phj(ptr noundef, i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN9base_blobILj256EE5beginEv(ptr noundef nonnull align 1 dereferenceable(32)) #3 align 2

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

%class.uint256 = type { %class.base_blob }
%class.base_blob = type { [32 x i8] }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14ArithToUint256RK13arith_uint256(ptr dead_on_unwind noalias nonnull writable sret(%class.uint256) align 1 %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(32) %1) local_unnamed_addr #0 {
  tail call void @_ZN7uint256C2Ev(ptr noundef nonnull align 1 dereferenceable(32) %0)
  %3 = tail call noundef ptr @_ZN9base_blobILj256EE5beginEv(ptr noundef nonnull align 1 dereferenceable(32) %0)
  %4 = load i32, ptr %1, align 4, !tbaa !5
  tail call void @_ZL9WriteLE32Phj(ptr noundef %3, i32 noundef %4)
  %5 = tail call noundef ptr @_ZN9base_blobILj256EE5beginEv(ptr noundef nonnull align 1 dereferenceable(32) %0)
  %6 = getelementptr inbounds i8, ptr %5, i64 4
  %7 = getelementptr inbounds i8, ptr %1, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  tail call void @_ZL9WriteLE32Phj(ptr noundef nonnull %6, i32 noundef %8)
  %9 = tail call noundef ptr @_ZN9base_blobILj256EE5beginEv(ptr noundef nonnull align 1 dereferenceable(32) %0)
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load i32, ptr %11, align 4, !tbaa !5
  tail call void @_ZL9WriteLE32Phj(ptr noundef nonnull %10, i32 noundef %12)
  %13 = tail call noundef ptr @_ZN9base_blobILj256EE5beginEv(ptr noundef nonnull align 1 dereferenceable(32) %0)
  %14 = getelementptr inbounds i8, ptr %13, i64 12
  %15 = getelementptr inbounds i8, ptr %1, i64 12
  %16 = load i32, ptr %15, align 4, !tbaa !5
  tail call void @_ZL9WriteLE32Phj(ptr noundef nonnull %14, i32 noundef %16)
  %17 = tail call noundef ptr @_ZN9base_blobILj256EE5beginEv(ptr noundef nonnull align 1 dereferenceable(32) %0)
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = getelementptr inbounds i8, ptr %1, i64 16
  %20 = load i32, ptr %19, align 4, !tbaa !5
  tail call void @_ZL9WriteLE32Phj(ptr noundef nonnull %18, i32 noundef %20)
  %21 = tail call noundef ptr @_ZN9base_blobILj256EE5beginEv(ptr noundef nonnull align 1 dereferenceable(32) %0)
  %22 = getelementptr inbounds i8, ptr %21, i64 20
  %23 = getelementptr inbounds i8, ptr %1, i64 20
  %24 = load i32, ptr %23, align 4, !tbaa !5
  tail call void @_ZL9WriteLE32Phj(ptr noundef nonnull %22, i32 noundef %24)
  %25 = tail call noundef ptr @_ZN9base_blobILj256EE5beginEv(ptr noundef nonnull align 1 dereferenceable(32) %0)
  %26 = getelementptr inbounds i8, ptr %25, i64 24
  %27 = getelementptr inbounds i8, ptr %1, i64 24
  %28 = load i32, ptr %27, align 4, !tbaa !5
  tail call void @_ZL9WriteLE32Phj(ptr noundef nonnull %26, i32 noundef %28)
  %29 = tail call noundef ptr @_ZN9base_blobILj256EE5beginEv(ptr noundef nonnull align 1 dereferenceable(32) %0)
  %30 = getelementptr inbounds i8, ptr %29, i64 28
  %31 = getelementptr inbounds i8, ptr %1, i64 28
  %32 = load i32, ptr %31, align 4, !tbaa !5
  tail call void @_ZL9WriteLE32Phj(ptr noundef nonnull %30, i32 noundef %32)
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7uint256C2Ev(ptr noundef nonnull align 1 dereferenceable(32)) unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @_ZL9WriteLE32Phj(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN9base_blobILj256EE5beginEv(ptr noundef nonnull align 1 dereferenceable(32)) local_unnamed_addr #2 align 2

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

!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++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass