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

; 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_u64_s = type { i32, ptr, i64, 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 i64 @Hacl_Bignum_Lib_bn_get_top_index_u64(i32 noundef, ptr noundef) #3

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

declare i64 @Hacl_Bignum_ModInvLimb_mod_inv_uint64(i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @Hacl_Bignum64_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 i64, align 8
  %11 = alloca %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u64_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, 2305843009213693951
  br i1 %16, label %17, label %19

17:                                               ; preds = %13
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 408)
  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 8) #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, 2305843009213693951
  br i1 %27, label %28, label %30

28:                                               ; preds = %24
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 410)
  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 8) #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, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %38, ptr align 8 %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 i64 @Hacl_Bignum_Lib_bn_get_top_index_u64(i32 noundef %43, ptr noundef %44)
  %46 = trunc i64 %45 to i32
  %47 = mul i32 64, %46
  store i32 %47, ptr %9, align 4, !tbaa !5
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !9
  %51 = load ptr, ptr %7, align 8, !tbaa !9
  call void @Hacl_Bignum_Montgomery_bn_precomp_r2_mod_n_u64(i32 noundef %48, i32 noundef %49, ptr noundef %50, ptr noundef %51)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #9
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  %53 = getelementptr inbounds i64, ptr %52, i64 0
  %54 = load i64, ptr %53, align 8, !tbaa !11
  %55 = call i64 @Hacl_Bignum_ModInvLimb_mod_inv_uint64(i64 noundef %54)
  store i64 %55, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #9
  %56 = getelementptr inbounds %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u64_s, ptr %11, i32 0, i32 0
  %57 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %57, ptr %56, align 8, !tbaa !13
  %58 = getelementptr inbounds %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u64_s, ptr %11, i32 0, i32 1
  %59 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %59, ptr %58, align 8, !tbaa !15
  %60 = getelementptr inbounds %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u64_s, ptr %11, i32 0, i32 2
  %61 = load i64, ptr %10, align 8, !tbaa !11
  store i64 %61, ptr %60, align 8, !tbaa !16
  %62 = getelementptr inbounds %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u64_s, ptr %11, i32 0, i32 3
  %63 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %63, ptr %62, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #9
  %64 = call noalias ptr @malloc(i64 noundef 32) #11
  store ptr %64, ptr %12, align 8, !tbaa !9
  %65 = load ptr, ptr %12, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.Hacl_Bignum_MontArithmetic_bn_mont_ctx_u64_s, ptr %65, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %66, ptr align 8 %11, i64 32, i1 false), !tbaa.struct !18
  %67 = 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 8, 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 %67
}

; 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"Hacl_Bignum_MontArithmetic_bn_mont_ctx_u64_s", !6, i64 0, !10, i64 8, !12, i64 16, !10, i64 24}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !12, i64 16}
!17 = !{!14, !10, i64 24}
!18 = !{i64 0, i64 4, !5, i64 8, i64 8, !9, i64 16, i64 8, !11, 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 i64 @Hacl_Bignum_Lib_bn_get_top_index_u64(i32 noundef, ptr noundef) local_unnamed_addr #0

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

declare i64 @Hacl_Bignum_ModInvLimb_mod_inv_uint64(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @Hacl_Bignum64_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 8) #6
  %5 = tail call noalias ptr @calloc(i64 noundef %3, i64 noundef 8) #6
  %6 = shl nuw nsw i64 %3, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %1, i64 %6, i1 false)
  %7 = tail call i64 @Hacl_Bignum_Lib_bn_get_top_index_u64(i32 noundef %0, ptr noundef %1)
  %8 = trunc i64 %7 to i32
  %9 = shl i32 %8, 6
  tail call void @Hacl_Bignum_Montgomery_bn_precomp_r2_mod_n_u64(i32 noundef %0, i32 noundef %9, ptr noundef %1, ptr noundef %4) #7
  %10 = load i64, ptr %1, align 8, !tbaa !5
  %11 = tail call i64 @Hacl_Bignum_ModInvLimb_mod_inv_uint64(i64 noundef %10) #7
  %12 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #8
  store i32 %0, ptr %12, align 8, !tbaa !9
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 8
  store ptr %5, ptr %.sroa.42.0..sroa_idx, align 8, !tbaa !11
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 16
  store i64 %11, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !5
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 24
  store ptr %4, ptr %.sroa.6.0..sroa_idx, align 8, !tbaa !11
  ret ptr %12
}

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


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