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

; 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"

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_EC_Ed25519_felem_sqr(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [5 x i128], align 16
  %6 = alloca i32, align 4
  %7 = alloca i128, align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %22, %2
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %10 = icmp ult i32 %9, 5
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %25

12:                                               ; preds = %8
  %13 = call { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef 0)
  %14 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %15 = extractvalue { i64, i64 } %13, 0
  store i64 %15, ptr %14, align 16
  %16 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %17 = extractvalue { i64, i64 } %13, 1
  store i64 %17, ptr %16, align 8
  %18 = load i128, ptr %7, align 16, !tbaa !11
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [5 x i128], ptr %5, i64 0, i64 %20
  store i128 %18, ptr %21, align 16, !tbaa !11
  br label %22

22:                                               ; preds = %12
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = add i32 %23, 1
  store i32 %24, ptr %6, align 4, !tbaa !9
  br label %8, !llvm.loop !13

25:                                               ; preds = %11
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds [5 x i128], ptr %5, i64 0, i64 0
  call void @Hacl_Impl_Curve25519_Field51_fsqr(ptr noundef %26, ptr noundef %27, ptr noundef %28)
  call void @llvm.lifetime.end.p0(i64 80, ptr %5) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @Hacl_Impl_Curve25519_Field51_fsqr(ptr noundef, ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"any pointer", !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 = !{!"__int128", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_EC_Ed25519_felem_sqr(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca [5 x i128], align 16
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %3) #3
  %4 = tail call { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef 0)
  %5 = extractvalue { i64, i64 } %4, 0
  %6 = extractvalue { i64, i64 } %4, 1
  %.sroa.2.0.insert.ext = zext i64 %6 to i128
  %.sroa.2.0.insert.shift = shl nuw i128 %.sroa.2.0.insert.ext, 64
  %.sroa.0.0.insert.ext = zext i64 %5 to i128
  %.sroa.0.0.insert.insert = or disjoint i128 %.sroa.2.0.insert.shift, %.sroa.0.0.insert.ext
  store i128 %.sroa.0.0.insert.insert, ptr %3, align 16, !tbaa !5
  %7 = tail call { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef 0)
  %8 = extractvalue { i64, i64 } %7, 0
  %9 = extractvalue { i64, i64 } %7, 1
  %.sroa.2.0.insert.ext.1 = zext i64 %9 to i128
  %.sroa.2.0.insert.shift.1 = shl nuw i128 %.sroa.2.0.insert.ext.1, 64
  %.sroa.0.0.insert.ext.1 = zext i64 %8 to i128
  %.sroa.0.0.insert.insert.1 = or disjoint i128 %.sroa.2.0.insert.shift.1, %.sroa.0.0.insert.ext.1
  %10 = getelementptr inbounds i8, ptr %3, i64 16
  store i128 %.sroa.0.0.insert.insert.1, ptr %10, align 16, !tbaa !5
  %11 = tail call { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef 0)
  %12 = extractvalue { i64, i64 } %11, 0
  %13 = extractvalue { i64, i64 } %11, 1
  %.sroa.2.0.insert.ext.2 = zext i64 %13 to i128
  %.sroa.2.0.insert.shift.2 = shl nuw i128 %.sroa.2.0.insert.ext.2, 64
  %.sroa.0.0.insert.ext.2 = zext i64 %12 to i128
  %.sroa.0.0.insert.insert.2 = or disjoint i128 %.sroa.2.0.insert.shift.2, %.sroa.0.0.insert.ext.2
  %14 = getelementptr inbounds i8, ptr %3, i64 32
  store i128 %.sroa.0.0.insert.insert.2, ptr %14, align 16, !tbaa !5
  %15 = tail call { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef 0)
  %16 = extractvalue { i64, i64 } %15, 0
  %17 = extractvalue { i64, i64 } %15, 1
  %.sroa.2.0.insert.ext.3 = zext i64 %17 to i128
  %.sroa.2.0.insert.shift.3 = shl nuw i128 %.sroa.2.0.insert.ext.3, 64
  %.sroa.0.0.insert.ext.3 = zext i64 %16 to i128
  %.sroa.0.0.insert.insert.3 = or disjoint i128 %.sroa.2.0.insert.shift.3, %.sroa.0.0.insert.ext.3
  %18 = getelementptr inbounds i8, ptr %3, i64 48
  store i128 %.sroa.0.0.insert.insert.3, ptr %18, align 16, !tbaa !5
  %19 = tail call { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef 0)
  %20 = extractvalue { i64, i64 } %19, 0
  %21 = extractvalue { i64, i64 } %19, 1
  %.sroa.2.0.insert.ext.4 = zext i64 %21 to i128
  %.sroa.2.0.insert.shift.4 = shl nuw i128 %.sroa.2.0.insert.ext.4, 64
  %.sroa.0.0.insert.ext.4 = zext i64 %20 to i128
  %.sroa.0.0.insert.insert.4 = or disjoint i128 %.sroa.2.0.insert.shift.4, %.sroa.0.0.insert.ext.4
  %22 = getelementptr inbounds i8, ptr %3, i64 64
  store i128 %.sroa.0.0.insert.insert.4, ptr %22, align 16, !tbaa !5
  call void @Hacl_Impl_Curve25519_Field51_fsqr(ptr noundef %1, ptr noundef %0, ptr noundef nonnull %3)
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %3) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @Hacl_Impl_Curve25519_Field51_fsqr(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass