; 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
define dso_local double @mpz_get_d(ptr noundef %0) #1 {
  %2 = alloca double, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0x43F0000000000000, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.__mpz_struct, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = icmp sge i32 %10, 0
  br i1 %11, label %12, label %16

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.__mpz_struct, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !11
  br label %21

16:                                               ; preds = %1
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.__mpz_struct, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = sub nsw i32 0, %19
  br label %21

21:                                               ; preds = %16, %12
  %22 = phi i32 [ %15, %12 ], [ %20, %16 ]
  %23 = sext i32 %22 to i64
  store i64 %23, ptr %4, align 8, !tbaa !14
  %24 = load i64, ptr %4, align 8, !tbaa !14
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store double 0.000000e+00, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %61

27:                                               ; preds = %21
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.__mpz_struct, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = load i64, ptr %4, align 8, !tbaa !14
  %32 = add nsw i64 %31, -1
  store i64 %32, ptr %4, align 8, !tbaa !14
  %33 = getelementptr inbounds i64, ptr %30, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !14
  %35 = uitofp i64 %34 to double
  store double %35, ptr %5, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %39, %27
  %37 = load i64, ptr %4, align 8, !tbaa !14
  %38 = icmp sgt i64 %37, 0
  br i1 %38, label %39, label %51

39:                                               ; preds = %36
  %40 = load double, ptr %6, align 8, !tbaa !9
  %41 = load double, ptr %5, align 8, !tbaa !9
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.__mpz_struct, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = load i64, ptr %4, align 8, !tbaa !14
  %46 = add nsw i64 %45, -1
  store i64 %46, ptr %4, align 8, !tbaa !14
  %47 = getelementptr inbounds i64, ptr %44, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !14
  %49 = uitofp i64 %48 to double
  %50 = call double @llvm.fmuladd.f64(double %40, double %41, double %49)
  store double %50, ptr %5, align 8, !tbaa !9
  br label %36, !llvm.loop !17

51:                                               ; preds = %36
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.__mpz_struct, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !11
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %51
  %57 = load double, ptr %5, align 8, !tbaa !9
  %58 = fneg double %57
  store double %58, ptr %5, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %56, %51
  %60 = load double, ptr %5, align 8, !tbaa !9
  store double %60, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %61

61:                                               ; preds = %59, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %62 = load double, ptr %2, align 8
  ret double %62
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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 = { 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 = !{!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 = !{!"double", !7, i64 0}
!11 = !{!12, !13, i64 4}
!12 = !{!"", !13, i64 0, !13, i64 4, !6, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local double @mpz_get_d(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %41, label %5

5:                                                ; preds = %1
  %6 = tail call i32 @llvm.abs.i32(i32 %3, i1 true)
  %7 = zext nneg i32 %6 to i64
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = add nsw i64 %7, -1
  %11 = getelementptr inbounds i64, ptr %9, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !12
  %13 = uitofp i64 %12 to double
  %14 = icmp ugt i32 %6, 1
  br i1 %14, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %15 = add nsw i64 %7, -2
  %xtraiter = and i64 %10, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.01420.prol = phi double [ %20, %.lr.ph.prol ], [ %13, %.lr.ph.preheader ]
  %.01519.prol = phi i64 [ %16, %.lr.ph.prol ], [ %10, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %16 = add nsw i64 %.01519.prol, -1
  %17 = getelementptr inbounds i64, ptr %9, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !12
  %19 = uitofp i64 %18 to double
  %20 = tail call double @llvm.fmuladd.f64(double %.01420.prol, double 0x43F0000000000000, double %19)
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !14

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.01420.unr = phi double [ %13, %.lr.ph.preheader ], [ %20, %.lr.ph.prol ]
  %.01519.unr = phi i64 [ %10, %.lr.ph.preheader ], [ %16, %.lr.ph.prol ]
  %.lcssa.unr = phi double [ poison, %.lr.ph.preheader ], [ %20, %.lr.ph.prol ]
  %21 = icmp ult i64 %15, 3
  br i1 %21, label %._crit_edge, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %9, i64 -8
  %invariant.gep24 = getelementptr i8, ptr %9, i64 -16
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01420 = phi double [ %.01420.unr, %.lr.ph.preheader.new ], [ %37, %.lr.ph ]
  %.01519 = phi i64 [ %.01519.unr, %.lr.ph.preheader.new ], [ %33, %.lr.ph ]
  %gep = getelementptr i64, ptr %invariant.gep, i64 %.01519
  %22 = load i64, ptr %gep, align 8, !tbaa !12
  %23 = uitofp i64 %22 to double
  %24 = tail call double @llvm.fmuladd.f64(double %.01420, double 0x43F0000000000000, double %23)
  %gep25 = getelementptr i64, ptr %invariant.gep24, i64 %.01519
  %25 = load i64, ptr %gep25, align 8, !tbaa !12
  %26 = uitofp i64 %25 to double
  %27 = tail call double @llvm.fmuladd.f64(double %24, double 0x43F0000000000000, double %26)
  %28 = add nsw i64 %.01519, -3
  %29 = getelementptr inbounds i64, ptr %9, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !12
  %31 = uitofp i64 %30 to double
  %32 = tail call double @llvm.fmuladd.f64(double %27, double 0x43F0000000000000, double %31)
  %33 = add nsw i64 %.01519, -4
  %34 = getelementptr inbounds i64, ptr %9, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !12
  %36 = uitofp i64 %35 to double
  %37 = tail call double @llvm.fmuladd.f64(double %32, double 0x43F0000000000000, double %36)
  %38 = icmp ugt i64 %28, 1
  br i1 %38, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %5
  %.014.lcssa = phi double [ %13, %5 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %37, %.lr.ph ]
  %39 = icmp slt i32 %3, 0
  %40 = fneg double %.014.lcssa
  %.1 = select i1 %39, double %40, double %.014.lcssa
  br label %41

41:                                               ; preds = %1, %._crit_edge
  %.0 = phi double [ %.1, %._crit_edge ], [ 0.000000e+00, %1 ]
  ret double %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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 speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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.unroll.disable"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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