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

; 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_32_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 [128 x i32], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca [128 x i32], align 16
  %18 = alloca i32, align 4
  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 [128 x i32], 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 [128 x i32], ptr %7, i64 0, i64 0
  store i32 1, ptr %20, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds i32, ptr %21, i64 0
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = and i32 %23, 1
  store i32 %24, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = sub i32 0, %25
  store i32 %26, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %27

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

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

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

79:                                               ; 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)
  %80 = load i32, ptr %16, align 4, !tbaa !9
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds [128 x i32], ptr %17, i64 0, i64 0
  call void @precompr2(i32 noundef %80, ptr noundef %81, ptr noundef %82)
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #6
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds i32, ptr %83, i64 0
  %85 = load i32, ptr %84, align 4, !tbaa !9
  %86 = call i32 @Hacl_Bignum_ModInvLimb_mod_inv_uint32(i32 noundef %85)
  store i32 %86, ptr %18, align 4, !tbaa !9
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = load i32, ptr %18, align 4, !tbaa !9
  %89 = getelementptr inbounds [128 x i32], ptr %17, i64 0, i64 0
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  call void @bn_slow_precomp(ptr noundef %87, i32 noundef %88, ptr noundef %89, ptr noundef %90, ptr noundef %91)
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 512, ptr %17) #6
  br label %94

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

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

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

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

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

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

declare i32 @Hacl_Bignum_ModInvLimb_mod_inv_uint32(i32 noundef) #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bn_slow_precomp(ptr noundef, i32 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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_32_mod(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca [128 x i32], align 16
  %5 = alloca [128 x i32], 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 i32 1, ptr %4, align 16, !tbaa !5
  %6 = load i32, ptr %0, align 4, !tbaa !5
  br label %13

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

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

24:                                               ; preds = %7
  %25 = shl i32 %10, 5
  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 %25, ptr noundef nonnull %0, ptr noundef nonnull %5)
  %26 = load i32, ptr %0, align 4, !tbaa !5
  %27 = call i32 @Hacl_Bignum_ModInvLimb_mod_inv_uint32(i32 noundef %26) #6
  call void @bn_slow_precomp(ptr noundef nonnull %0, i32 noundef %27, ptr noundef nonnull %5, ptr noundef %1, ptr noundef %2)
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %5) #6
  br label %29

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

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @Hacl_Bignum_Lib_bn_get_top_index_u32(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 i32 @Hacl_Bignum_ModInvLimb_mod_inv_uint32(i32 noundef) local_unnamed_addr #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bn_slow_precomp(ptr noundef, i32 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 = !{!"int", !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