; LLVM IR from cryptid-org/cryptid-native :: dependencies/gmp/src (mini-gmp)

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

; 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
declare dso_local void @mpz_init(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @mpz_clear(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @mpz_set_ui(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @mpz_mul_ui(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @mpz_divexact(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @mpz_fac_ui(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @mpz_bin_uiui(ptr noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca [1 x %struct.__mpz_struct], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load i64, ptr %6, align 8, !tbaa !9
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = icmp ule i64 %9, %10
  %12 = zext i1 %11 to i32
  %13 = sext i32 %12 to i64
  call void @mpz_set_ui(ptr noundef %8, i64 noundef %13)
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = lshr i64 %15, 1
  %17 = icmp ugt i64 %14, %16
  br i1 %17, label %18, label %29

18:                                               ; preds = %3
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = icmp ule i64 %19, %20
  br i1 %21, label %22, label %26

22:                                               ; preds = %18
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = sub i64 %23, %24
  br label %27

26:                                               ; preds = %18
  br label %27

27:                                               ; preds = %26, %22
  %28 = phi i64 [ %25, %22 ], [ 0, %26 ]
  store i64 %28, ptr %6, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %27, %3
  %30 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %7, i64 0, i64 0
  call void @mpz_init(ptr noundef %30)
  %31 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %7, i64 0, i64 0
  %32 = load i64, ptr %6, align 8, !tbaa !9
  call void @mpz_fac_ui(ptr noundef %31, i64 noundef %32)
  br label %33

33:                                               ; preds = %41, %29
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = icmp ugt i64 %34, 0
  br i1 %35, label %36, label %44

36:                                               ; preds = %33
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = add i64 %39, -1
  store i64 %40, ptr %5, align 8, !tbaa !9
  call void @mpz_mul_ui(ptr noundef %37, ptr noundef %38, i64 noundef %39)
  br label %41

41:                                               ; preds = %36
  %42 = load i64, ptr %6, align 8, !tbaa !9
  %43 = add i64 %42, -1
  store i64 %43, ptr %6, align 8, !tbaa !9
  br label %33, !llvm.loop !11

44:                                               ; preds = %33
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %7, i64 0, i64 0
  call void @mpz_divexact(ptr noundef %45, ptr noundef %46, ptr noundef %47)
  %48 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %7, i64 0, i64 0
  call void @mpz_clear(ptr noundef %48)
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #2
  ret void
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !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"

%struct.__mpz_struct = type { i32, i32, ptr }

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @mpz_init(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mpz_clear(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mpz_set_ui(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mpz_mul_ui(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mpz_divexact(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mpz_fac_ui(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @mpz_bin_uiui(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = alloca [1 x %struct.__mpz_struct], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  %5 = icmp ule i64 %2, %1
  %6 = zext i1 %5 to i64
  tail call void @mpz_set_ui(ptr noundef %0, i64 noundef %6)
  %7 = lshr i64 %1, 1
  %8 = icmp ult i64 %7, %2
  %9 = tail call i64 @llvm.usub.sat.i64(i64 %1, i64 %2)
  %.0 = select i1 %8, i64 %9, i64 %2
  call void @mpz_init(ptr noundef nonnull %4)
  call void @mpz_fac_ui(ptr noundef nonnull %4, i64 noundef %.0)
  %.not19 = icmp eq i64 %.0, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.121 = phi i64 [ %11, %.lr.ph ], [ %.0, %3 ]
  %.01620 = phi i64 [ %10, %.lr.ph ], [ %1, %3 ]
  %10 = add i64 %.01620, -1
  call void @mpz_mul_ui(ptr noundef %0, ptr noundef %0, i64 noundef %.01620)
  %11 = add i64 %.121, -1
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %3
  call void @mpz_divexact(ptr noundef %0, ptr noundef %0, ptr noundef nonnull %4)
  call void @mpz_clear(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.usub.sat.i64(i64, i64) #2

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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