; LLVM IR from ftylitak/qzxing :: src/zxing/bigint/BigUnsigned.ll (ZN11BigUnsigned8setBlockEjm)

; 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.NumberlikeArray = type { i32, i32, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11BigUnsigned8setBlockEjm(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i64 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !11
  %8 = load ptr, ptr %4, align 8
  %9 = load i64, ptr %6, align 8, !tbaa !11
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %23

11:                                               ; preds = %3
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = getelementptr inbounds %class.NumberlikeArray, ptr %8, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = icmp ult i32 %12, %14
  br i1 %15, label %16, label %22

16:                                               ; preds = %11
  %17 = getelementptr inbounds %class.NumberlikeArray, ptr %8, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds i64, ptr %18, i64 %20
  store i64 0, ptr %21, align 8, !tbaa !11
  call void @_ZN11BigUnsigned15zapLeadingZerosEv(ptr noundef nonnull align 8 dereferenceable(16) %8)
  br label %22

22:                                               ; preds = %16, %11
  br label %58

23:                                               ; preds = %3
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = getelementptr inbounds %class.NumberlikeArray, ptr %8, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = icmp uge i32 %24, %26
  br i1 %27, label %28, label %51

28:                                               ; preds = %23
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = add i32 %29, 1
  call void @_ZN15NumberlikeArrayImE15allocateAndCopyEj(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef %30)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %31 = getelementptr inbounds %class.NumberlikeArray, ptr %8, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !13
  store i32 %32, ptr %7, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %44, %28
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = icmp ult i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %47

38:                                               ; preds = %33
  %39 = getelementptr inbounds %class.NumberlikeArray, ptr %8, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds i64, ptr %40, i64 %42
  store i64 0, ptr %43, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %38
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = add i32 %45, 1
  store i32 %46, ptr %7, align 4, !tbaa !9
  br label %33, !llvm.loop !16

47:                                               ; preds = %37
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = add i32 %48, 1
  %50 = getelementptr inbounds %class.NumberlikeArray, ptr %8, i32 0, i32 1
  store i32 %49, ptr %50, align 4, !tbaa !13
  br label %51

51:                                               ; preds = %47, %23
  %52 = load i64, ptr %6, align 8, !tbaa !11
  %53 = getelementptr inbounds %class.NumberlikeArray, ptr %8, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds i64, ptr %54, i64 %56
  store i64 %52, ptr %57, align 8, !tbaa !11
  br label %58

58:                                               ; preds = %51, %22
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11BigUnsigned15zapLeadingZerosEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN15NumberlikeArrayImE15allocateAndCopyEj(ptr noundef nonnull align 8 dereferenceable(16), 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) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 4}
!14 = !{!"_ZTS15NumberlikeArrayImE", !10, i64 0, !10, i64 4, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11BigUnsigned8setBlockEjm(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = icmp eq i64 %2, 0
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp ugt i32 %6, %1
  br i1 %4, label %8, label %14

8:                                                ; preds = %3
  br i1 %7, label %9, label %33

9:                                                ; preds = %8
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = zext i32 %1 to i64
  %13 = getelementptr inbounds i64, ptr %11, i64 %12
  store i64 0, ptr %13, align 8, !tbaa !12
  tail call void @_ZN11BigUnsigned15zapLeadingZerosEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  br label %33

14:                                               ; preds = %3
  br i1 %7, label %28, label %15

15:                                               ; preds = %14
  %16 = add i32 %1, 1
  tail call void @_ZN15NumberlikeArrayImE15allocateAndCopyEj(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %16)
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = icmp ult i32 %17, %1
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %15
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = zext i32 %17 to i64
  %22 = shl nuw nsw i64 %21, 3
  %scevgep = getelementptr i8, ptr %20, i64 %22
  %23 = xor i32 %17, -1
  %24 = add i32 %23, %1
  %25 = zext i32 %24 to i64
  %26 = shl nuw nsw i64 %25, 3
  %27 = add nuw nsw i64 %26, 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %scevgep, i8 0, i64 %27, i1 false), !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %15
  store i32 %16, ptr %5, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %._crit_edge, %14
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = zext i32 %1 to i64
  %32 = getelementptr inbounds i64, ptr %30, i64 %31
  store i64 %2, ptr %32, align 8, !tbaa !12
  br label %33

33:                                               ; preds = %8, %9, %28
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11BigUnsigned15zapLeadingZerosEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN15NumberlikeArrayImE15allocateAndCopyEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !7, i64 4}
!6 = !{!"_ZTS15NumberlikeArrayImE", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass