; LLVM IR from sca-secure-library-sca25519/sca25519 :: cw/sca25519_cw_st/crypto/scalarmult (scalarmult_25519)

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

@Rx = external hidden global { [32 x i8] }, align 8
@Ry = external hidden global { [32 x i8] }, align 8
@Rz = external hidden global { <{ i8, [31 x i8] }> }, align 8
@Sx = external hidden global { [32 x i8] }, align 8
@Sy = external hidden global { [32 x i8] }, align 8
@Sz = external hidden global { <{ i8, [31 x i8] }> }, align 8
@static_key = external hidden global { [32 x i8] }, align 8
@blindingFactor = external hidden global { <{ [8 x i8], [24 x i8] }> }, align 8

; Function Attrs: nounwind uwtable
define dso_local void @set_static_key_curve25519(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) #0 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i8, align 1
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  store ptr %7, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %17) #2
  store i8 0, ptr %17, align 1, !tbaa !9
  br label %18

18:                                               ; preds = %87, %8
  %19 = load i8, ptr %17, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = icmp slt i32 %20, 32
  br i1 %21, label %22, label %90

22:                                               ; preds = %18
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load i8, ptr %17, align 1, !tbaa !9
  %25 = zext i8 %24 to i64
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = load i8, ptr %17, align 1, !tbaa !9
  %29 = zext i8 %28 to i64
  %30 = getelementptr inbounds [32 x i8], ptr @Rx, i64 0, i64 %29
  store i8 %27, ptr %30, align 1, !tbaa !9
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = load i8, ptr %17, align 1, !tbaa !9
  %33 = zext i8 %32 to i64
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = load i8, ptr %17, align 1, !tbaa !9
  %37 = zext i8 %36 to i64
  %38 = getelementptr inbounds [32 x i8], ptr @Ry, i64 0, i64 %37
  store i8 %35, ptr %38, align 1, !tbaa !9
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = load i8, ptr %17, align 1, !tbaa !9
  %41 = zext i8 %40 to i64
  %42 = getelementptr inbounds i8, ptr %39, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = load i8, ptr %17, align 1, !tbaa !9
  %45 = zext i8 %44 to i64
  %46 = getelementptr inbounds [32 x i8], ptr @Rz, i64 0, i64 %45
  store i8 %43, ptr %46, align 1, !tbaa !9
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = load i8, ptr %17, align 1, !tbaa !9
  %49 = zext i8 %48 to i64
  %50 = getelementptr inbounds i8, ptr %47, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !9
  %52 = load i8, ptr %17, align 1, !tbaa !9
  %53 = zext i8 %52 to i64
  %54 = getelementptr inbounds [32 x i8], ptr @Sx, i64 0, i64 %53
  store i8 %51, ptr %54, align 1, !tbaa !9
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = load i8, ptr %17, align 1, !tbaa !9
  %57 = zext i8 %56 to i64
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !9
  %60 = load i8, ptr %17, align 1, !tbaa !9
  %61 = zext i8 %60 to i64
  %62 = getelementptr inbounds [32 x i8], ptr @Sy, i64 0, i64 %61
  store i8 %59, ptr %62, align 1, !tbaa !9
  %63 = load ptr, ptr %14, align 8, !tbaa !5
  %64 = load i8, ptr %17, align 1, !tbaa !9
  %65 = zext i8 %64 to i64
  %66 = getelementptr inbounds i8, ptr %63, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !9
  %68 = load i8, ptr %17, align 1, !tbaa !9
  %69 = zext i8 %68 to i64
  %70 = getelementptr inbounds [32 x i8], ptr @Sz, i64 0, i64 %69
  store i8 %67, ptr %70, align 1, !tbaa !9
  %71 = load ptr, ptr %15, align 8, !tbaa !5
  %72 = load i8, ptr %17, align 1, !tbaa !9
  %73 = zext i8 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !9
  %76 = load i8, ptr %17, align 1, !tbaa !9
  %77 = zext i8 %76 to i64
  %78 = getelementptr inbounds [32 x i8], ptr @static_key, i64 0, i64 %77
  store i8 %75, ptr %78, align 1, !tbaa !9
  %79 = load ptr, ptr %16, align 8, !tbaa !5
  %80 = load i8, ptr %17, align 1, !tbaa !9
  %81 = zext i8 %80 to i64
  %82 = getelementptr inbounds i8, ptr %79, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !9
  %84 = load i8, ptr %17, align 1, !tbaa !9
  %85 = zext i8 %84 to i64
  %86 = getelementptr inbounds [32 x i8], ptr @blindingFactor, i64 0, i64 %85
  store i8 %83, ptr %86, align 1, !tbaa !9
  br label %87

87:                                               ; preds = %22
  %88 = load i8, ptr %17, align 1, !tbaa !9
  %89 = add i8 %88, 1
  store i8 %89, ptr %17, align 1, !tbaa !9
  br label %18, !llvm.loop !10

90:                                               ; preds = %18
  call void @update_static_key_curve25519()
  call void @llvm.lifetime.end.p0(i64 1, ptr %17) #2
  ret void
}

; 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 dso_local void @update_static_key_curve25519() #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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@Rx = external hidden local_unnamed_addr global { [32 x i8] }, align 8
@Ry = external hidden local_unnamed_addr global { [32 x i8] }, align 8
@Rz = external hidden local_unnamed_addr global { <{ i8, [31 x i8] }> }, align 8
@Sx = external hidden local_unnamed_addr global { [32 x i8] }, align 8
@Sy = external hidden local_unnamed_addr global { [32 x i8] }, align 8
@Sz = external hidden local_unnamed_addr global { <{ i8, [31 x i8] }> }, align 8
@static_key = external hidden local_unnamed_addr global { [32 x i8] }, align 8
@blindingFactor = external hidden local_unnamed_addr global { <{ [8 x i8], [24 x i8] }> }, align 8

; Function Attrs: nounwind uwtable
define dso_local void @set_static_key_curve25519(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef readonly %5, ptr nocapture noundef readonly %6, ptr nocapture noundef readonly %7) local_unnamed_addr #0 {
  br label %9

9:                                                ; preds = %8, %9
  %indvars.iv = phi i64 [ 0, %8 ], [ %indvars.iv.next, %9 ]
  %10 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = getelementptr inbounds [32 x i8], ptr @Rx, i64 0, i64 %indvars.iv
  store i8 %11, ptr %12, align 1, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = getelementptr inbounds [32 x i8], ptr @Ry, i64 0, i64 %indvars.iv
  store i8 %14, ptr %15, align 1, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = getelementptr inbounds [32 x i8], ptr @Rz, i64 0, i64 %indvars.iv
  store i8 %17, ptr %18, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %3, i64 %indvars.iv
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = getelementptr inbounds [32 x i8], ptr @Sx, i64 0, i64 %indvars.iv
  store i8 %20, ptr %21, align 1, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = getelementptr inbounds [32 x i8], ptr @Sy, i64 0, i64 %indvars.iv
  store i8 %23, ptr %24, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %5, i64 %indvars.iv
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = getelementptr inbounds [32 x i8], ptr @Sz, i64 0, i64 %indvars.iv
  store i8 %26, ptr %27, align 1, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %6, i64 %indvars.iv
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = getelementptr inbounds [32 x i8], ptr @static_key, i64 0, i64 %indvars.iv
  store i8 %29, ptr %30, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %7, i64 %indvars.iv
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = getelementptr inbounds [32 x i8], ptr @blindingFactor, i64 0, i64 %indvars.iv
  store i8 %32, ptr %33, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 32
  br i1 %exitcond.not, label %34, label %9, !llvm.loop !8

34:                                               ; preds = %9
  tail call void @update_static_key_curve25519()
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @update_static_key_curve25519() local_unnamed_addr #0

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

!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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass