; 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_sha512_ctx = type { [8 x i64], [16 x i64], [2 x i64], i64 }

; Function Attrs: nounwind uwtable
define dso_local void @crypto_sha512_update(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
  %9 = alloca i32, align 4
  %10 = 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
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  br label %80

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %15, i32 0, i32 3
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = call i64 @align(i64 noundef %17, i64 noundef 128)
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = icmp ule i64 %18, %19
  br i1 %20, label %21, label %26

21:                                               ; preds = %14
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %22, i32 0, i32 3
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = call i64 @align(i64 noundef %24, i64 noundef 128)
  br label %28

26:                                               ; preds = %14
  %27 = load i64, ptr %6, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %26, %21
  %29 = phi i64 [ %25, %21 ], [ %27, %26 ]
  store i64 %29, ptr %7, align 8, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %7, align 8, !tbaa !9
  call void @sha512_update(ptr noundef %30, ptr noundef %31, i64 noundef %32)
  %33 = load i64, ptr %7, align 8, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 %33
  store ptr %35, ptr %5, align 8, !tbaa !5
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = load i64, ptr %6, align 8, !tbaa !9
  %38 = sub i64 %37, %36
  store i64 %38, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %71, %28
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = udiv i64 %41, 128
  %43 = icmp ult i64 %40, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %39
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %74

45:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %60, %45
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = icmp ult i64 %47, 16
  br i1 %48, label %50, label %49

49:                                               ; preds = %46
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %63

50:                                               ; preds = %46
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i64, ptr %10, align 8, !tbaa !9
  %53 = mul i64 %52, 8
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  %55 = call i64 @load64_be(ptr noundef %54)
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %56, i32 0, i32 1
  %58 = load i64, ptr %10, align 8, !tbaa !9
  %59 = getelementptr inbounds [16 x i64], ptr %57, i64 0, i64 %58
  store i64 %55, ptr %59, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %50
  %61 = load i64, ptr %10, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr %10, align 8, !tbaa !9
  br label %46, !llvm.loop !13

63:                                               ; preds = %49
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 128
  store ptr %65, ptr %5, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %66, i32 0, i32 3
  %68 = load i64, ptr %67, align 8, !tbaa !11
  %69 = add i64 %68, 128
  store i64 %69, ptr %67, align 8, !tbaa !11
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sha512_end_block(ptr noundef %70)
  br label %71

71:                                               ; preds = %63
  %72 = load i64, ptr %8, align 8, !tbaa !9
  %73 = add i64 %72, 1
  store i64 %73, ptr %8, align 8, !tbaa !9
  br label %39, !llvm.loop !15

74:                                               ; preds = %44
  %75 = load i64, ptr %6, align 8, !tbaa !9
  %76 = and i64 %75, 127
  store i64 %76, ptr %6, align 8, !tbaa !9
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load i64, ptr %6, align 8, !tbaa !9
  call void @sha512_update(ptr noundef %77, ptr noundef %78, i64 noundef %79)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %80

80:                                               ; preds = %74, %13
  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 hidden i64 @align(i64 noundef, i64 noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden i64 @load64_be(ptr noundef) #0

; 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 hidden void @sha512_end_block(ptr noundef) #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" }
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 = !{!12, !10, i64 208}
!12 = !{!"", !7, i64 0, !7, i64 64, !7, i64 192, !10, i64 208}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 void @crypto_sha512_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %2, 0
  br i1 %4, label %69, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 208
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = tail call i64 @align(i64 noundef %7, i64 noundef 128)
  %.not = icmp ugt i64 %8, %2
  br i1 %.not, label %12, label %9

9:                                                ; preds = %5
  %10 = load i64, ptr %6, align 8, !tbaa !5
  %11 = tail call i64 @align(i64 noundef %10, i64 noundef 128)
  br label %12

12:                                               ; preds = %5, %9
  %13 = phi i64 [ %11, %9 ], [ %2, %5 ]
  tail call void @sha512_update(ptr noundef nonnull %0, ptr noundef %1, i64 noundef %13)
  %14 = getelementptr inbounds i8, ptr %1, i64 %13
  %15 = sub i64 %2, %13
  %.not33 = icmp ult i64 %15, 128
  br i1 %.not33, label %._crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %12
  %16 = lshr i64 %15, 7
  %17 = getelementptr inbounds i8, ptr %0, i64 64
  %18 = getelementptr inbounds i8, ptr %0, i64 72
  %19 = getelementptr inbounds i8, ptr %0, i64 80
  %20 = getelementptr inbounds i8, ptr %0, i64 88
  %21 = getelementptr inbounds i8, ptr %0, i64 96
  %22 = getelementptr inbounds i8, ptr %0, i64 104
  %23 = getelementptr inbounds i8, ptr %0, i64 112
  %24 = getelementptr inbounds i8, ptr %0, i64 120
  %25 = getelementptr inbounds i8, ptr %0, i64 128
  %26 = getelementptr inbounds i8, ptr %0, i64 136
  %27 = getelementptr inbounds i8, ptr %0, i64 144
  %28 = getelementptr inbounds i8, ptr %0, i64 152
  %29 = getelementptr inbounds i8, ptr %0, i64 160
  %30 = getelementptr inbounds i8, ptr %0, i64 168
  %31 = getelementptr inbounds i8, ptr %0, i64 176
  %32 = getelementptr inbounds i8, ptr %0, i64 184
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %.02732 = phi i64 [ 0, %.preheader.lr.ph ], [ %67, %.preheader ]
  %.02831 = phi ptr [ %14, %.preheader.lr.ph ], [ %64, %.preheader ]
  %33 = tail call i64 @load64_be(ptr noundef %.02831)
  store i64 %33, ptr %17, align 8, !tbaa !10
  %34 = getelementptr inbounds i8, ptr %.02831, i64 8
  %35 = tail call i64 @load64_be(ptr noundef nonnull %34)
  store i64 %35, ptr %18, align 8, !tbaa !10
  %36 = getelementptr inbounds i8, ptr %.02831, i64 16
  %37 = tail call i64 @load64_be(ptr noundef nonnull %36)
  store i64 %37, ptr %19, align 8, !tbaa !10
  %38 = getelementptr inbounds i8, ptr %.02831, i64 24
  %39 = tail call i64 @load64_be(ptr noundef nonnull %38)
  store i64 %39, ptr %20, align 8, !tbaa !10
  %40 = getelementptr inbounds i8, ptr %.02831, i64 32
  %41 = tail call i64 @load64_be(ptr noundef nonnull %40)
  store i64 %41, ptr %21, align 8, !tbaa !10
  %42 = getelementptr inbounds i8, ptr %.02831, i64 40
  %43 = tail call i64 @load64_be(ptr noundef nonnull %42)
  store i64 %43, ptr %22, align 8, !tbaa !10
  %44 = getelementptr inbounds i8, ptr %.02831, i64 48
  %45 = tail call i64 @load64_be(ptr noundef nonnull %44)
  store i64 %45, ptr %23, align 8, !tbaa !10
  %46 = getelementptr inbounds i8, ptr %.02831, i64 56
  %47 = tail call i64 @load64_be(ptr noundef nonnull %46)
  store i64 %47, ptr %24, align 8, !tbaa !10
  %48 = getelementptr inbounds i8, ptr %.02831, i64 64
  %49 = tail call i64 @load64_be(ptr noundef nonnull %48)
  store i64 %49, ptr %25, align 8, !tbaa !10
  %50 = getelementptr inbounds i8, ptr %.02831, i64 72
  %51 = tail call i64 @load64_be(ptr noundef nonnull %50)
  store i64 %51, ptr %26, align 8, !tbaa !10
  %52 = getelementptr inbounds i8, ptr %.02831, i64 80
  %53 = tail call i64 @load64_be(ptr noundef nonnull %52)
  store i64 %53, ptr %27, align 8, !tbaa !10
  %54 = getelementptr inbounds i8, ptr %.02831, i64 88
  %55 = tail call i64 @load64_be(ptr noundef nonnull %54)
  store i64 %55, ptr %28, align 8, !tbaa !10
  %56 = getelementptr inbounds i8, ptr %.02831, i64 96
  %57 = tail call i64 @load64_be(ptr noundef nonnull %56)
  store i64 %57, ptr %29, align 8, !tbaa !10
  %58 = getelementptr inbounds i8, ptr %.02831, i64 104
  %59 = tail call i64 @load64_be(ptr noundef nonnull %58)
  store i64 %59, ptr %30, align 8, !tbaa !10
  %60 = getelementptr inbounds i8, ptr %.02831, i64 112
  %61 = tail call i64 @load64_be(ptr noundef nonnull %60)
  store i64 %61, ptr %31, align 8, !tbaa !10
  %62 = getelementptr inbounds i8, ptr %.02831, i64 120
  %63 = tail call i64 @load64_be(ptr noundef nonnull %62)
  store i64 %63, ptr %32, align 8, !tbaa !10
  %64 = getelementptr inbounds i8, ptr %.02831, i64 128
  %65 = load i64, ptr %6, align 8, !tbaa !5
  %66 = add i64 %65, 128
  store i64 %66, ptr %6, align 8, !tbaa !5
  tail call void @sha512_end_block(ptr noundef nonnull %0)
  %67 = add nuw nsw i64 %.02732, 1
  %exitcond.not = icmp eq i64 %67, %16
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %.preheader, %12
  %.028.lcssa = phi ptr [ %14, %12 ], [ %64, %.preheader ]
  %68 = and i64 %15, 127
  tail call void @sha512_update(ptr noundef nonnull %0, ptr noundef %.028.lcssa, i64 noundef %68)
  br label %69

69:                                               ; preds = %3, %._crit_edge
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i64 @align(i64 noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare hidden i64 @load64_be(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @sha512_end_block(ptr noundef) 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, !9, i64 208}
!6 = !{!"", !7, i64 0, !7, i64 64, !7, i64 192, !9, i64 208}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!9, !9, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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