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

@gmp_free_func = external hidden global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [92 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__.mpz_sizeinbase = external hidden unnamed_addr constant [49 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [11 x i8], align 1

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

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @gmp_xalloc_limbs(i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @mpz_sizeinbase(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca %struct.gmp_div_inverse, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp sge i32 %13, 2
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  br label %17

16:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.23, ptr noundef @.str.1, i32 noundef 4035, ptr noundef @__PRETTY_FUNCTION__.mpz_sizeinbase) #4
  unreachable

17:                                               ; preds = %15
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = icmp sle i32 %18, 36
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  br label %22

21:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.24, ptr noundef @.str.1, i32 noundef 4036, ptr noundef @__PRETTY_FUNCTION__.mpz_sizeinbase) #4
  unreachable

22:                                               ; preds = %20
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.__mpz_struct, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = icmp sge i32 %25, 0
  br i1 %26, label %27, label %31

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.__mpz_struct, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !11
  br label %36

31:                                               ; preds = %22
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.__mpz_struct, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = sub nsw i32 0, %34
  br label %36

36:                                               ; preds = %31, %27
  %37 = phi i32 [ %30, %27 ], [ %35, %31 ]
  %38 = sext i32 %37 to i64
  store i64 %38, ptr %6, align 8, !tbaa !13
  %39 = load i64, ptr %6, align 8, !tbaa !13
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  store i64 1, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %107

42:                                               ; preds = %36
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.__mpz_struct, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  store ptr %45, ptr %7, align 8, !tbaa !5
  %46 = load i64, ptr %6, align 8, !tbaa !13
  %47 = sub nsw i64 %46, 1
  %48 = mul i64 %47, 64
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load i64, ptr %6, align 8, !tbaa !13
  %51 = sub nsw i64 %50, 1
  %52 = getelementptr inbounds i64, ptr %49, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !13
  %54 = call i64 @mpn_limb_size_in_base_2(i64 noundef %53)
  %55 = add i64 %48, %54
  store i64 %55, ptr %9, align 8, !tbaa !13
  %56 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %56, label %75 [
    i32 2, label %57
    i32 4, label %59
    i32 8, label %63
    i32 16, label %67
    i32 32, label %71
  ]

57:                                               ; preds = %42
  %58 = load i64, ptr %9, align 8, !tbaa !13
  store i64 %58, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %107

59:                                               ; preds = %42
  %60 = load i64, ptr %9, align 8, !tbaa !13
  %61 = add i64 %60, 1
  %62 = udiv i64 %61, 2
  store i64 %62, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %107

63:                                               ; preds = %42
  %64 = load i64, ptr %9, align 8, !tbaa !13
  %65 = add i64 %64, 2
  %66 = udiv i64 %65, 3
  store i64 %66, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %107

67:                                               ; preds = %42
  %68 = load i64, ptr %9, align 8, !tbaa !13
  %69 = add i64 %68, 3
  %70 = udiv i64 %69, 4
  store i64 %70, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %107

71:                                               ; preds = %42
  %72 = load i64, ptr %9, align 8, !tbaa !13
  %73 = add i64 %72, 4
  %74 = udiv i64 %73, 5
  store i64 %74, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %107

75:                                               ; preds = %42
  %76 = load i64, ptr %6, align 8, !tbaa !13
  %77 = call ptr @gmp_xalloc_limbs(i64 noundef %76)
  store ptr %77, ptr %8, align 8, !tbaa !5
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = load i64, ptr %6, align 8, !tbaa !13
  call void @mpn_copyi(ptr noundef %78, ptr noundef %79, i64 noundef %80)
  %81 = load i32, ptr %5, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  call void @mpn_div_qr_1_invert(ptr noundef %10, i64 noundef %82)
  store i64 0, ptr %11, align 8, !tbaa !13
  br label %83

83:                                               ; preds = %100, %75
  %84 = load i64, ptr %11, align 8, !tbaa !13
  %85 = add i64 %84, 1
  store i64 %85, ptr %11, align 8, !tbaa !13
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = load i64, ptr %6, align 8, !tbaa !13
  %89 = call i64 @mpn_div_qr_1_preinv(ptr noundef %86, ptr noundef %87, i64 noundef %88, ptr noundef %10)
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = load i64, ptr %6, align 8, !tbaa !13
  %92 = sub nsw i64 %91, 1
  %93 = getelementptr inbounds i64, ptr %90, i64 %92
  %94 = load i64, ptr %93, align 8, !tbaa !13
  %95 = icmp eq i64 %94, 0
  %96 = zext i1 %95 to i32
  %97 = sext i32 %96 to i64
  %98 = load i64, ptr %6, align 8, !tbaa !13
  %99 = sub nsw i64 %98, %97
  store i64 %99, ptr %6, align 8, !tbaa !13
  br label %100

100:                                              ; preds = %83
  %101 = load i64, ptr %6, align 8, !tbaa !13
  %102 = icmp sgt i64 %101, 0
  br i1 %102, label %83, label %103, !llvm.loop !16

103:                                              ; preds = %100
  %104 = load ptr, ptr @gmp_free_func, align 8, !tbaa !5
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  call void %104(ptr noundef %105, i64 noundef 0)
  %106 = load i64, ptr %11, align 8, !tbaa !13
  store i64 %106, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %107

107:                                              ; preds = %103, %71, %67, %63, %59, %57, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %108 = load i64, ptr %3, align 8
  ret i64 %108
}

; Function Attrs: nounwind uwtable
declare hidden i64 @mpn_limb_size_in_base_2(i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @mpn_div_qr_1_invert(ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @mpn_div_qr_1_preinv(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #0

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !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"

%struct.gmp_div_inverse = type { i32, i64, i64, i64 }

@gmp_free_func = external hidden local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [92 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__.mpz_sizeinbase = external hidden unnamed_addr constant [49 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [11 x i8], align 1

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

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden ptr @gmp_xalloc_limbs(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @mpz_sizeinbase(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.gmp_div_inverse, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  %4 = icmp sgt i32 %1, 1
  br i1 %4, label %6, label %5

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.23, ptr noundef nonnull @.str.1, i32 noundef 4035, ptr noundef nonnull @__PRETTY_FUNCTION__.mpz_sizeinbase) #5
  unreachable

6:                                                ; preds = %2
  %7 = icmp ult i32 %1, 37
  br i1 %7, label %9, label %8

8:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.24, ptr noundef nonnull @.str.1, i32 noundef 4036, ptr noundef nonnull @__PRETTY_FUNCTION__.mpz_sizeinbase) #5
  unreachable

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = tail call i32 @llvm.abs.i32(i32 %11, i1 true)
  %13 = zext nneg i32 %12 to i64
  %14 = icmp eq i32 %11, 0
  br i1 %14, label %48, label %15

15:                                               ; preds = %9
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = add nsw i64 %13, -1
  %19 = shl nuw nsw i64 %18, 6
  %20 = getelementptr inbounds i64, ptr %17, i64 %18
  %21 = load i64, ptr %20, align 8, !tbaa !12
  %22 = tail call i64 @mpn_limb_size_in_base_2(i64 noundef %21)
  %23 = add i64 %22, %19
  switch i32 %1, label %36 [
    i32 2, label %48
    i32 4, label %24
    i32 8, label %27
    i32 16, label %30
    i32 32, label %33
  ]

24:                                               ; preds = %15
  %25 = add i64 %23, 1
  %26 = lshr i64 %25, 1
  br label %48

27:                                               ; preds = %15
  %28 = add i64 %23, 2
  %29 = udiv i64 %28, 3
  br label %48

30:                                               ; preds = %15
  %31 = add i64 %23, 3
  %32 = lshr i64 %31, 2
  br label %48

33:                                               ; preds = %15
  %34 = add i64 %23, 4
  %35 = udiv i64 %34, 5
  br label %48

36:                                               ; preds = %15
  %37 = tail call ptr @gmp_xalloc_limbs(i64 noundef %13)
  tail call void @mpn_copyi(ptr noundef %37, ptr noundef nonnull %17, i64 noundef %13)
  %38 = zext nneg i32 %1 to i64
  call void @mpn_div_qr_1_invert(ptr noundef nonnull %3, i64 noundef %38)
  %invariant.gep = getelementptr i8, ptr %37, i64 -8
  br label %39

39:                                               ; preds = %39, %36
  %.032 = phi i64 [ %13, %36 ], [ %44, %39 ]
  %.0 = phi i64 [ 0, %36 ], [ %40, %39 ]
  %40 = add i64 %.0, 1
  %41 = call i64 @mpn_div_qr_1_preinv(ptr noundef %37, ptr noundef %37, i64 noundef %.032, ptr noundef nonnull %3)
  %gep = getelementptr i64, ptr %invariant.gep, i64 %.032
  %42 = load i64, ptr %gep, align 8, !tbaa !12
  %43 = icmp eq i64 %42, 0
  %.neg = sext i1 %43 to i64
  %44 = add nsw i64 %.032, %.neg
  %45 = icmp sgt i64 %44, 0
  br i1 %45, label %39, label %46, !llvm.loop !14

46:                                               ; preds = %39
  %47 = load ptr, ptr @gmp_free_func, align 8, !tbaa !16
  call void %47(ptr noundef nonnull %37, i64 noundef 0) #4
  br label %48

48:                                               ; preds = %15, %9, %46, %33, %30, %27, %24
  %.031 = phi i64 [ %40, %46 ], [ %35, %33 ], [ %32, %30 ], [ %29, %27 ], [ %26, %24 ], [ 1, %9 ], [ %23, %15 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  ret i64 %.031
}

; Function Attrs: nounwind uwtable
declare hidden i64 @mpn_limb_size_in_base_2(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @mpn_div_qr_1_invert(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @mpn_div_qr_1_preinv(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 4}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass