; 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 i32 @mpz_cmp_ui(ptr noundef, i64 noundef) #1

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mpz_invert(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [1 x %struct.__mpz_struct], align 16
  %9 = alloca [1 x %struct.__mpz_struct], align 16
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.__mpz_struct, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %20, label %16

16:                                               ; preds = %3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call i32 @mpz_cmpabs_ui(ptr noundef %17, i64 noundef 1)
  %19 = icmp sle i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %16, %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %60

21:                                               ; preds = %16
  %22 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %8, i64 0, i64 0
  call void @mpz_init(ptr noundef %22)
  %23 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %9, i64 0, i64 0
  call void @mpz_init(ptr noundef %23)
  %24 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %8, i64 0, i64 0
  %25 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %9, i64 0, i64 0
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mpz_gcdext(ptr noundef %24, ptr noundef %25, ptr noundef null, ptr noundef %26, ptr noundef %27)
  %28 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %8, i64 0, i64 0
  %29 = call i32 @mpz_cmp_ui(ptr noundef %28, i64 noundef 1)
  %30 = icmp eq i32 %29, 0
  %31 = zext i1 %30 to i32
  store i32 %31, ptr %10, align 4, !tbaa !12
  %32 = load i32, ptr %10, align 4, !tbaa !12
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %56

34:                                               ; preds = %21
  %35 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %9, i64 0, i64 0
  %36 = getelementptr inbounds %struct.__mpz_struct, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = icmp slt i32 %37, 0
  br i1 %38, label %39, label %53

39:                                               ; preds = %34
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.__mpz_struct, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = icmp sge i32 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %39
  %45 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %9, i64 0, i64 0
  %46 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %9, i64 0, i64 0
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mpz_add(ptr noundef %45, ptr noundef %46, ptr noundef %47)
  br label %52

48:                                               ; preds = %39
  %49 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %9, i64 0, i64 0
  %50 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %9, i64 0, i64 0
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mpz_sub(ptr noundef %49, ptr noundef %50, ptr noundef %51)
  br label %52

52:                                               ; preds = %48, %44
  br label %53

53:                                               ; preds = %52, %34
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %9, i64 0, i64 0
  call void @mpz_swap(ptr noundef %54, ptr noundef %55)
  br label %56

56:                                               ; preds = %53, %21
  %57 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %8, i64 0, i64 0
  call void @mpz_clear(ptr noundef %57)
  %58 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %9, i64 0, i64 0
  call void @mpz_clear(ptr noundef %58)
  %59 = load i32, ptr %10, align 4, !tbaa !12
  store i32 %59, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %60

60:                                               ; preds = %56, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #2
  %61 = load i32, ptr %4, align 4
  ret i32 %61
}

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, !11, i64 4}
!10 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, 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"

%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 i32 @mpz_cmp_ui(ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @mpz_invert(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca [1 x %struct.__mpz_struct], align 16
  %5 = alloca [1 x %struct.__mpz_struct], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #2
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %28, label %9

9:                                                ; preds = %3
  %10 = tail call i32 @mpz_cmpabs_ui(ptr noundef %2, i64 noundef 1)
  %11 = icmp slt i32 %10, 1
  br i1 %11, label %28, label %12

12:                                               ; preds = %9
  call void @mpz_init(ptr noundef nonnull %4)
  call void @mpz_init(ptr noundef nonnull %5)
  call void @mpz_gcdext(ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef null, ptr noundef nonnull %1, ptr noundef %2)
  %13 = call i32 @mpz_cmp_ui(ptr noundef nonnull %4, i64 noundef 1)
  %14 = icmp eq i32 %13, 0
  %15 = zext i1 %14 to i32
  br i1 %14, label %16, label %27

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %5, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %26

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %2, i64 4
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp sgt i32 %22, -1
  br i1 %23, label %24, label %25

24:                                               ; preds = %20
  call void @mpz_add(ptr noundef nonnull %5, ptr noundef nonnull %5, ptr noundef nonnull %2)
  br label %26

25:                                               ; preds = %20
  call void @mpz_sub(ptr noundef nonnull %5, ptr noundef nonnull %5, ptr noundef nonnull %2)
  br label %26

26:                                               ; preds = %24, %25, %16
  call void @mpz_swap(ptr noundef %0, ptr noundef nonnull %5)
  br label %27

27:                                               ; preds = %26, %12
  call void @mpz_clear(ptr noundef nonnull %4)
  call void @mpz_clear(ptr noundef nonnull %5)
  br label %28

28:                                               ; preds = %3, %9, %27
  %.0 = phi i32 [ %15, %27 ], [ 0, %9 ], [ 0, %3 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #2
  ret i32 %.0
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass