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

; 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.arith_uint256 = type { %class.base_uint }
%class.base_uint = type { [8 x i32] }

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(32) ptr @_ZN9base_uintILj256EElSEj(ptr noundef nonnull align 4 dereferenceable(32), i32 noundef) #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 4 dereferenceable(32) ptr @_ZN13arith_uint25610SetCompactEjPbS0_(ptr noundef nonnull align 4 dereferenceable(32) %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %class.arith_uint256, align 4
  %12 = alloca %class.arith_uint256, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = lshr i32 %14, 24
  store i32 %15, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = and i32 %16, 8388607
  store i32 %17, ptr %10, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp sle i32 %18, 3
  br i1 %19, label %20, label %29

20:                                               ; preds = %4
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = sub nsw i32 3, %21
  %23 = mul nsw i32 8, %22
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = lshr i32 %24, %23
  store i32 %25, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #3
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  call void @_ZN13arith_uint256C2Em(ptr noundef nonnull align 4 dereferenceable(32) %11, i64 noundef %27)
  %28 = call noundef nonnull align 4 dereferenceable(32) ptr @_ZN13arith_uint256aSEOS_(ptr noundef nonnull align 4 dereferenceable(32) %13, ptr noundef nonnull align 4 dereferenceable(32) %11)
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #3
  br label %37

29:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 32, ptr %12) #3
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  call void @_ZN13arith_uint256C2Em(ptr noundef nonnull align 4 dereferenceable(32) %12, i64 noundef %31)
  %32 = call noundef nonnull align 4 dereferenceable(32) ptr @_ZN13arith_uint256aSEOS_(ptr noundef nonnull align 4 dereferenceable(32) %13, ptr noundef nonnull align 4 dereferenceable(32) %12)
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #3
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 3
  %35 = mul nsw i32 8, %34
  %36 = call noundef nonnull align 4 dereferenceable(32) ptr @_ZN9base_uintILj256EElSEj(ptr noundef nonnull align 4 dereferenceable(32) %13, i32 noundef %35)
  br label %37

37:                                               ; preds = %29, %20
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %51

40:                                               ; preds = %37
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %47

43:                                               ; preds = %40
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = and i32 %44, 8388608
  %46 = icmp ne i32 %45, 0
  br label %47

47:                                               ; preds = %43, %40
  %48 = phi i1 [ false, %40 ], [ %46, %43 ]
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = zext i1 %48 to i8
  store i8 %50, ptr %49, align 1, !tbaa !11
  br label %51

51:                                               ; preds = %47, %37
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %80

54:                                               ; preds = %51
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %76

57:                                               ; preds = %54
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = icmp sgt i32 %58, 34
  br i1 %59, label %74, label %60

60:                                               ; preds = %57
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = icmp ugt i32 %61, 255
  br i1 %62, label %63, label %66

63:                                               ; preds = %60
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = icmp sgt i32 %64, 33
  br i1 %65, label %74, label %66

66:                                               ; preds = %63, %60
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = icmp ugt i32 %67, 65535
  br i1 %68, label %69, label %72

69:                                               ; preds = %66
  %70 = load i32, ptr %9, align 4, !tbaa !9
  %71 = icmp sgt i32 %70, 32
  br label %72

72:                                               ; preds = %69, %66
  %73 = phi i1 [ false, %66 ], [ %71, %69 ]
  br label %74

74:                                               ; preds = %72, %63, %57
  %75 = phi i1 [ true, %63 ], [ true, %57 ], [ %73, %72 ]
  br label %76

76:                                               ; preds = %74, %54
  %77 = phi i1 [ false, %54 ], [ %75, %74 ]
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = zext i1 %77 to i8
  store i8 %79, ptr %78, align 1, !tbaa !11
  br label %80

80:                                               ; preds = %76, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret ptr %13
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13arith_uint256C2Em(ptr noundef nonnull align 4 dereferenceable(32), i64 noundef) unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(32) ptr @_ZN13arith_uint256aSEOS_(ptr noundef nonnull align 4 dereferenceable(32), ptr noundef nonnull align 4 dereferenceable(32)) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}


; 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.arith_uint256 = type { %class.base_uint }
%class.base_uint = type { [8 x i32] }

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(32) ptr @_ZN9base_uintILj256EElSEj(ptr noundef nonnull align 4 dereferenceable(32), i32 noundef) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 4 dereferenceable(32) ptr @_ZN13arith_uint25610SetCompactEjPbS0_(ptr noundef nonnull returned align 4 dereferenceable(32) %0, i32 noundef %1, ptr noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #0 align 2 {
  %5 = alloca %class.arith_uint256, align 4
  %6 = alloca %class.arith_uint256, align 4
  %7 = lshr i32 %1, 24
  %8 = and i32 %1, 8388607
  %9 = icmp ult i32 %1, 67108864
  br i1 %9, label %10, label %16

10:                                               ; preds = %4
  %11 = shl nuw nsw i32 %7, 3
  %12 = sub nuw nsw i32 24, %11
  %13 = lshr i32 %8, %12
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  %14 = zext nneg i32 %13 to i64
  call void @_ZN13arith_uint256C2Em(ptr noundef nonnull align 4 dereferenceable(32) %5, i64 noundef %14)
  %15 = call noundef nonnull align 4 dereferenceable(32) ptr @_ZN13arith_uint256aSEOS_(ptr noundef nonnull align 4 dereferenceable(32) %0, ptr noundef nonnull align 4 dereferenceable(32) %5)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  br label %22

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #3
  %17 = zext nneg i32 %8 to i64
  call void @_ZN13arith_uint256C2Em(ptr noundef nonnull align 4 dereferenceable(32) %6, i64 noundef %17)
  %18 = call noundef nonnull align 4 dereferenceable(32) ptr @_ZN13arith_uint256aSEOS_(ptr noundef nonnull align 4 dereferenceable(32) %0, ptr noundef nonnull align 4 dereferenceable(32) %6)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #3
  %19 = shl nuw nsw i32 %7, 3
  %20 = add nsw i32 %19, -24
  %21 = call noundef nonnull align 4 dereferenceable(32) ptr @_ZN9base_uintILj256EElSEj(ptr noundef nonnull align 4 dereferenceable(32) %0, i32 noundef %20)
  br label %22

22:                                               ; preds = %16, %10
  %.0 = phi i32 [ %13, %10 ], [ %8, %16 ]
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %29, label %23

23:                                               ; preds = %22
  %24 = icmp ne i32 %.0, 0
  %25 = and i32 %1, 8388608
  %26 = icmp ne i32 %25, 0
  %27 = and i1 %26, %24
  %28 = zext i1 %27 to i8
  store i8 %28, ptr %2, align 1, !tbaa !5
  br label %29

29:                                               ; preds = %23, %22
  %.not24 = icmp eq ptr %3, null
  br i1 %.not24, label %43, label %30

30:                                               ; preds = %29
  %.not25 = icmp eq i32 %.0, 0
  br i1 %.not25, label %41, label %31

31:                                               ; preds = %30
  %32 = icmp ugt i32 %1, 587202559
  br i1 %32, label %41, label %33

33:                                               ; preds = %31
  %34 = icmp ugt i32 %.0, 255
  %35 = icmp ugt i32 %1, 570425343
  %or.cond = and i1 %35, %34
  br i1 %or.cond, label %41, label %36

36:                                               ; preds = %33
  %37 = icmp ugt i32 %.0, 65535
  %38 = icmp ugt i32 %1, 553648127
  %39 = and i1 %38, %37
  %40 = zext i1 %39 to i8
  br label %41

41:                                               ; preds = %31, %36, %33, %30
  %42 = phi i8 [ 0, %30 ], [ 1, %31 ], [ %40, %36 ], [ 1, %33 ]
  store i8 %42, ptr %3, align 1, !tbaa !5
  br label %43

43:                                               ; preds = %41, %29
  ret ptr %0
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13arith_uint256C2Em(ptr noundef nonnull align 4 dereferenceable(32), i64 noundef) unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(32) ptr @_ZN13arith_uint256aSEOS_(ptr noundef nonnull align 4 dereferenceable(32), ptr noundef nonnull align 4 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass