; LLVM IR from cryspen/libcrux :: sys/hacl/c/src (Hacl_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"

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

; Function Attrs: nounwind uwtable
declare dso_local void @Hacl_Bignum_Karatsuba_bn_karatsuba_mul_uint32(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; 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: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nounwind uwtable
declare hidden void @bn_mont_reduction_u32(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_Bignum_Montgomery_bn_mont_mul_u32(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %6
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = add i32 %17, %18
  %20 = zext i32 %19 to i64
  %21 = icmp ugt i64 %20, 4611686018427387903
  br i1 %21, label %22, label %24

22:                                               ; preds = %16
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 983)
  call void @exit(i32 noundef 253) #5
  unreachable

24:                                               ; preds = %16
  br label %25

25:                                               ; preds = %24
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = add i32 %26, %27
  %29 = zext i32 %28 to i64
  %30 = call ptr @llvm.stacksave.p0()
  store ptr %30, ptr %13, align 8
  %31 = alloca i32, i64 %29, align 16
  store i64 %29, ptr %14, align 8
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = add i32 %32, %33
  %35 = zext i32 %34 to i64
  %36 = mul i64 %35, 4
  call void @llvm.memset.p0.i64(ptr align 16 %31, i8 0, i64 %36, i1 false)
  br label %37

37:                                               ; preds = %25
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = mul i32 4, %38
  %40 = zext i32 %39 to i64
  %41 = icmp ugt i64 %40, 4611686018427387903
  br i1 %41, label %42, label %44

42:                                               ; preds = %37
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 986)
  call void @exit(i32 noundef 253) #5
  unreachable

44:                                               ; preds = %37
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = mul i32 4, %47
  %49 = zext i32 %48 to i64
  %50 = alloca i32, i64 %49, align 16
  store i64 %49, ptr %15, align 8
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = mul i32 4, %51
  %53 = zext i32 %52 to i64
  %54 = mul i64 %53, 4
  call void @llvm.memset.p0.i64(ptr align 16 %50, i8 0, i64 %54, i1 false)
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = load ptr, ptr %10, align 8, !tbaa !9
  %57 = load ptr, ptr %11, align 8, !tbaa !9
  call void @Hacl_Bignum_Karatsuba_bn_karatsuba_mul_uint32(i32 noundef %55, ptr noundef %56, ptr noundef %57, ptr noundef %50, ptr noundef %31)
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = load ptr, ptr %8, align 8, !tbaa !9
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = load ptr, ptr %12, align 8, !tbaa !9
  call void @bn_mont_reduction_u32(i32 noundef %58, ptr noundef %59, i32 noundef %60, ptr noundef %31, ptr noundef %61)
  %62 = load ptr, ptr %13, align 8
  call void @llvm.stackrestore.p0(ptr %62)
  ret void
}

attributes #0 = { 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 = { 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 #3 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { noreturn 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

; Function Attrs: nounwind uwtable
declare dso_local void @Hacl_Bignum_Karatsuba_bn_karatsuba_mul_uint32(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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
declare hidden void @bn_mont_reduction_u32(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_Bignum_Montgomery_bn_mont_mul_u32(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = shl i32 %0, 1
  %8 = zext i32 %7 to i64
  %9 = alloca i32, i64 %8, align 16
  %10 = shl nuw nsw i64 %8, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %9, i8 0, i64 %10, i1 false)
  %11 = shl i32 %0, 2
  %12 = zext i32 %11 to i64
  %13 = alloca i32, i64 %12, align 16
  %14 = shl nuw nsw i64 %12, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %13, i8 0, i64 %14, i1 false)
  call void @Hacl_Bignum_Karatsuba_bn_karatsuba_mul_uint32(i32 noundef %0, ptr noundef %3, ptr noundef %4, ptr noundef nonnull %13, ptr noundef nonnull %9)
  call void @bn_mont_reduction_u32(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef nonnull %9, ptr noundef %5)
  ret void
}

attributes #0 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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)"}


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