; LLVM IR from BabitMF/bmf :: bmf_lite/src/algorithm/modules/operators/utils/SHA256.ll (ZN8bmf_lite6SHA2563padEv)

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8bmf_lite6SHA2569transformEv(ptr noundef nonnull align 8 dereferenceable(112)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8bmf_lite6SHA2563padEv(ptr noundef nonnull align 8 dereferenceable(112) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %6 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 1
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = zext i32 %7 to i64
  store i64 %8, ptr %3, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  %9 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp ult i32 %10, 56
  %12 = zext i1 %11 to i64
  %13 = select i1 %11, i32 56, i32 64
  %14 = trunc i32 %13 to i8
  store i8 %14, ptr %4, align 1, !tbaa !14
  %15 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 0
  %16 = load i64, ptr %3, align 8, !tbaa !13
  %17 = add i64 %16, 1
  store i64 %17, ptr %3, align 8, !tbaa !13
  %18 = getelementptr inbounds [64 x i8], ptr %15, i64 0, i64 %16
  store i8 -128, ptr %18, align 1, !tbaa !14
  br label %19

19:                                               ; preds = %24, %1
  %20 = load i64, ptr %3, align 8, !tbaa !13
  %21 = load i8, ptr %4, align 1, !tbaa !14
  %22 = zext i8 %21 to i64
  %23 = icmp ult i64 %20, %22
  br i1 %23, label %24, label %29

24:                                               ; preds = %19
  %25 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 0
  %26 = load i64, ptr %3, align 8, !tbaa !13
  %27 = add i64 %26, 1
  store i64 %27, ptr %3, align 8, !tbaa !13
  %28 = getelementptr inbounds [64 x i8], ptr %25, i64 0, i64 %26
  store i8 0, ptr %28, align 1, !tbaa !14
  br label %19, !llvm.loop !15

29:                                               ; preds = %19
  %30 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !9
  %32 = icmp uge i32 %31, 56
  br i1 %32, label %33, label %36

33:                                               ; preds = %29
  call void @_ZN8bmf_lite6SHA2569transformEv(ptr noundef nonnull align 8 dereferenceable(112) %5)
  %34 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 0
  %35 = getelementptr inbounds [64 x i8], ptr %34, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %35, i8 0, i64 56, i1 false)
  br label %36

36:                                               ; preds = %33, %29
  %37 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !9
  %39 = mul i32 %38, 8
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 2
  %42 = load i64, ptr %41, align 8, !tbaa !17
  %43 = add i64 %42, %40
  store i64 %43, ptr %41, align 8, !tbaa !17
  %44 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !17
  %46 = trunc i64 %45 to i8
  %47 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 0
  %48 = getelementptr inbounds [64 x i8], ptr %47, i64 0, i64 63
  store i8 %46, ptr %48, align 1, !tbaa !14
  %49 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 2
  %50 = load i64, ptr %49, align 8, !tbaa !17
  %51 = lshr i64 %50, 8
  %52 = trunc i64 %51 to i8
  %53 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 0
  %54 = getelementptr inbounds [64 x i8], ptr %53, i64 0, i64 62
  store i8 %52, ptr %54, align 2, !tbaa !14
  %55 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 2
  %56 = load i64, ptr %55, align 8, !tbaa !17
  %57 = lshr i64 %56, 16
  %58 = trunc i64 %57 to i8
  %59 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 0
  %60 = getelementptr inbounds [64 x i8], ptr %59, i64 0, i64 61
  store i8 %58, ptr %60, align 1, !tbaa !14
  %61 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 2
  %62 = load i64, ptr %61, align 8, !tbaa !17
  %63 = lshr i64 %62, 24
  %64 = trunc i64 %63 to i8
  %65 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 0
  %66 = getelementptr inbounds [64 x i8], ptr %65, i64 0, i64 60
  store i8 %64, ptr %66, align 4, !tbaa !14
  %67 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 2
  %68 = load i64, ptr %67, align 8, !tbaa !17
  %69 = lshr i64 %68, 32
  %70 = trunc i64 %69 to i8
  %71 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 0
  %72 = getelementptr inbounds [64 x i8], ptr %71, i64 0, i64 59
  store i8 %70, ptr %72, align 1, !tbaa !14
  %73 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 2
  %74 = load i64, ptr %73, align 8, !tbaa !17
  %75 = lshr i64 %74, 40
  %76 = trunc i64 %75 to i8
  %77 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 0
  %78 = getelementptr inbounds [64 x i8], ptr %77, i64 0, i64 58
  store i8 %76, ptr %78, align 2, !tbaa !14
  %79 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 2
  %80 = load i64, ptr %79, align 8, !tbaa !17
  %81 = lshr i64 %80, 48
  %82 = trunc i64 %81 to i8
  %83 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 0
  %84 = getelementptr inbounds [64 x i8], ptr %83, i64 0, i64 57
  store i8 %82, ptr %84, align 1, !tbaa !14
  %85 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 2
  %86 = load i64, ptr %85, align 8, !tbaa !17
  %87 = lshr i64 %86, 56
  %88 = trunc i64 %87 to i8
  %89 = getelementptr inbounds %"class.bmf_lite::SHA256", ptr %5, i32 0, i32 0
  %90 = getelementptr inbounds [64 x i8], ptr %89, i64 0, i64 56
  store i8 %88, ptr %90, align 8, !tbaa !14
  call void @_ZN8bmf_lite6SHA2569transformEv(ptr noundef nonnull align 8 dereferenceable(112) %5)
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 64}
!10 = !{!"_ZTSN8bmf_lite6SHA256E", !7, i64 0, !11, i64 64, !12, i64 72, !7, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !12, i64 72}


; 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 void @_ZN8bmf_lite6SHA2569transformEv(ptr noundef nonnull align 8 dereferenceable(112)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8bmf_lite6SHA2563padEv(ptr noundef nonnull align 8 dereferenceable(112) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 64
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = zext i32 %3 to i64
  %5 = icmp ult i32 %3, 56
  %6 = getelementptr inbounds [64 x i8], ptr %0, i64 0, i64 %4
  store i8 -128, ptr %6, align 1, !tbaa !11
  %7 = select i1 %5, i64 56, i64 64
  %.04 = add nuw nsw i64 %4, 1
  %8 = icmp ult i64 %.04, %7
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %scevgep = getelementptr i8, ptr %0, i64 %.04
  %9 = xor i64 %4, -1
  %10 = add nsw i64 %7, %9
  tail call void @llvm.memset.p0.i64(ptr align 1 %scevgep, i8 0, i64 %10, i1 false), !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %1
  %11 = load i32, ptr %2, align 8, !tbaa !5
  %12 = icmp ugt i32 %11, 55
  br i1 %12, label %13, label %14

13:                                               ; preds = %._crit_edge
  tail call void @_ZN8bmf_lite6SHA2569transformEv(ptr noundef nonnull align 8 dereferenceable(112) %0)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %0, i8 0, i64 56, i1 false)
  %.pre = load i32, ptr %2, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %13, %._crit_edge
  %15 = phi i32 [ %.pre, %13 ], [ %11, %._crit_edge ]
  %16 = shl i32 %15, 3
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %0, i64 72
  %19 = load i64, ptr %18, align 8, !tbaa !12
  %20 = add i64 %19, %17
  store i64 %20, ptr %18, align 8, !tbaa !12
  %21 = trunc i64 %20 to i8
  %22 = getelementptr inbounds i8, ptr %0, i64 63
  store i8 %21, ptr %22, align 1, !tbaa !11
  %23 = lshr i64 %20, 8
  %24 = trunc i64 %23 to i8
  %25 = getelementptr inbounds i8, ptr %0, i64 62
  store i8 %24, ptr %25, align 2, !tbaa !11
  %26 = lshr i64 %20, 16
  %27 = trunc i64 %26 to i8
  %28 = getelementptr inbounds i8, ptr %0, i64 61
  store i8 %27, ptr %28, align 1, !tbaa !11
  %29 = lshr i64 %20, 24
  %30 = trunc i64 %29 to i8
  %31 = getelementptr inbounds i8, ptr %0, i64 60
  store i8 %30, ptr %31, align 4, !tbaa !11
  %32 = lshr i64 %20, 32
  %33 = trunc i64 %32 to i8
  %34 = getelementptr inbounds i8, ptr %0, i64 59
  store i8 %33, ptr %34, align 1, !tbaa !11
  %35 = lshr i64 %20, 40
  %36 = trunc i64 %35 to i8
  %37 = getelementptr inbounds i8, ptr %0, i64 58
  store i8 %36, ptr %37, align 2, !tbaa !11
  %38 = lshr i64 %20, 48
  %39 = trunc i64 %38 to i8
  %40 = getelementptr inbounds i8, ptr %0, i64 57
  store i8 %39, ptr %40, align 1, !tbaa !11
  %41 = lshr i64 %20, 56
  %42 = trunc nuw i64 %41 to i8
  %43 = getelementptr inbounds i8, ptr %0, i64 56
  store i8 %42, ptr %43, align 8, !tbaa !11
  tail call void @_ZN8bmf_lite6SHA2569transformEv(ptr noundef nonnull align 8 dereferenceable(112) %0)
  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

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: write) }

!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 64}
!6 = !{!"_ZTSN8bmf_lite6SHA256E", !7, i64 0, !9, i64 64, !10, i64 72, !7, i64 80}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !10, i64 72}


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