; LLVM IR from albertobsd/keyhunt :: hash/sha512.ll (ZN7CSHA5128FinalizeEPh)

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

%class.CSHA512 = type { [8 x i64], [128 x i8], 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: mustprogress uwtable
declare hidden void @_ZN7_sha512L9TransformEPmPKh(ptr noundef, ptr noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7CSHA5128FinalizeEPh(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef %1) #1 align 2 {
  %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
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %8 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 2
  %9 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %9, ptr %5, align 8, !tbaa !12
  %10 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 1
  %11 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 2
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = add i64 %12, 1
  store i64 %13, ptr %11, align 8, !tbaa !9
  %14 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 %12
  store i8 -128, ptr %14, align 1, !tbaa !13
  %15 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 2
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = icmp ugt i64 %16, 112
  br i1 %17, label %18, label %32

18:                                               ; preds = %2
  %19 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 1
  %20 = getelementptr inbounds [128 x i8], ptr %19, i64 0, i64 0
  %21 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 2
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  %24 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 2
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = sub i64 128, %25
  call void @llvm.memset.p0.i64(ptr align 1 %23, i8 0, i64 %26, i1 false)
  %27 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 0
  %28 = getelementptr inbounds [8 x i64], ptr %27, i64 0, i64 0
  %29 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 1
  %30 = getelementptr inbounds [128 x i8], ptr %29, i64 0, i64 0
  call void @_ZN7_sha512L9TransformEPmPKh(ptr noundef %28, ptr noundef %30)
  %31 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 2
  store i64 0, ptr %31, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %18, %2
  %33 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 1
  %34 = getelementptr inbounds [128 x i8], ptr %33, i64 0, i64 0
  %35 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %34, i64 %36
  %38 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 2
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = sub i64 112, %39
  call void @llvm.memset.p0.i64(ptr align 1 %37, i8 0, i64 %40, i1 false)
  %41 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 3
  %42 = load i64, ptr %41, align 8, !tbaa !14
  %43 = lshr i64 %42, 54
  %44 = call i64 @llvm.bswap.i64(i64 %43)
  %45 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 1
  %46 = getelementptr inbounds [128 x i8], ptr %45, i64 0, i64 0
  %47 = getelementptr inbounds i8, ptr %46, i64 112
  store i64 %44, ptr %47, align 8, !tbaa !12
  %48 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 3
  %49 = load i64, ptr %48, align 8, !tbaa !14
  %50 = shl i64 %49, 7
  %51 = load i64, ptr %5, align 8, !tbaa !12
  %52 = or i64 %50, %51
  %53 = shl i64 %52, 3
  %54 = call i64 @llvm.bswap.i64(i64 %53)
  %55 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 1
  %56 = getelementptr inbounds [128 x i8], ptr %55, i64 0, i64 0
  %57 = getelementptr inbounds i8, ptr %56, i64 120
  store i64 %54, ptr %57, align 8, !tbaa !12
  %58 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 0
  %59 = getelementptr inbounds [8 x i64], ptr %58, i64 0, i64 0
  %60 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 1
  %61 = getelementptr inbounds [128 x i8], ptr %60, i64 0, i64 0
  call void @_ZN7_sha512L9TransformEPmPKh(ptr noundef %59, ptr noundef %61)
  store i64 0, ptr %6, align 8, !tbaa !12
  br label %62

62:                                               ; preds = %75, %32
  %63 = load i64, ptr %6, align 8, !tbaa !12
  %64 = icmp ult i64 %63, 8
  br i1 %64, label %65, label %78

65:                                               ; preds = %62
  %66 = getelementptr inbounds %class.CSHA512, ptr %7, i32 0, i32 0
  %67 = load i64, ptr %6, align 8, !tbaa !12
  %68 = getelementptr inbounds [8 x i64], ptr %66, i64 0, i64 %67
  %69 = load i64, ptr %68, align 8, !tbaa !12
  %70 = call i64 @llvm.bswap.i64(i64 %69)
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = load i64, ptr %6, align 8, !tbaa !12
  %73 = mul i64 8, %72
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  store i64 %70, ptr %74, align 8, !tbaa !12
  br label %75

75:                                               ; preds = %65
  %76 = load i64, ptr %6, align 8, !tbaa !12
  %77 = add i64 %76, 1
  store i64 %77, ptr %6, align 8, !tbaa !12
  br label %62, !llvm.loop !15

78:                                               ; preds = %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.bswap.i64(i64) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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++ TBAA"}
!9 = !{!10, !11, i64 192}
!10 = !{!"_ZTS7CSHA512", !7, i64 0, !7, i64 64, !11, i64 192, !11, i64 200}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !11, i64 200}
!15 = distinct !{!15, !16}
!16 = !{!"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 uwtable
declare hidden void @_ZN7_sha512L9TransformEPmPKh(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7CSHA5128FinalizeEPh(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 192
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = add i64 %4, 1
  store i64 %6, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds [128 x i8], ptr %5, i64 0, i64 %4
  store i8 -128, ptr %7, align 1, !tbaa !10
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = icmp ugt i64 %8, 112
  br i1 %9, label %10, label %13

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %5, i64 %8
  %12 = sub i64 128, %8
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %11, i8 0, i64 %12, i1 false)
  tail call void @_ZN7_sha512L9TransformEPmPKh(ptr noundef nonnull %0, ptr noundef nonnull %5)
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %10, %2
  %14 = phi i64 [ 0, %10 ], [ %8, %2 ]
  %15 = getelementptr inbounds i8, ptr %5, i64 %14
  %16 = sub nuw nsw i64 112, %14
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %15, i8 0, i64 %16, i1 false)
  %17 = getelementptr inbounds i8, ptr %0, i64 200
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = lshr i64 %18, 54
  %20 = tail call i64 @llvm.bswap.i64(i64 %19)
  %21 = getelementptr inbounds i8, ptr %0, i64 176
  store i64 %20, ptr %21, align 8, !tbaa !12
  %22 = shl i64 %18, 10
  %23 = shl i64 %4, 3
  %24 = or i64 %22, %23
  %25 = tail call i64 @llvm.bswap.i64(i64 %24)
  %26 = getelementptr inbounds i8, ptr %0, i64 184
  store i64 %25, ptr %26, align 8, !tbaa !12
  tail call void @_ZN7_sha512L9TransformEPmPKh(ptr noundef nonnull %0, ptr noundef nonnull %5)
  %27 = load i64, ptr %0, align 8, !tbaa !12
  %28 = tail call i64 @llvm.bswap.i64(i64 %27)
  store i64 %28, ptr %1, align 8, !tbaa !12
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  %30 = load i64, ptr %29, align 8, !tbaa !12
  %31 = tail call i64 @llvm.bswap.i64(i64 %30)
  %32 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 %31, ptr %32, align 8, !tbaa !12
  %33 = getelementptr inbounds i8, ptr %0, i64 16
  %34 = load i64, ptr %33, align 8, !tbaa !12
  %35 = tail call i64 @llvm.bswap.i64(i64 %34)
  %36 = getelementptr inbounds i8, ptr %1, i64 16
  store i64 %35, ptr %36, align 8, !tbaa !12
  %37 = getelementptr inbounds i8, ptr %0, i64 24
  %38 = load i64, ptr %37, align 8, !tbaa !12
  %39 = tail call i64 @llvm.bswap.i64(i64 %38)
  %40 = getelementptr inbounds i8, ptr %1, i64 24
  store i64 %39, ptr %40, align 8, !tbaa !12
  %41 = getelementptr inbounds i8, ptr %0, i64 32
  %42 = load i64, ptr %41, align 8, !tbaa !12
  %43 = tail call i64 @llvm.bswap.i64(i64 %42)
  %44 = getelementptr inbounds i8, ptr %1, i64 32
  store i64 %43, ptr %44, align 8, !tbaa !12
  %45 = getelementptr inbounds i8, ptr %0, i64 40
  %46 = load i64, ptr %45, align 8, !tbaa !12
  %47 = tail call i64 @llvm.bswap.i64(i64 %46)
  %48 = getelementptr inbounds i8, ptr %1, i64 40
  store i64 %47, ptr %48, align 8, !tbaa !12
  %49 = getelementptr inbounds i8, ptr %0, i64 48
  %50 = load i64, ptr %49, align 8, !tbaa !12
  %51 = tail call i64 @llvm.bswap.i64(i64 %50)
  %52 = getelementptr inbounds i8, ptr %1, i64 48
  store i64 %51, ptr %52, align 8, !tbaa !12
  %53 = getelementptr inbounds i8, ptr %0, i64 56
  %54 = load i64, ptr %53, align 8, !tbaa !12
  %55 = tail call i64 @llvm.bswap.i64(i64 %54)
  %56 = getelementptr inbounds i8, ptr %1, i64 56
  store i64 %55, ptr %56, align 8, !tbaa !12
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.bswap.i64(i64) #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable 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, !9, i64 192}
!6 = !{!"_ZTS7CSHA512", !7, i64 0, !7, i64 64, !9, i64 192, !9, i64 200}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !9, i64 200}
!12 = !{!9, !9, i64 0}


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