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

; 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 [82 x i8], align 1
@Hacl_Impl_FFDHE_Constants_ffdhe_g2 = external hidden constant [1 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ffdhe_len(i8 noundef zeroext) #0

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_FFDHE_ffdhe_secret_to_public_precomp(i8 noundef zeroext %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #4 {
  %5 = alloca i8, align 1
  %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 ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca ptr, align 8
  %14 = alloca i8, align 1
  %15 = alloca ptr, align 8
  store i8 %0, ptr %5, align 1, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !8
  store ptr %2, ptr %7, align 8, !tbaa !8
  store ptr %3, ptr %8, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %16 = load i8, ptr %5, align 1, !tbaa !5
  %17 = call i32 @ffdhe_len(i8 noundef zeroext %16)
  store i32 %17, ptr %9, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %18 = load i32, ptr %9, align 4, !tbaa !10
  %19 = sub i32 %18, 1
  %20 = udiv i32 %19, 8
  %21 = add i32 %20, 1
  store i32 %21, ptr %10, align 4, !tbaa !10
  br label %22

22:                                               ; preds = %4
  %23 = load i32, ptr %10, align 4, !tbaa !10
  %24 = zext i32 %23 to i64
  %25 = icmp ugt i64 %24, 2305843009213693951
  br i1 %25, label %26, label %28

26:                                               ; preds = %22
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 277)
  call void @exit(i32 noundef 253) #7
  unreachable

28:                                               ; preds = %22
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %31 = load i32, ptr %10, align 4, !tbaa !10
  %32 = zext i32 %31 to i64
  %33 = mul i64 %32, 8
  %34 = alloca i8, i64 %33, align 16
  store ptr %34, ptr %11, align 8, !tbaa !8
  %35 = load ptr, ptr %11, align 8, !tbaa !8
  %36 = load i32, ptr %10, align 4, !tbaa !10
  %37 = zext i32 %36 to i64
  %38 = mul i64 %37, 8
  call void @llvm.memset.p0.i64(ptr align 8 %35, i8 0, i64 %38, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #6
  store i8 0, ptr %12, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  store ptr %12, ptr %13, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #6
  %39 = load i8, ptr @Hacl_Impl_FFDHE_Constants_ffdhe_g2, align 1, !tbaa !5
  store i8 %39, ptr %14, align 1, !tbaa !5
  %40 = load i8, ptr %14, align 1, !tbaa !5
  %41 = load ptr, ptr %13, align 8, !tbaa !8
  %42 = getelementptr inbounds i8, ptr %41, i64 0
  store i8 %40, ptr %42, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  %43 = load ptr, ptr %11, align 8, !tbaa !8
  call void @Hacl_Bignum_Convert_bn_from_bytes_be_uint64(i32 noundef 1, ptr noundef %12, ptr noundef %43)
  br label %44

44:                                               ; preds = %30
  %45 = load i32, ptr %10, align 4, !tbaa !10
  %46 = zext i32 %45 to i64
  %47 = icmp ugt i64 %46, 2305843009213693951
  br i1 %47, label %48, label %50

48:                                               ; preds = %44
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 287)
  call void @exit(i32 noundef 253) #7
  unreachable

50:                                               ; preds = %44
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %53 = load i32, ptr %10, align 4, !tbaa !10
  %54 = zext i32 %53 to i64
  %55 = mul i64 %54, 8
  %56 = alloca i8, i64 %55, align 16
  store ptr %56, ptr %15, align 8, !tbaa !8
  %57 = load ptr, ptr %15, align 8, !tbaa !8
  %58 = load i32, ptr %10, align 4, !tbaa !10
  %59 = zext i32 %58 to i64
  %60 = mul i64 %59, 8
  call void @llvm.memset.p0.i64(ptr align 8 %57, i8 0, i64 %60, i1 false)
  %61 = load i32, ptr %9, align 4, !tbaa !10
  %62 = load ptr, ptr %7, align 8, !tbaa !8
  %63 = load ptr, ptr %15, align 8, !tbaa !8
  call void @Hacl_Bignum_Convert_bn_from_bytes_be_uint64(i32 noundef %61, ptr noundef %62, ptr noundef %63)
  %64 = load i8, ptr %5, align 1, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !8
  %66 = load ptr, ptr %15, align 8, !tbaa !8
  %67 = load ptr, ptr %11, align 8, !tbaa !8
  %68 = load ptr, ptr %8, align 8, !tbaa !8
  call void @ffdhe_compute_exp(i8 noundef zeroext %64, ptr noundef %65, ptr noundef %66, ptr noundef %67, ptr noundef %68)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @ffdhe_compute_exp(i8 noundef zeroext, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, 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"

@Hacl_Impl_FFDHE_Constants_ffdhe_g2 = external hidden local_unnamed_addr constant [1 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ffdhe_len(i8 noundef zeroext) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_FFDHE_ffdhe_secret_to_public_precomp(i8 noundef zeroext %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca i8, align 1
  %6 = tail call i32 @ffdhe_len(i8 noundef zeroext %0)
  %7 = add i32 %6, -1
  %8 = lshr i32 %7, 3
  %9 = add nuw nsw i32 %8, 1
  %10 = zext nneg i32 %9 to i64
  %11 = shl nuw nsw i64 %10, 3
  %12 = alloca i8, i64 %11, align 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %12, i8 0, i64 %11, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #4
  %13 = load i8, ptr @Hacl_Impl_FFDHE_Constants_ffdhe_g2, align 1, !tbaa !5
  store i8 %13, ptr %5, align 1, !tbaa !5
  call void @Hacl_Bignum_Convert_bn_from_bytes_be_uint64(i32 noundef 1, ptr noundef nonnull %5, ptr noundef nonnull %12)
  %14 = alloca i8, i64 %11, align 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %14, i8 0, i64 %11, i1 false)
  call void @Hacl_Bignum_Convert_bn_from_bytes_be_uint64(i32 noundef %6, ptr noundef %2, ptr noundef nonnull %14)
  call void @ffdhe_compute_exp(i8 noundef zeroext %0, ptr noundef %1, ptr noundef nonnull %14, ptr noundef nonnull %12, ptr noundef %3)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @ffdhe_compute_exp(i8 noundef zeroext, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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