; LLVM IR from oreparaz/dudect :: examples/donna (curve25519-donna)

; 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: nounwind uwtable
define dso_local i32 @curve25519_donna(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [10 x i64], align 16
  %8 = alloca [10 x i64], align 16
  %9 = alloca [11 x i64], align 16
  %10 = alloca [10 x i64], align 16
  %11 = alloca [32 x i8], align 16
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 80, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 88, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 80, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %25, %3
  %14 = load i32, ptr %12, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 32
  br i1 %15, label %16, label %28

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i32, ptr %12, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %17, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %22 = load i32, ptr %12, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 %23
  store i8 %21, ptr %24, align 1, !tbaa !11
  br label %25

25:                                               ; preds = %16
  %26 = load i32, ptr %12, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %12, align 4, !tbaa !9
  br label %13, !llvm.loop !12

28:                                               ; preds = %13
  %29 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  %30 = load i8, ptr %29, align 16, !tbaa !11
  %31 = zext i8 %30 to i32
  %32 = and i32 %31, 248
  %33 = trunc i32 %32 to i8
  store i8 %33, ptr %29, align 16, !tbaa !11
  %34 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 31
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = zext i8 %35 to i32
  %37 = and i32 %36, 127
  %38 = trunc i32 %37 to i8
  store i8 %38, ptr %34, align 1, !tbaa !11
  %39 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 31
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = or i32 %41, 64
  %43 = trunc i32 %42 to i8
  store i8 %43, ptr %39, align 1, !tbaa !11
  %44 = getelementptr inbounds [10 x i64], ptr %7, i64 0, i64 0
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  call void @fexpand(ptr noundef %44, ptr noundef %45)
  %46 = getelementptr inbounds [10 x i64], ptr %8, i64 0, i64 0
  %47 = getelementptr inbounds [11 x i64], ptr %9, i64 0, i64 0
  %48 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  %49 = getelementptr inbounds [10 x i64], ptr %7, i64 0, i64 0
  call void @cmult(ptr noundef %46, ptr noundef %47, ptr noundef %48, ptr noundef %49)
  %50 = getelementptr inbounds [10 x i64], ptr %10, i64 0, i64 0
  %51 = getelementptr inbounds [11 x i64], ptr %9, i64 0, i64 0
  call void @crecip(ptr noundef %50, ptr noundef %51)
  %52 = getelementptr inbounds [11 x i64], ptr %9, i64 0, i64 0
  %53 = getelementptr inbounds [10 x i64], ptr %8, i64 0, i64 0
  %54 = getelementptr inbounds [10 x i64], ptr %10, i64 0, i64 0
  call void @fmul(ptr noundef %52, ptr noundef %53, ptr noundef %54)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds [11 x i64], ptr %9, i64 0, i64 0
  call void @fcontract(ptr noundef %55, ptr noundef %56)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 80, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 88, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 80, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 80, ptr %7) #2
  ret i32 0
}

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

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

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

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

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: nounwind uwtable
define dso_local noundef i32 @curve25519_donna(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [10 x i64], align 16
  %5 = alloca [10 x i64], align 16
  %6 = alloca [11 x i64], align 16
  %7 = alloca [10 x i64], align 16
  %8 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %8) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %8, ptr noundef nonnull align 1 dereferenceable(32) %1, i64 32, i1 false), !tbaa !5
  %9 = load i8, ptr %8, align 16, !tbaa !5
  %10 = and i8 %9, -8
  store i8 %10, ptr %8, align 16, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %8, i64 31
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = and i8 %12, 63
  %14 = or disjoint i8 %13, 64
  store i8 %14, ptr %11, align 1, !tbaa !5
  call void @fexpand(ptr noundef nonnull %4, ptr noundef %2)
  call void @cmult(ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef nonnull %8, ptr noundef nonnull %4)
  call void @crecip(ptr noundef nonnull %7, ptr noundef nonnull %6)
  call void @fmul(ptr noundef nonnull %6, ptr noundef nonnull %5, ptr noundef nonnull %7)
  call void @fcontract(ptr noundef %0, ptr noundef nonnull %6)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %4) #3
  ret i32 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: nounwind uwtable
declare hidden void @fexpand(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

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

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

; Function Attrs: mustprogress 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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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


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