; 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_final(ptr noundef, ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @crypto_hmac_sha512_final(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  call void @crypto_sha512_final(ptr noundef %7, ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %22, %2
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = icmp ult i64 %10, 128
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %14, i32 0, i32 0
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds [128 x i8], ptr %15, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = zext i8 %18 to i32
  %20 = xor i32 %19, 106
  %21 = trunc i32 %20 to i8
  store i8 %21, ptr %17, align 1, !tbaa !11
  br label %22

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

25:                                               ; preds = %12
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %26, i32 0, i32 1
  call void @crypto_sha512_init(ptr noundef %27)
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [128 x i8], ptr %31, i64 0, i64 0
  call void @crypto_sha512_update(ptr noundef %29, ptr noundef %32, i64 noundef 128)
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  call void @crypto_sha512_update(ptr noundef %34, ptr noundef %35, i64 noundef 64)
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.crypto_hmac_sha512_ctx, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @crypto_sha512_final(ptr noundef %37, ptr noundef %38)
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  call void @crypto_wipe(ptr noundef %39, i64 noundef 344)
  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 = { "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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

; 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_final(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @crypto_hmac_sha512_final(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
vector.ph:
  %2 = getelementptr inbounds i8, ptr %0, i64 128
  tail call void @crypto_sha512_final(ptr noundef nonnull %2, ptr noundef %1)
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %wide.load = load <16 x i8>, ptr %0, align 1, !tbaa !5
  %wide.load14 = load <16 x i8>, ptr %3, align 1, !tbaa !5
  %4 = xor <16 x i8> %wide.load, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  %5 = xor <16 x i8> %wide.load14, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  store <16 x i8> %4, ptr %0, align 1, !tbaa !5
  store <16 x i8> %5, ptr %3, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %wide.load.1 = load <16 x i8>, ptr %6, align 1, !tbaa !5
  %wide.load14.1 = load <16 x i8>, ptr %7, align 1, !tbaa !5
  %8 = xor <16 x i8> %wide.load.1, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  %9 = xor <16 x i8> %wide.load14.1, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  store <16 x i8> %8, ptr %6, align 1, !tbaa !5
  store <16 x i8> %9, ptr %7, align 1, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 64
  %11 = getelementptr inbounds i8, ptr %0, i64 80
  %wide.load.2 = load <16 x i8>, ptr %10, align 1, !tbaa !5
  %wide.load14.2 = load <16 x i8>, ptr %11, align 1, !tbaa !5
  %12 = xor <16 x i8> %wide.load.2, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  %13 = xor <16 x i8> %wide.load14.2, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  store <16 x i8> %12, ptr %10, align 1, !tbaa !5
  store <16 x i8> %13, ptr %11, align 1, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 96
  %15 = getelementptr inbounds i8, ptr %0, i64 112
  %wide.load.3 = load <16 x i8>, ptr %14, align 1, !tbaa !5
  %wide.load14.3 = load <16 x i8>, ptr %15, align 1, !tbaa !5
  %16 = xor <16 x i8> %wide.load.3, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  %17 = xor <16 x i8> %wide.load14.3, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  store <16 x i8> %16, ptr %14, align 1, !tbaa !5
  store <16 x i8> %17, ptr %15, align 1, !tbaa !5
  tail call void @crypto_sha512_init(ptr noundef nonnull %2)
  tail call void @crypto_sha512_update(ptr noundef nonnull %2, ptr noundef nonnull %0, i64 noundef 128)
  tail call void @crypto_sha512_update(ptr noundef nonnull %2, ptr noundef %1, i64 noundef 64)
  tail call void @crypto_sha512_final(ptr noundef nonnull %2, ptr noundef %1)
  tail call void @crypto_wipe(ptr noundef nonnull %0, i64 noundef 344) #2
  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 = { "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 = { 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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass