; LLVM IR from cryspen/libcrux :: sys/hacl/c/src (Hacl_Bignum4096)

; 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"

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @Hacl_Bignum4096_mod(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [64 x i64], align 16
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca [64 x i64], align 16
  %18 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 512, ptr %7) #6
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 0, i64 512, i1 false)
  %19 = getelementptr inbounds [64 x i64], ptr %7, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %19, i8 0, i64 512, i1 false)
  %20 = getelementptr inbounds [64 x i64], ptr %7, i64 0, i64 0
  store i64 1, ptr %20, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds i64, ptr %21, i64 0
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = and i64 %23, 1
  store i64 %24, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %25 = load i64, ptr %8, align 8, !tbaa !9
  %26 = sub i64 0, %25
  store i64 %26, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  store i64 0, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %27

27:                                               ; preds = %66, %3
  %28 = load i32, ptr %11, align 4, !tbaa !11
  %29 = icmp ult i32 %28, 64
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %69

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %32 = load i32, ptr %11, align 4, !tbaa !11
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [64 x i64], ptr %7, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %11, align 4, !tbaa !11
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds i64, ptr %36, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = call i64 @FStar_UInt64_eq_mask(i64 noundef %35, i64 noundef %40)
  store i64 %41, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %42 = load i32, ptr %11, align 4, !tbaa !11
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [64 x i64], ptr %7, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %11, align 4, !tbaa !11
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds i64, ptr %46, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = call i64 @FStar_UInt64_gte_mask(i64 noundef %45, i64 noundef %50)
  %52 = xor i64 %51, -1
  store i64 %52, ptr %13, align 8, !tbaa !9
  %53 = load i64, ptr %12, align 8, !tbaa !9
  %54 = load i64, ptr %10, align 8, !tbaa !9
  %55 = and i64 %53, %54
  %56 = load i64, ptr %12, align 8, !tbaa !9
  %57 = xor i64 %56, -1
  %58 = load i64, ptr %13, align 8, !tbaa !9
  %59 = and i64 %58, -1
  %60 = load i64, ptr %13, align 8, !tbaa !9
  %61 = xor i64 %60, -1
  %62 = and i64 %61, 0
  %63 = or i64 %59, %62
  %64 = and i64 %57, %63
  %65 = or i64 %55, %64
  store i64 %65, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %66

66:                                               ; preds = %31
  %67 = load i32, ptr %11, align 4, !tbaa !11
  %68 = add i32 %67, 1
  store i32 %68, ptr %11, align 4, !tbaa !11
  br label %27, !llvm.loop !13

69:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %70 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %70, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %71 = load i64, ptr %9, align 8, !tbaa !9
  %72 = load i64, ptr %14, align 8, !tbaa !9
  %73 = and i64 %71, %72
  store i64 %73, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = call i64 @Hacl_Bignum_Lib_bn_get_top_index_u64(i32 noundef 64, ptr noundef %74)
  %76 = trunc i64 %75 to i32
  %77 = mul i32 64, %76
  store i32 %77, ptr %16, align 4, !tbaa !11
  %78 = load i64, ptr %15, align 8, !tbaa !9
  %79 = icmp eq i64 %78, -1
  br i1 %79, label %80, label %93

80:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 512, ptr %17) #6
  call void @llvm.memset.p0.i64(ptr align 16 %17, i8 0, i64 512, i1 false)
  %81 = load i32, ptr %16, align 4, !tbaa !11
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds [64 x i64], ptr %17, i64 0, i64 0
  call void @precompr2(i32 noundef %81, ptr noundef %82, ptr noundef %83)
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds i64, ptr %84, i64 0
  %86 = load i64, ptr %85, align 8, !tbaa !9
  %87 = call i64 @Hacl_Bignum_ModInvLimb_mod_inv_uint64(i64 noundef %86)
  store i64 %87, ptr %18, align 8, !tbaa !9
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = load i64, ptr %18, align 8, !tbaa !9
  %90 = getelementptr inbounds [64 x i64], ptr %17, i64 0, i64 0
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  call void @bn_slow_precomp(ptr noundef %88, i64 noundef %89, ptr noundef %90, ptr noundef %91, ptr noundef %92)
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 512, ptr %17) #6
  br label %95

93:                                               ; preds = %69
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %94, i8 0, i64 512, i1 false)
  br label %95

95:                                               ; preds = %93, %80
  %96 = load i64, ptr %15, align 8, !tbaa !9
  %97 = icmp eq i64 %96, -1
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 512, ptr %7) #6
  ret i1 %97
}

; Function Attrs: noinline nounwind uwtable
declare hidden i64 @FStar_UInt64_eq_mask(i64 noundef, i64 noundef) #3

; Function Attrs: noinline nounwind uwtable
declare hidden i64 @FStar_UInt64_gte_mask(i64 noundef, i64 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @Hacl_Bignum_Lib_bn_get_top_index_u64(i32 noundef, ptr noundef) #4

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

declare i64 @Hacl_Bignum_ModInvLimb_mod_inv_uint64(i64 noundef) #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bn_slow_precomp(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 = { noinline 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 = { 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 #5 = { "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 #6 = { 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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @Hacl_Bignum4096_mod(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca [64 x i64], align 16
  %5 = alloca [64 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 512, ptr nonnull %4) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(512) %4, i8 0, i64 512, i1 false)
  store i64 1, ptr %4, align 16, !tbaa !5
  %6 = load i64, ptr %0, align 8, !tbaa !5
  br label %13

7:                                                ; preds = %13
  %8 = and i64 %6, 1
  %9 = icmp ne i64 %8, 0
  %10 = tail call i64 @Hacl_Bignum_Lib_bn_get_top_index_u64(i32 noundef 64, ptr noundef nonnull %0)
  %11 = icmp eq i64 %23, -1
  %12 = select i1 %9, i1 %11, i1 false
  br i1 %12, label %24, label %29

13:                                               ; preds = %3, %13
  %indvars.iv = phi i64 [ 0, %3 ], [ %indvars.iv.next, %13 ]
  %.030 = phi i64 [ 0, %3 ], [ %23, %13 ]
  %14 = getelementptr inbounds [64 x i64], ptr %4, i64 0, i64 %indvars.iv
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = tail call i64 @FStar_UInt64_eq_mask(i64 noundef %15, i64 noundef %17)
  %19 = load i64, ptr %16, align 8, !tbaa !5
  %20 = tail call i64 @FStar_UInt64_gte_mask(i64 noundef %15, i64 noundef %19)
  %21 = and i64 %18, %.030
  %.demorgan = or i64 %20, %18
  %22 = xor i64 %.demorgan, -1
  %23 = or i64 %21, %22
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 64
  br i1 %exitcond.not, label %7, label %13, !llvm.loop !9

24:                                               ; preds = %7
  %25 = trunc i64 %10 to i32
  %26 = shl i32 %25, 6
  call void @llvm.lifetime.start.p0(i64 512, ptr nonnull %5) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(512) %5, i8 0, i64 512, i1 false)
  call void @precompr2(i32 noundef %26, ptr noundef nonnull %0, ptr noundef nonnull %5)
  %27 = load i64, ptr %0, align 8, !tbaa !5
  %28 = call i64 @Hacl_Bignum_ModInvLimb_mod_inv_uint64(i64 noundef %27) #6
  call void @bn_slow_precomp(ptr noundef nonnull %0, i64 noundef %28, ptr noundef nonnull %5, ptr noundef %1, ptr noundef %2)
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %5) #6
  br label %30

29:                                               ; preds = %7
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(512) %2, i8 0, i64 512, i1 false)
  br label %30

30:                                               ; preds = %29, %24
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %4) #6
  ret i1 %12
}

; Function Attrs: noinline nounwind uwtable
declare hidden i64 @FStar_UInt64_eq_mask(i64 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: noinline nounwind uwtable
declare hidden i64 @FStar_UInt64_gte_mask(i64 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @Hacl_Bignum_Lib_bn_get_top_index_u64(i32 noundef, ptr noundef) local_unnamed_addr #4

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

declare i64 @Hacl_Bignum_ModInvLimb_mod_inv_uint64(i64 noundef) local_unnamed_addr #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bn_slow_precomp(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 = { noinline 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 = { 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 #5 = { "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 #6 = { 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"}


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