; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @crypto_sha512_final(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %7, i32 0, i32 2
  %9 = getelementptr inbounds [2 x i64], ptr %8, i64 0, i64 0
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %10, i32 0, i32 3
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = mul i64 %12, 8
  call void @sha512_incr(ptr noundef %9, i64 noundef %13)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  call void @sha512_set_input(ptr noundef %14, i8 noundef zeroext -128)
  %15 = load ptr, ptr %3, 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 !9
  %18 = icmp ugt i64 %17, 111
  br i1 %18, label %19, label %34

19:                                               ; preds = %2
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  call void @sha512_compress(ptr noundef %20)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !12
  br label %21

21:                                               ; preds = %30, %19
  %22 = load i64, ptr %5, align 8, !tbaa !12
  %23 = icmp ult i64 %22, 14
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %33

25:                                               ; preds = %21
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %26, i32 0, i32 1
  %28 = load i64, ptr %5, align 8, !tbaa !12
  %29 = getelementptr inbounds [16 x i64], ptr %27, i64 0, i64 %28
  store i64 0, ptr %29, align 8, !tbaa !12
  br label %30

30:                                               ; preds = %25
  %31 = load i64, ptr %5, align 8, !tbaa !12
  %32 = add i64 %31, 1
  store i64 %32, ptr %5, align 8, !tbaa !12
  br label %21, !llvm.loop !13

33:                                               ; preds = %24
  br label %34

34:                                               ; preds = %33, %2
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %35, i32 0, i32 2
  %37 = getelementptr inbounds [2 x i64], ptr %36, i64 0, i64 0
  %38 = load i64, ptr %37, align 8, !tbaa !12
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %39, i32 0, i32 1
  %41 = getelementptr inbounds [16 x i64], ptr %40, i64 0, i64 14
  store i64 %38, ptr %41, align 8, !tbaa !12
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds [2 x i64], ptr %43, i64 0, i64 1
  %45 = load i64, ptr %44, align 8, !tbaa !12
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds [16 x i64], ptr %47, i64 0, i64 15
  store i64 %45, ptr %48, align 8, !tbaa !12
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  call void @sha512_compress(ptr noundef %49)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !12
  br label %50

50:                                               ; preds = %64, %34
  %51 = load i64, ptr %6, align 8, !tbaa !12
  %52 = icmp ult i64 %51, 8
  br i1 %52, label %54, label %53

53:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %67

54:                                               ; preds = %50
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load i64, ptr %6, align 8, !tbaa !12
  %57 = mul i64 %56, 8
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.crypto_sha512_ctx, ptr %59, i32 0, i32 0
  %61 = load i64, ptr %6, align 8, !tbaa !12
  %62 = getelementptr inbounds [8 x i64], ptr %60, i64 0, i64 %61
  %63 = load i64, ptr %62, align 8, !tbaa !12
  call void @store64_be(ptr noundef %58, i64 noundef %63)
  br label %64

64:                                               ; preds = %54
  %65 = load i64, ptr %6, align 8, !tbaa !12
  %66 = add i64 %65, 1
  store i64 %66, ptr %6, align 8, !tbaa !12
  br label %50, !llvm.loop !15

67:                                               ; preds = %53
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  call void @crypto_wipe(ptr noundef %68, i64 noundef 216)
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @sha512_set_input(ptr noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare hidden void @sha512_compress(ptr noundef) #1

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

declare void @crypto_wipe(ptr noundef, i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 208}
!10 = !{!"", !7, i64 0, !7, i64 64, !7, i64 192, !11, i64 208}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!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_final(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 192
  %4 = getelementptr inbounds i8, ptr %0, i64 208
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = shl i64 %5, 3
  tail call void @sha512_incr(ptr noundef nonnull %3, i64 noundef %6)
  tail call void @sha512_set_input(ptr noundef %0, i8 noundef zeroext -128)
  %7 = load i64, ptr %4, align 8, !tbaa !5
  %8 = icmp ugt i64 %7, 111
  br i1 %8, label %.loopexit.loopexit, label %.loopexit

.loopexit.loopexit:                               ; preds = %2
  tail call void @sha512_compress(ptr noundef nonnull %0)
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(112) %9, i8 0, i64 112, i1 false), !tbaa !10
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %2
  %10 = getelementptr inbounds i8, ptr %0, i64 176
  %11 = load <2 x i64>, ptr %3, align 8, !tbaa !10
  store <2 x i64> %11, ptr %10, align 8, !tbaa !10
  tail call void @sha512_compress(ptr noundef nonnull %0)
  %12 = load i64, ptr %0, align 8, !tbaa !10
  tail call void @store64_be(ptr noundef %1, i64 noundef %12)
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load i64, ptr %14, align 8, !tbaa !10
  tail call void @store64_be(ptr noundef nonnull %13, i64 noundef %15)
  %16 = getelementptr inbounds i8, ptr %1, i64 16
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load i64, ptr %17, align 8, !tbaa !10
  tail call void @store64_be(ptr noundef nonnull %16, i64 noundef %18)
  %19 = getelementptr inbounds i8, ptr %1, i64 24
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load i64, ptr %20, align 8, !tbaa !10
  tail call void @store64_be(ptr noundef nonnull %19, i64 noundef %21)
  %22 = getelementptr inbounds i8, ptr %1, i64 32
  %23 = getelementptr inbounds i8, ptr %0, i64 32
  %24 = load i64, ptr %23, align 8, !tbaa !10
  tail call void @store64_be(ptr noundef nonnull %22, i64 noundef %24)
  %25 = getelementptr inbounds i8, ptr %1, i64 40
  %26 = getelementptr inbounds i8, ptr %0, i64 40
  %27 = load i64, ptr %26, align 8, !tbaa !10
  tail call void @store64_be(ptr noundef nonnull %25, i64 noundef %27)
  %28 = getelementptr inbounds i8, ptr %1, i64 48
  %29 = getelementptr inbounds i8, ptr %0, i64 48
  %30 = load i64, ptr %29, align 8, !tbaa !10
  tail call void @store64_be(ptr noundef nonnull %28, i64 noundef %30)
  %31 = getelementptr inbounds i8, ptr %1, i64 56
  %32 = getelementptr inbounds i8, ptr %0, i64 56
  %33 = load i64, ptr %32, align 8, !tbaa !10
  tail call void @store64_be(ptr noundef nonnull %31, i64 noundef %33)
  tail call void @crypto_wipe(ptr noundef nonnull %0, i64 noundef 216) #3
  ret void
}

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

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

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

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

declare void @crypto_wipe(ptr noundef, i64 noundef) local_unnamed_addr #1

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass