; 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

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; 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

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

24:                                               ; preds = %5
  %25 = load i32, ptr %12, align 4, !tbaa !10
  %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 317)
  call void @exit(i32 noundef 253) #7
  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 %14) #6
  %33 = load i32, ptr %12, align 4, !tbaa !10
  %34 = zext i32 %33 to i64
  %35 = mul i64 %34, 8
  %36 = alloca i8, i64 %35, align 16
  store ptr %36, ptr %14, align 8, !tbaa !8
  %37 = load ptr, ptr %14, align 8, !tbaa !8
  %38 = load i32, ptr %12, align 4, !tbaa !10
  %39 = zext i32 %38 to i64
  %40 = mul i64 %39, 8
  call void @llvm.memset.p0.i64(ptr align 8 %37, i8 0, i64 %40, i1 false)
  br label %41

41:                                               ; preds = %32
  %42 = load i32, ptr %12, align 4, !tbaa !10
  %43 = zext i32 %42 to i64
  %44 = icmp ugt i64 %43, 2305843009213693951
  br i1 %44, label %45, label %47

45:                                               ; preds = %41
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 320)
  call void @exit(i32 noundef 253) #7
  unreachable

47:                                               ; preds = %41
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %50 = load i32, ptr %12, align 4, !tbaa !10
  %51 = zext i32 %50 to i64
  %52 = mul i64 %51, 8
  %53 = alloca i8, i64 %52, align 16
  store ptr %53, ptr %15, align 8, !tbaa !8
  %54 = load ptr, ptr %15, align 8, !tbaa !8
  %55 = load i32, ptr %12, align 4, !tbaa !10
  %56 = zext i32 %55 to i64
  %57 = mul i64 %56, 8
  call void @llvm.memset.p0.i64(ptr align 8 %54, i8 0, i64 %57, i1 false)
  %58 = load i32, ptr %11, align 4, !tbaa !10
  %59 = load ptr, ptr %8, align 8, !tbaa !8
  %60 = load ptr, ptr %14, align 8, !tbaa !8
  call void @Hacl_Bignum_Convert_bn_from_bytes_be_uint64(i32 noundef %58, ptr noundef %59, ptr noundef %60)
  %61 = load i32, ptr %11, align 4, !tbaa !10
  %62 = load ptr, ptr %9, 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)
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %64 = load i8, ptr %6, align 1, !tbaa !5
  %65 = load ptr, ptr %15, align 8, !tbaa !8
  %66 = load ptr, ptr %13, align 8, !tbaa !8
  %67 = call i64 @ffdhe_check_pk(i8 noundef zeroext %64, ptr noundef %65, ptr noundef %66)
  store i64 %67, ptr %16, align 8, !tbaa !12
  %68 = load i64, ptr %16, align 8, !tbaa !12
  %69 = icmp eq i64 %68, -1
  br i1 %69, label %70, label %76

70:                                               ; preds = %49
  %71 = load i8, ptr %6, align 1, !tbaa !5
  %72 = load ptr, ptr %7, align 8, !tbaa !8
  %73 = load ptr, ptr %14, align 8, !tbaa !8
  %74 = load ptr, ptr %15, align 8, !tbaa !8
  %75 = load ptr, ptr %10, align 8, !tbaa !8
  call void @ffdhe_compute_exp(i8 noundef zeroext %71, ptr noundef %72, ptr noundef %73, ptr noundef %74, ptr noundef %75)
  br label %76

76:                                               ; preds = %70, %49
  %77 = load i64, ptr %16, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  ret i64 %77
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @ffdhe_check_pk(i8 noundef zeroext, 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 #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}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !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"

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ffdhe_len(i8 noundef zeroext) 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: 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

; Function Attrs: nounwind uwtable
define dso_local i64 @Hacl_FFDHE_ffdhe_shared_secret_precomp(i8 noundef zeroext %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %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)
  %13 = alloca i8, i64 %11, align 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %13, 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 %12)
  call void @Hacl_Bignum_Convert_bn_from_bytes_be_uint64(i32 noundef %6, ptr noundef %3, ptr noundef nonnull %13)
  %14 = call i64 @ffdhe_check_pk(i8 noundef zeroext %0, ptr noundef nonnull %13, ptr noundef %1)
  %15 = icmp eq i64 %14, -1
  br i1 %15, label %16, label %17

16:                                               ; preds = %5
  call void @ffdhe_compute_exp(i8 noundef zeroext %0, ptr noundef %1, ptr noundef nonnull %12, ptr noundef nonnull %13, ptr noundef %4)
  br label %17

17:                                               ; preds = %16, %5
  ret i64 %14
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @ffdhe_check_pk(i8 noundef zeroext, 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 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" }

!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,TailCallElimPass