; LLVM IR from holzschu/ios_system :: ssh_keygen (smult_curve25519_ref)

; 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 @crypto_scalarmult_curve25519(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 [96 x i32], align 16
  %8 = alloca [32 x i8], align 16
  %9 = 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 384, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %22, %3
  %11 = load i32, ptr %9, align 4, !tbaa !9
  %12 = icmp ult i32 %11, 32
  br i1 %12, label %13, label %25

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

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

25:                                               ; preds = %10
  %26 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %27 = load i8, ptr %26, align 16, !tbaa !11
  %28 = zext i8 %27 to i32
  %29 = and i32 %28, 248
  %30 = trunc i32 %29 to i8
  store i8 %30, ptr %26, align 16, !tbaa !11
  %31 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 31
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = and i32 %33, 127
  %35 = trunc i32 %34 to i8
  store i8 %35, ptr %31, align 1, !tbaa !11
  %36 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 31
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = zext i8 %37 to i32
  %39 = or i32 %38, 64
  %40 = trunc i32 %39 to i8
  store i8 %40, ptr %36, align 1, !tbaa !11
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %54, %25
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = icmp ult i32 %42, 32
  br i1 %43, label %44, label %57

44:                                               ; preds = %41
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = zext i8 %49 to i32
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds [96 x i32], ptr %7, i64 0, i64 %52
  store i32 %50, ptr %53, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %44
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = add i32 %55, 1
  store i32 %56, ptr %9, align 4, !tbaa !9
  br label %41, !llvm.loop !14

57:                                               ; preds = %41
  %58 = getelementptr inbounds [96 x i32], ptr %7, i64 0, i64 0
  %59 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  call void @mainloop(ptr noundef %58, ptr noundef %59)
  %60 = getelementptr inbounds [96 x i32], ptr %7, i64 0, i64 0
  %61 = getelementptr inbounds i32, ptr %60, i64 32
  %62 = getelementptr inbounds [96 x i32], ptr %7, i64 0, i64 0
  %63 = getelementptr inbounds i32, ptr %62, i64 32
  call void @recip(ptr noundef %61, ptr noundef %63)
  %64 = getelementptr inbounds [96 x i32], ptr %7, i64 0, i64 0
  %65 = getelementptr inbounds i32, ptr %64, i64 64
  %66 = getelementptr inbounds [96 x i32], ptr %7, i64 0, i64 0
  %67 = getelementptr inbounds [96 x i32], ptr %7, i64 0, i64 0
  %68 = getelementptr inbounds i32, ptr %67, i64 32
  call void @mult(ptr noundef %65, ptr noundef %66, ptr noundef %68)
  %69 = getelementptr inbounds [96 x i32], ptr %7, i64 0, i64 0
  %70 = getelementptr inbounds i32, ptr %69, i64 64
  call void @freeze(ptr noundef %70)
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %71

71:                                               ; preds = %85, %57
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = icmp ult i32 %72, 32
  br i1 %73, label %74, label %88

74:                                               ; preds = %71
  %75 = load i32, ptr %9, align 4, !tbaa !9
  %76 = add i32 64, %75
  %77 = zext i32 %76 to i64
  %78 = getelementptr inbounds [96 x i32], ptr %7, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !9
  %80 = trunc i32 %79 to i8
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load i32, ptr %9, align 4, !tbaa !9
  %83 = zext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %81, i64 %83
  store i8 %80, ptr %84, align 1, !tbaa !11
  br label %85

85:                                               ; preds = %74
  %86 = load i32, ptr %9, align 4, !tbaa !9
  %87 = add i32 %86, 1
  store i32 %87, ptr %9, align 4, !tbaa !9
  br label %71, !llvm.loop !15

88:                                               ; preds = %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 384, 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 @mainloop(ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare hidden void @freeze(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"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; 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 @crypto_scalarmult_curve25519(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = alloca [96 x i32], align 16
  %5 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 384, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %5, ptr noundef nonnull align 1 dereferenceable(32) %1, i64 32, i1 false), !tbaa !5
  %6 = load i8, ptr %5, align 16, !tbaa !5
  %7 = and i8 %6, -8
  store i8 %7, ptr %5, align 16, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %5, i64 31
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = and i8 %9, 63
  %11 = or disjoint i8 %10, 64
  store i8 %11, ptr %8, align 1, !tbaa !5
  %12 = load <4 x i8>, ptr %2, align 1, !tbaa !5
  %13 = zext <4 x i8> %12 to <4 x i32>
  store <4 x i32> %13, ptr %4, align 16, !tbaa !8
  %14 = getelementptr inbounds i8, ptr %2, i64 4
  %15 = getelementptr inbounds i8, ptr %4, i64 16
  %16 = load <4 x i8>, ptr %14, align 1, !tbaa !5
  %17 = zext <4 x i8> %16 to <4 x i32>
  store <4 x i32> %17, ptr %15, align 16, !tbaa !8
  %18 = getelementptr inbounds i8, ptr %2, i64 8
  %19 = getelementptr inbounds i8, ptr %4, i64 32
  %20 = load <4 x i8>, ptr %18, align 1, !tbaa !5
  %21 = zext <4 x i8> %20 to <4 x i32>
  store <4 x i32> %21, ptr %19, align 16, !tbaa !8
  %22 = getelementptr inbounds i8, ptr %2, i64 12
  %23 = getelementptr inbounds i8, ptr %4, i64 48
  %24 = load <4 x i8>, ptr %22, align 1, !tbaa !5
  %25 = zext <4 x i8> %24 to <4 x i32>
  store <4 x i32> %25, ptr %23, align 16, !tbaa !8
  %26 = getelementptr inbounds i8, ptr %2, i64 16
  %27 = getelementptr inbounds i8, ptr %4, i64 64
  %28 = load <4 x i8>, ptr %26, align 1, !tbaa !5
  %29 = zext <4 x i8> %28 to <4 x i32>
  store <4 x i32> %29, ptr %27, align 16, !tbaa !8
  %30 = getelementptr inbounds i8, ptr %2, i64 20
  %31 = getelementptr inbounds i8, ptr %4, i64 80
  %32 = load <4 x i8>, ptr %30, align 1, !tbaa !5
  %33 = zext <4 x i8> %32 to <4 x i32>
  store <4 x i32> %33, ptr %31, align 16, !tbaa !8
  %34 = getelementptr inbounds i8, ptr %2, i64 24
  %35 = getelementptr inbounds i8, ptr %4, i64 96
  %36 = load <4 x i8>, ptr %34, align 1, !tbaa !5
  %37 = zext <4 x i8> %36 to <4 x i32>
  store <4 x i32> %37, ptr %35, align 16, !tbaa !8
  %38 = getelementptr inbounds i8, ptr %2, i64 28
  %39 = getelementptr inbounds i8, ptr %4, i64 112
  %40 = load <4 x i8>, ptr %38, align 1, !tbaa !5
  %41 = zext <4 x i8> %40 to <4 x i32>
  store <4 x i32> %41, ptr %39, align 16, !tbaa !8
  call void @mainloop(ptr noundef nonnull %4, ptr noundef nonnull %5)
  %42 = getelementptr inbounds i8, ptr %4, i64 128
  call void @recip(ptr noundef nonnull %42, ptr noundef nonnull %42)
  %43 = getelementptr inbounds i8, ptr %4, i64 256
  call void @mult(ptr noundef nonnull %43, ptr noundef nonnull %4, ptr noundef nonnull %42)
  call void @freeze(ptr noundef nonnull %43)
  %44 = load <16 x i32>, ptr %43, align 16, !tbaa !8
  %45 = trunc <16 x i32> %44 to <16 x i8>
  store <16 x i8> %45, ptr %0, align 1, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %4, i64 320
  %47 = getelementptr inbounds i8, ptr %0, i64 16
  %48 = load <16 x i32>, ptr %46, align 16, !tbaa !8
  %49 = trunc <16 x i32> %48 to <16 x i8>
  store <16 x i8> %49, ptr %47, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 384, 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 @mainloop(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare hidden void @freeze(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"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


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