; LLVM IR from Water-Melon/Melon :: src (mln_bignum)

; 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.mln_bignum_t = type { i32, i32, [257 x i64] }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__mln_bignum_abs_compare(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @mln_bignum_prime(ptr noundef nonnull %0, i32 noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %struct.mln_bignum_t, align 8
  %7 = alloca %struct.mln_bignum_t, align 8
  %8 = alloca %struct.mln_bignum_t, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp ugt i32 %10, 4112
  br i1 %11, label %15, label %12

12:                                               ; preds = %2
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp ult i32 %13, 3
  br i1 %14, label %15, label %16

15:                                               ; preds = %12, %2
  store i32 -1, ptr %3, align 4
  br label %54

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 2064, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 2064, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 2064, ptr %8) #5
  call void @llvm.memset.p0.i64(ptr align 8 %8, i8 0, i64 2064, i1 false)
  %17 = getelementptr inbounds %struct.mln_bignum_t, ptr %8, i32 0, i32 1
  store i32 1, ptr %17, align 4
  %18 = getelementptr inbounds %struct.mln_bignum_t, ptr %8, i32 0, i32 2
  %19 = getelementptr inbounds [257 x i64], ptr %18, i64 0, i64 0
  store i64 1, ptr %19, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  br label %20

20:                                               ; preds = %51, %25, %16
  br label %21

21:                                               ; preds = %20
  %22 = load i32, ptr %5, align 4, !tbaa !9
  call void @mln_bignum_random_prime(ptr noundef %6, i32 noundef %22)
  %23 = call i32 @__mln_bignum_abs_compare(ptr noundef %6, ptr noundef %8)
  %24 = icmp sle i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  br label %20

26:                                               ; preds = %21
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = icmp ule i32 %27, 512
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  br label %33

30:                                               ; preds = %26
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = lshr i32 %31, 9
  br label %33

33:                                               ; preds = %30, %29
  %34 = phi i32 [ 4, %29 ], [ %32, %30 ]
  store i32 %34, ptr %9, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %44, %33
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = icmp ugt i32 %36, 0
  br i1 %37, label %38, label %47

38:                                               ; preds = %35
  %39 = load i32, ptr %5, align 4, !tbaa !9
  call void @mln_bignum_random_scope(ptr noundef %7, i32 noundef %39, ptr noundef %6)
  %40 = call i32 @mln_bignum_witness(ptr noundef %7, ptr noundef %6)
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %38
  br label %47

43:                                               ; preds = %38
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = add i32 %45, -1
  store i32 %46, ptr %9, align 4, !tbaa !9
  br label %35, !llvm.loop !13

47:                                               ; preds = %42, %35
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %47
  br label %52

51:                                               ; preds = %47
  br label %20

52:                                               ; preds = %50
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %53, ptr align 8 %6, i64 2064, i1 false), !tbaa.struct !15
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 2064, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 2064, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 2064, ptr %6) #5
  br label %54

54:                                               ; preds = %52, %15
  %55 = load i32, ptr %3, align 4
  ret i32 %55
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_bignum_random_prime(ptr noundef, i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_bignum_random_scope(ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mln_bignum_witness(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 2056, !16}
!16 = !{!7, !7, 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.mln_bignum_t = type { i32, i32, [257 x i64] }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__mln_bignum_abs_compare(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @mln_bignum_prime(ptr nocapture noundef nonnull writeonly %0, i32 noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.mln_bignum_t, align 8
  %4 = alloca %struct.mln_bignum_t, align 8
  %5 = alloca %struct.mln_bignum_t, align 8
  %6 = add i32 %1, -4113
  %or.cond = icmp ult i32 %6, -4110
  br i1 %or.cond, label %18, label %7

7:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 2064, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 2064, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 2064, ptr nonnull %5) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(2064) %5, i8 0, i64 2064, i1 false)
  %8 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 1, ptr %8, align 4
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  store i64 1, ptr %9, align 8, !tbaa !5
  %10 = icmp ult i32 %1, 513
  %11 = lshr i32 %1, 9
  %spec.select = select i1 %10, i32 4, i32 %11
  %cond14 = icmp eq i32 %spec.select, 0
  br i1 %cond14, label %.backedge.us, label %.split

.backedge.us:                                     ; preds = %7, %.backedge.us
  call void @mln_bignum_random_prime(ptr noundef nonnull %3, i32 noundef %1)
  %12 = call i32 @__mln_bignum_abs_compare(ptr noundef nonnull %3, ptr noundef nonnull %5)
  %13 = icmp slt i32 %12, 1
  br i1 %13, label %.backedge.us, label %._crit_edge

.split:                                           ; preds = %7, %.split.backedge
  call void @mln_bignum_random_prime(ptr noundef nonnull %3, i32 noundef %1)
  %14 = call i32 @__mln_bignum_abs_compare(ptr noundef nonnull %3, ptr noundef nonnull %5)
  %15 = icmp slt i32 %14, 1
  br i1 %15, label %.split.backedge, label %.lr.ph

.split.backedge:                                  ; preds = %.lr.ph, %.split
  br label %.split

select.unfold:                                    ; preds = %.lr.ph
  %16 = add nsw i32 %.015, -1
  %cond = icmp eq i32 %16, 0
  br i1 %cond, label %._crit_edge, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %.split, %select.unfold
  %.015 = phi i32 [ %16, %select.unfold ], [ %spec.select, %.split ]
  call void @mln_bignum_random_scope(ptr noundef nonnull %4, i32 noundef %1, ptr noundef nonnull %3)
  %17 = call i32 @mln_bignum_witness(ptr noundef nonnull %4, ptr noundef nonnull %3)
  %.not13 = icmp eq i32 %17, 0
  br i1 %.not13, label %select.unfold, label %.split.backedge

._crit_edge:                                      ; preds = %select.unfold, %.backedge.us
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(2064) %0, ptr noundef nonnull align 8 dereferenceable(2064) %3, i64 2064, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 2064, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 2064, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 2064, ptr nonnull %3) #5
  br label %18

18:                                               ; preds = %2, %._crit_edge
  %.011 = phi i32 [ 0, %._crit_edge ], [ -1, %2 ]
  ret i32 %.011
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_bignum_random_prime(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_bignum_random_scope(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mln_bignum_witness(ptr noundef, ptr noundef) local_unnamed_addr #2

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass