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

; 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.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u32_s = type { i32, ptr, i32, ptr }

@.str = external hidden unnamed_addr constant [70 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1

declare i32 @printf(ptr noundef, ...) #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

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

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

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

declare void @Hacl_Bignum_Montgomery_bn_precomp_r2_mod_n_u32(i32 noundef, i32 noundef, ptr noundef, ptr noundef) #0

declare i32 @Hacl_Bignum_ModInvLimb_mod_inv_uint32(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @Hacl_Bignum32_mont_ctx_init(i32 noundef %0, ptr noundef %1) #4 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u32_s, align 8
  %12 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %2
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = zext i32 %14 to i64
  %16 = icmp ugt i64 %15, 4611686018427387903
  br i1 %16, label %17, label %19

17:                                               ; preds = %13
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 409)
  call void @exit(i32 noundef 253) #8
  unreachable

19:                                               ; preds = %13
  br label %20

20:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #9
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = zext i32 %21 to i64
  %23 = call noalias ptr @calloc(i64 noundef %22, i64 noundef 4) #10
  store ptr %23, ptr %5, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %20
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = zext i32 %25 to i64
  %27 = icmp ugt i64 %26, 4611686018427387903
  br i1 %27, label %28, label %30

28:                                               ; preds = %24
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 411)
  call void @exit(i32 noundef 253) #8
  unreachable

30:                                               ; preds = %24
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #9
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = zext i32 %33 to i64
  %35 = call noalias ptr @calloc(i64 noundef %34, i64 noundef 4) #10
  store ptr %35, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #9
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %36, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #9
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %37, ptr %8, align 8, !tbaa !9
  %38 = load ptr, ptr %8, align 8, !tbaa !9
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = zext i32 %40 to i64
  %42 = mul i64 %41, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %38, ptr align 4 %39, i64 %42, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #9
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !9
  %45 = call i32 @Hacl_Bignum_Lib_bn_get_top_index_u32(i32 noundef %43, ptr noundef %44)
  %46 = mul i32 32, %45
  store i32 %46, ptr %9, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = load ptr, ptr %4, align 8, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  call void @Hacl_Bignum_Montgomery_bn_precomp_r2_mod_n_u32(i32 noundef %47, i32 noundef %48, ptr noundef %49, ptr noundef %50)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #9
  %51 = load ptr, ptr %4, align 8, !tbaa !9
  %52 = getelementptr inbounds i32, ptr %51, i64 0
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = call i32 @Hacl_Bignum_ModInvLimb_mod_inv_uint32(i32 noundef %53)
  store i32 %54, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #9
  %55 = getelementptr inbounds %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u32_s, ptr %11, i32 0, i32 0
  %56 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %56, ptr %55, align 8, !tbaa !11
  %57 = getelementptr inbounds %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u32_s, ptr %11, i32 0, i32 1
  %58 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %58, ptr %57, align 8, !tbaa !13
  %59 = getelementptr inbounds %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u32_s, ptr %11, i32 0, i32 2
  %60 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %60, ptr %59, align 8, !tbaa !14
  %61 = getelementptr inbounds %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u32_s, ptr %11, i32 0, i32 3
  %62 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %62, ptr %61, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #9
  %63 = call noalias ptr @malloc(i64 noundef 32) #11
  store ptr %63, ptr %12, align 8, !tbaa !9
  %64 = load ptr, ptr %12, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u32_s, ptr %64, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %65, ptr align 8 %11, i64 32, i1 false), !tbaa.struct !16
  %66 = load ptr, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #9
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #9
  ret ptr %66
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #5

; 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) #6

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #7

attributes #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 = { noreturn nounwind "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 willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = { nounwind allocsize(0,1) "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { nounwind allocsize(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 #8 = { noreturn nounwind }
attributes #9 = { nounwind }
attributes #10 = { nounwind allocsize(0,1) }
attributes #11 = { nounwind allocsize(0) }

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"Hacl_Bignum_MontArithmetic_bn_mont_ctx_u32_s", !6, i64 0, !10, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !10, i64 24}
!16 = !{i64 0, i64 4, !5, i64 8, i64 8, !9, i64 16, i64 4, !5, i64 24, i64 8, !9}


; 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: inlinehint nounwind uwtable
declare hidden i32 @Hacl_Bignum_Lib_bn_get_top_index_u32(i32 noundef, ptr noundef) local_unnamed_addr #0

declare void @Hacl_Bignum_Montgomery_bn_precomp_r2_mod_n_u32(i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @Hacl_Bignum_ModInvLimb_mod_inv_uint32(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @Hacl_Bignum32_mont_ctx_init(i32 noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = zext i32 %0 to i64
  %4 = tail call noalias ptr @calloc(i64 noundef %3, i64 noundef 4) #6
  %5 = tail call noalias ptr @calloc(i64 noundef %3, i64 noundef 4) #6
  %6 = shl nuw nsw i64 %3, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %1, i64 %6, i1 false)
  %7 = tail call i32 @Hacl_Bignum_Lib_bn_get_top_index_u32(i32 noundef %0, ptr noundef %1)
  %8 = shl i32 %7, 5
  tail call void @Hacl_Bignum_Montgomery_bn_precomp_r2_mod_n_u32(i32 noundef %0, i32 noundef %8, ptr noundef %1, ptr noundef %4) #7
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = tail call i32 @Hacl_Bignum_ModInvLimb_mod_inv_uint32(i32 noundef %9) #7
  %11 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #8
  store i32 %0, ptr %11, align 8, !tbaa !5
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 8
  store ptr %5, ptr %.sroa.42.0..sroa_idx, align 8, !tbaa !9
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 16
  store i32 %10, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !5
  %.sroa.63.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 24
  store ptr %4, ptr %.sroa.63.0..sroa_idx, align 8, !tbaa !9
  ret ptr %11
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

; 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) #4

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #5

attributes #0 = { 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 #1 = { "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 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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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: readwrite) }
attributes #5 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0,1) }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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