; LLVM IR from philanc/luazen :: src/mono (monocypher-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"

%struct.crypto_hmac_sha512_ctx = type { [128 x i8], %struct.crypto_sha512_ctx }
%struct.crypto_sha512_ctx = type { [8 x i64], [16 x i64], [2 x i64], i64 }

; Function Attrs: nounwind uwtable
declare dso_local void @crypto_sha512_init(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @crypto_sha512_update(ptr noundef, ptr noundef, i64 noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @crypto_sha512(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @crypto_hmac_sha512_init(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %9 = load i64, ptr %6, align 8, !tbaa !9
  %10 = icmp ugt i64 %9, 128
  br i1 %10, label %11, label %20

11:                                               ; preds = %3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %12, i32 0, i32 0
  %14 = getelementptr inbounds [128 x i8], ptr %13, i64 0, i64 0
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i64, ptr %6, align 8, !tbaa !9
  call void @crypto_sha512(ptr noundef %14, ptr noundef %15, i64 noundef %16)
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds [128 x i8], ptr %18, i64 0, i64 0
  store ptr %19, ptr %5, align 8, !tbaa !5
  store i64 64, ptr %6, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %11, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %38, %20
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %41

26:                                               ; preds = %21
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %27, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = zext i8 %30 to i32
  %32 = xor i32 %31, 54
  %33 = trunc i32 %32 to i8
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %34, i32 0, i32 0
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = getelementptr inbounds [128 x i8], ptr %35, i64 0, i64 %36
  store i8 %33, ptr %37, align 1, !tbaa !11
  br label %38

38:                                               ; preds = %26
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = add i64 %39, 1
  store i64 %40, ptr %7, align 8, !tbaa !9
  br label %21, !llvm.loop !12

41:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %42 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %42, ptr %8, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %52, %41
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = icmp ult i64 %44, 128
  br i1 %45, label %47, label %46

46:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %55

47:                                               ; preds = %43
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %48, i32 0, i32 0
  %50 = load i64, ptr %8, align 8, !tbaa !9
  %51 = getelementptr inbounds [128 x i8], ptr %49, i64 0, i64 %50
  store i8 54, ptr %51, align 1, !tbaa !11
  br label %52

52:                                               ; preds = %47
  %53 = load i64, ptr %8, align 8, !tbaa !9
  %54 = add i64 %53, 1
  store i64 %54, ptr %8, align 8, !tbaa !9
  br label %43, !llvm.loop !14

55:                                               ; preds = %46
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %56, i32 0, i32 1
  call void @crypto_sha512_init(ptr noundef %57)
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds [128 x i8], ptr %61, i64 0, i64 0
  call void @crypto_sha512_update(ptr noundef %59, ptr noundef %62, i64 noundef 128)
  ret void
}

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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !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
declare dso_local void @crypto_sha512_init(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @crypto_sha512_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @crypto_sha512(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @crypto_hmac_sha512_init(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = ptrtoint ptr %0 to i64
  %5 = icmp ugt i64 %2, 128
  br i1 %5, label %.thread, label %6

.thread:                                          ; preds = %3
  tail call void @crypto_sha512(ptr noundef %0, ptr noundef %1, i64 noundef %2)
  br label %iter.check

6:                                                ; preds = %3
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %.lr.ph25.preheader, label %iter.check

iter.check:                                       ; preds = %.thread, %6
  %.02030 = phi i64 [ 64, %.thread ], [ %2, %6 ]
  %.02129 = phi ptr [ %0, %.thread ], [ %1, %6 ]
  %min.iters.check = icmp ult i64 %.02030, 8
  %.0212934 = ptrtoint ptr %.02129 to i64
  %7 = sub i64 %4, %.0212934
  %diff.check = icmp ult i64 %7, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check35 = icmp ult i64 %.02030, 32
  br i1 %min.iters.check35, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %.02030, 224
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %8 = getelementptr inbounds i8, ptr %.02129, i64 %index
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %wide.load = load <16 x i8>, ptr %8, align 1, !tbaa !5
  %wide.load36 = load <16 x i8>, ptr %9, align 1, !tbaa !5
  %10 = xor <16 x i8> %wide.load, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
  %11 = xor <16 x i8> %wide.load36, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
  %12 = getelementptr inbounds [128 x i8], ptr %0, i64 0, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  store <16 x i8> %10, ptr %12, align 1, !tbaa !5
  store <16 x i8> %11, ptr %13, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %14 = icmp eq i64 %index.next, %n.vec
  br i1 %14, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %.02030, %n.vec
  br i1 %cmp.n, label %.preheader, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %n.vec.remaining = and i64 %.02030, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %.01923.ph = phi i64 [ 0, %iter.check ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec38, %vec.epilog.middle.block ]
  %xtraiter = and i64 %.02030, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.01923.prol = phi i64 [ %19, %.lr.ph.prol ], [ %.01923.ph, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %15 = getelementptr inbounds i8, ptr %.02129, i64 %.01923.prol
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = xor i8 %16, 54
  %18 = getelementptr inbounds [128 x i8], ptr %0, i64 0, i64 %.01923.prol
  store i8 %17, ptr %18, align 1, !tbaa !5
  %19 = add nuw nsw i64 %.01923.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !12

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.01923.unr = phi i64 [ %.01923.ph, %.lr.ph.preheader ], [ %19, %.lr.ph.prol ]
  %20 = sub nsw i64 %.01923.ph, %.02030
  %21 = icmp ugt i64 %20, -4
  br i1 %21, label %.preheader, label %.lr.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec38 = and i64 %.02030, 248
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index39 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next41, %vec.epilog.vector.body ]
  %22 = getelementptr inbounds i8, ptr %.02129, i64 %index39
  %wide.load40 = load <8 x i8>, ptr %22, align 1, !tbaa !5
  %23 = xor <8 x i8> %wide.load40, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
  %24 = getelementptr inbounds [128 x i8], ptr %0, i64 0, i64 %index39
  store <8 x i8> %23, ptr %24, align 1, !tbaa !5
  %index.next41 = add nuw i64 %index39, 8
  %25 = icmp eq i64 %index.next41, %n.vec38
  br i1 %25, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !14

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n42 = icmp eq i64 %.02030, %n.vec38
  br i1 %cmp.n42, label %.preheader, label %.lr.ph.preheader

.preheader:                                       ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %vec.epilog.middle.block, %middle.block
  %26 = icmp ult i64 %.02030, 128
  br i1 %26, label %.lr.ph25.preheader, label %._crit_edge

.lr.ph25.preheader:                               ; preds = %6, %.preheader
  %.0203133 = phi i64 [ %.02030, %.preheader ], [ 0, %6 ]
  %scevgep = getelementptr i8, ptr %0, i64 %.0203133
  %27 = sub nuw nsw i64 128, %.0203133
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %scevgep, i8 54, i64 %27, i1 false), !tbaa !5
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.01923 = phi i64 [ %47, %.lr.ph ], [ %.01923.unr, %.lr.ph.prol.loopexit ]
  %28 = getelementptr inbounds i8, ptr %.02129, i64 %.01923
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = xor i8 %29, 54
  %31 = getelementptr inbounds [128 x i8], ptr %0, i64 0, i64 %.01923
  store i8 %30, ptr %31, align 1, !tbaa !5
  %32 = add nuw nsw i64 %.01923, 1
  %33 = getelementptr inbounds i8, ptr %.02129, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %35 = xor i8 %34, 54
  %36 = getelementptr inbounds [128 x i8], ptr %0, i64 0, i64 %32
  store i8 %35, ptr %36, align 1, !tbaa !5
  %37 = add nuw nsw i64 %.01923, 2
  %38 = getelementptr inbounds i8, ptr %.02129, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !5
  %40 = xor i8 %39, 54
  %41 = getelementptr inbounds [128 x i8], ptr %0, i64 0, i64 %37
  store i8 %40, ptr %41, align 1, !tbaa !5
  %42 = add nuw nsw i64 %.01923, 3
  %43 = getelementptr inbounds i8, ptr %.02129, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !5
  %45 = xor i8 %44, 54
  %46 = getelementptr inbounds [128 x i8], ptr %0, i64 0, i64 %42
  store i8 %45, ptr %46, align 1, !tbaa !5
  %47 = add nuw nsw i64 %.01923, 4
  %exitcond.not.3 = icmp eq i64 %47, %.02030
  br i1 %exitcond.not.3, label %.preheader, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph25.preheader, %.preheader
  %48 = getelementptr inbounds i8, ptr %0, i64 128
  tail call void @crypto_sha512_init(ptr noundef nonnull %48)
  tail call void @crypto_sha512_update(ptr noundef nonnull %48, ptr noundef %0, i64 noundef 128)
  ret void
}

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

!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, !10, !11}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = distinct !{!14, !9, !10, !11}
!15 = distinct !{!15, !9, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass