; LLVM IR from Waqar144/simplecrypto-cxx :: simplecrypto-cxx/sha384.ll (Z12sha384_FinalP10SHA384_CTXPh)

; 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.SHA384_CTX = type { %"struct.std::array", %"struct.std::array.0", %"struct.std::array.1" }
%"struct.std::array" = type { [8 x i64] }
%"struct.std::array.0" = type { [2 x i64] }
%"struct.std::array.1" = type { [16 x i64] }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64), i64 noundef) #0 align 2

; 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: 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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i64 @_ZL9reverse64m(i64 noundef) #3

; Function Attrs: mustprogress nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayImLm8EE4dataEv(ptr noundef nonnull align 8 dereferenceable(64)) #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12sha384_FinalP10SHA384_CTXPh(ptr noundef %0, ptr noundef %1) #5 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %35

8:                                                ; preds = %2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZL11sha384_LastP10SHA384_CTX(ptr noundef %9)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %27, %8
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 8
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  br label %30

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.SHA384_CTX, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %16, i64 noundef %18) #7
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = call noundef i64 @_ZL9reverse64m(i64 noundef %20)
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.SHA384_CTX, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %23, i64 noundef %25) #7
  store i64 %21, ptr %26, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %14
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %5, align 4, !tbaa !9
  br label %10, !llvm.loop !13

30:                                               ; preds = %13
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.SHA384_CTX, ptr %32, i32 0, i32 0
  %34 = call noundef ptr @_ZNSt5arrayImLm8EE4dataEv(ptr noundef nonnull align 8 dereferenceable(64) %33) #8
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %31, ptr align 8 %34, i64 48, i1 false)
  br label %35

35:                                               ; preds = %30, %2
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %36, i8 0, i64 208, i1 false)
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL11sha384_LastP10SHA384_CTX(ptr noundef) #5

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint mustprogress 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 #4 = { mustprogress nounwind willreturn memory(none) 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 #5 = { mustprogress 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 #6 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress 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) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i64 @_ZL9reverse64m(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayImLm8EE4dataEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12sha384_FinalP10SHA384_CTXPh(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #4 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %37, label %3

3:                                                ; preds = %2
  tail call void @_ZL11sha384_LastP10SHA384_CTX(ptr noundef %0)
  %4 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 0) #6
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = tail call noundef i64 @_ZL9reverse64m(i64 noundef %5)
  %7 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 0) #6
  store i64 %6, ptr %7, align 8, !tbaa !5
  %8 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 1) #6
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = tail call noundef i64 @_ZL9reverse64m(i64 noundef %9)
  %11 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 1) #6
  store i64 %10, ptr %11, align 8, !tbaa !5
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 2) #6
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = tail call noundef i64 @_ZL9reverse64m(i64 noundef %13)
  %15 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 2) #6
  store i64 %14, ptr %15, align 8, !tbaa !5
  %16 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 3) #6
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = tail call noundef i64 @_ZL9reverse64m(i64 noundef %17)
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 3) #6
  store i64 %18, ptr %19, align 8, !tbaa !5
  %20 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 4) #6
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = tail call noundef i64 @_ZL9reverse64m(i64 noundef %21)
  %23 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 4) #6
  store i64 %22, ptr %23, align 8, !tbaa !5
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 5) #6
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = tail call noundef i64 @_ZL9reverse64m(i64 noundef %25)
  %27 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 5) #6
  store i64 %26, ptr %27, align 8, !tbaa !5
  %28 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 6) #6
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = tail call noundef i64 @_ZL9reverse64m(i64 noundef %29)
  %31 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 6) #6
  store i64 %30, ptr %31, align 8, !tbaa !5
  %32 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 7) #6
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = tail call noundef i64 @_ZL9reverse64m(i64 noundef %33)
  %35 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayImLm8EEixEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef 7) #6
  store i64 %34, ptr %35, align 8, !tbaa !5
  %36 = tail call noundef ptr @_ZNSt5arrayImLm8EE4dataEv(ptr noundef nonnull align 8 dereferenceable(64) %0) #7
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(48) %36, i64 48, i1 false)
  br label %37

37:                                               ; preds = %3, %2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(208) %0, i8 0, i64 208, i1 false)
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL11sha384_LastP10SHA384_CTX(ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

attributes #0 = { mustprogress 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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 #3 = { mustprogress nofree nosync nounwind willreturn memory(none) 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 #4 = { mustprogress 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 #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(none) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass