; LLVM IR from albertobsd/keyhunt :: hash/sha256.ll (ZN7CSHA2568FinalizeEPh)

; 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.CSHA256 = type { [8 x i32], [64 x i8], i64 }

@_ZN7_sha256L3padE = external hidden constant <{ i8, [63 x i8] }>, align 16

; 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 speculatable willreturn memory(none)
declare i32 @llvm.bswap.i32(i32) #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
declare dso_local void @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef, i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7CSHA2568FinalizeEPh(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [8 x i8], align 1
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = getelementptr inbounds %class.CSHA256, ptr %6, i32 0, i32 2
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = shl i64 %8, 3
  %10 = call i64 @llvm.bswap.i64(i64 %9)
  %11 = getelementptr inbounds [8 x i8], ptr %5, i64 0, i64 0
  store i64 %10, ptr %11, align 1, !tbaa !12
  %12 = getelementptr inbounds %class.CSHA256, ptr %6, i32 0, i32 2
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = urem i64 %13, 64
  %15 = sub i64 119, %14
  %16 = urem i64 %15, 64
  %17 = add i64 1, %16
  call void @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104) %6, ptr noundef @_ZN7_sha256L3padE, i64 noundef %17)
  %18 = getelementptr inbounds [8 x i8], ptr %5, i64 0, i64 0
  call void @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104) %6, ptr noundef %18, i64 noundef 8)
  %19 = getelementptr inbounds %class.CSHA256, ptr %6, i32 0, i32 0
  %20 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 0
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = call i32 @llvm.bswap.i32(i32 %21)
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %22, ptr %23, align 4, !tbaa !13
  %24 = getelementptr inbounds %class.CSHA256, ptr %6, i32 0, i32 0
  %25 = getelementptr inbounds [8 x i32], ptr %24, i64 0, i64 1
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = call i32 @llvm.bswap.i32(i32 %26)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 4
  store i32 %27, ptr %29, align 4, !tbaa !13
  %30 = getelementptr inbounds %class.CSHA256, ptr %6, i32 0, i32 0
  %31 = getelementptr inbounds [8 x i32], ptr %30, i64 0, i64 2
  %32 = load i32, ptr %31, align 8, !tbaa !13
  %33 = call i32 @llvm.bswap.i32(i32 %32)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 8
  store i32 %33, ptr %35, align 4, !tbaa !13
  %36 = getelementptr inbounds %class.CSHA256, ptr %6, i32 0, i32 0
  %37 = getelementptr inbounds [8 x i32], ptr %36, i64 0, i64 3
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = call i32 @llvm.bswap.i32(i32 %38)
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 12
  store i32 %39, ptr %41, align 4, !tbaa !13
  %42 = getelementptr inbounds %class.CSHA256, ptr %6, i32 0, i32 0
  %43 = getelementptr inbounds [8 x i32], ptr %42, i64 0, i64 4
  %44 = load i32, ptr %43, align 8, !tbaa !13
  %45 = call i32 @llvm.bswap.i32(i32 %44)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 16
  store i32 %45, ptr %47, align 4, !tbaa !13
  %48 = getelementptr inbounds %class.CSHA256, ptr %6, i32 0, i32 0
  %49 = getelementptr inbounds [8 x i32], ptr %48, i64 0, i64 5
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = call i32 @llvm.bswap.i32(i32 %50)
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 20
  store i32 %51, ptr %53, align 4, !tbaa !13
  %54 = getelementptr inbounds %class.CSHA256, ptr %6, i32 0, i32 0
  %55 = getelementptr inbounds [8 x i32], ptr %54, i64 0, i64 6
  %56 = load i32, ptr %55, align 8, !tbaa !13
  %57 = call i32 @llvm.bswap.i32(i32 %56)
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i64 24
  store i32 %57, ptr %59, align 4, !tbaa !13
  %60 = getelementptr inbounds %class.CSHA256, ptr %6, i32 0, i32 0
  %61 = getelementptr inbounds [8 x i32], ptr %60, i64 0, i64 7
  %62 = load i32, ptr %61, align 4, !tbaa !13
  %63 = call i32 @llvm.bswap.i32(i32 %62)
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 28
  store i32 %63, ptr %65, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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++ TBAA"}
!9 = !{!10, !11, i64 96}
!10 = !{!"_ZTS7CSHA256", !7, i64 0, !7, i64 32, !11, i64 96}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}


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

@_ZN7_sha256L3padE = external hidden constant <{ i8, [63 x i8] }>, align 16

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef, i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7CSHA2568FinalizeEPh(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #2 align 2 {
  %3 = alloca [8 x i8], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = shl i64 %5, 3
  %7 = tail call i64 @llvm.bswap.i64(i64 %6)
  store i64 %7, ptr %3, align 8, !tbaa !10
  %8 = sub i64 55, %5
  %9 = and i64 %8, 63
  %10 = add nuw nsw i64 %9, 1
  tail call void @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull @_ZN7_sha256L3padE, i64 noundef %10)
  call void @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull %3, i64 noundef 8)
  %11 = load i32, ptr %0, align 8, !tbaa !11
  %12 = call i32 @llvm.bswap.i32(i32 %11)
  store i32 %12, ptr %1, align 4, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %0, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = call i32 @llvm.bswap.i32(i32 %14)
  %16 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %15, ptr %16, align 4, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = call i32 @llvm.bswap.i32(i32 %18)
  %20 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %19, ptr %20, align 4, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %0, i64 12
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = call i32 @llvm.bswap.i32(i32 %22)
  %24 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %23, ptr %24, align 4, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = call i32 @llvm.bswap.i32(i32 %26)
  %28 = getelementptr inbounds i8, ptr %1, i64 16
  store i32 %27, ptr %28, align 4, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %0, i64 20
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = call i32 @llvm.bswap.i32(i32 %30)
  %32 = getelementptr inbounds i8, ptr %1, i64 20
  store i32 %31, ptr %32, align 4, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %0, i64 24
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = call i32 @llvm.bswap.i32(i32 %34)
  %36 = getelementptr inbounds i8, ptr %1, i64 24
  store i32 %35, ptr %36, align 4, !tbaa !11
  %37 = getelementptr inbounds i8, ptr %0, i64 28
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = call i32 @llvm.bswap.i32(i32 %38)
  %40 = getelementptr inbounds i8, ptr %1, i64 28
  store i32 %39, ptr %40, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret void
}

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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass