; LLVM IR from chdb-io/chdb :: base/poco/Foundation/src/SHA1Engine.ll (ZN4Poco10SHA1Engine10updateImplEPKvm)

; 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.Poco::SHA1Engine" = type { %"class.Poco::DigestEngine", %"struct.Poco::SHA1Engine::Context", %"class.std::vector" }
%"class.Poco::DigestEngine" = type { ptr }
%"struct.Poco::SHA1Engine::Context" = type { [5 x i32], i32, i32, [16 x i32], i32 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Poco10SHA1Engine10updateImplEPKvm(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %11 = getelementptr inbounds %"class.Poco::SHA1Engine", ptr %9, i32 0, i32 1
  %12 = getelementptr inbounds %"struct.Poco::SHA1Engine::Context", ptr %11, i32 0, i32 3
  %13 = getelementptr inbounds [16 x i32], ptr %12, i64 0, i64 0
  store ptr %13, ptr %8, align 8, !tbaa !5
  %14 = getelementptr inbounds %"class.Poco::SHA1Engine", ptr %9, i32 0, i32 1
  %15 = getelementptr inbounds %"struct.Poco::SHA1Engine::Context", ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = trunc i64 %17 to i32
  %19 = shl i32 %18, 3
  %20 = add i32 %16, %19
  %21 = getelementptr inbounds %"class.Poco::SHA1Engine", ptr %9, i32 0, i32 1
  %22 = getelementptr inbounds %"struct.Poco::SHA1Engine::Context", ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = icmp ult i32 %20, %23
  br i1 %24, label %25, label %30

25:                                               ; preds = %3
  %26 = getelementptr inbounds %"class.Poco::SHA1Engine", ptr %9, i32 0, i32 1
  %27 = getelementptr inbounds %"struct.Poco::SHA1Engine::Context", ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 8, !tbaa !20
  %29 = add i32 %28, 1
  store i32 %29, ptr %27, align 8, !tbaa !20
  br label %30

30:                                               ; preds = %25, %3
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = trunc i64 %31 to i32
  %33 = shl i32 %32, 3
  %34 = getelementptr inbounds %"class.Poco::SHA1Engine", ptr %9, i32 0, i32 1
  %35 = getelementptr inbounds %"struct.Poco::SHA1Engine::Context", ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = add i32 %36, %33
  store i32 %37, ptr %35, align 4, !tbaa !11
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = trunc i64 %38 to i32
  %40 = lshr i32 %39, 29
  %41 = getelementptr inbounds %"class.Poco::SHA1Engine", ptr %9, i32 0, i32 1
  %42 = getelementptr inbounds %"struct.Poco::SHA1Engine::Context", ptr %41, i32 0, i32 2
  %43 = load i32, ptr %42, align 8, !tbaa !20
  %44 = add i32 %43, %40
  store i32 %44, ptr %42, align 8, !tbaa !20
  br label %45

45:                                               ; preds = %70, %30
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = add i64 %46, -1
  store i64 %47, ptr %6, align 8, !tbaa !9
  %48 = icmp ugt i64 %46, 0
  br i1 %48, label %49, label %71

49:                                               ; preds = %45
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i32 1
  store ptr %51, ptr %7, align 8, !tbaa !5
  %52 = load i8, ptr %50, align 1, !tbaa !21
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %"class.Poco::SHA1Engine", ptr %9, i32 0, i32 1
  %55 = getelementptr inbounds %"struct.Poco::SHA1Engine::Context", ptr %54, i32 0, i32 4
  %56 = load i32, ptr %55, align 4, !tbaa !22
  %57 = add i32 %56, 1
  store i32 %57, ptr %55, align 4, !tbaa !22
  %58 = zext i32 %56 to i64
  %59 = getelementptr inbounds i8, ptr %53, i64 %58
  store i8 %52, ptr %59, align 1, !tbaa !21
  %60 = getelementptr inbounds %"class.Poco::SHA1Engine", ptr %9, i32 0, i32 1
  %61 = getelementptr inbounds %"struct.Poco::SHA1Engine::Context", ptr %60, i32 0, i32 4
  %62 = load i32, ptr %61, align 4, !tbaa !22
  %63 = icmp eq i32 %62, 64
  br i1 %63, label %64, label %70

64:                                               ; preds = %49
  %65 = getelementptr inbounds %"class.Poco::SHA1Engine", ptr %9, i32 0, i32 1
  %66 = getelementptr inbounds %"struct.Poco::SHA1Engine::Context", ptr %65, i32 0, i32 3
  %67 = getelementptr inbounds [16 x i32], ptr %66, i64 0, i64 0
  call void @_ZN4Poco10SHA1Engine11byteReverseEPji(ptr noundef %67, i32 noundef 64)
  call void @_ZN4Poco10SHA1Engine9transformEv(ptr noundef nonnull align 8 dereferenceable(128) %9)
  %68 = getelementptr inbounds %"class.Poco::SHA1Engine", ptr %9, i32 0, i32 1
  %69 = getelementptr inbounds %"struct.Poco::SHA1Engine::Context", ptr %68, i32 0, i32 4
  store i32 0, ptr %69, align 4, !tbaa !22
  br label %70

70:                                               ; preds = %64, %49
  br label %45, !llvm.loop !23

71:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN4Poco10SHA1Engine11byteReverseEPji(ptr noundef, i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Poco10SHA1Engine9transformEv(ptr noundef nonnull align 8 dereferenceable(128)) #3 align 2

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

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 = { nocallback nofree nosync 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 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 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !15, i64 28}
!12 = !{!"_ZTSN4Poco10SHA1EngineE", !13, i64 0, !14, i64 8, !16, i64 104}
!13 = !{!"_ZTSN4Poco12DigestEngineE"}
!14 = !{!"_ZTSN4Poco10SHA1Engine7ContextE", !7, i64 0, !15, i64 20, !15, i64 24, !7, i64 28, !15, i64 92}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTSSt6vectorIhSaIhEE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!12, !15, i64 32}
!21 = !{!7, !7, i64 0}
!22 = !{!12, !15, i64 100}
!23 = distinct !{!23, !24}
!24 = !{!"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
define dso_local void @_ZN4Poco10SHA1Engine10updateImplEPKvm(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr nocapture noundef readonly %1, i64 noundef %2) unnamed_addr #0 align 2 {
._crit_edge10:
  %3 = getelementptr inbounds i8, ptr %0, i64 36
  %4 = getelementptr inbounds i8, ptr %0, i64 28
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = trunc i64 %2 to i32
  %7 = shl i32 %6, 3
  %8 = xor i32 %5, -1
  %9 = icmp ugt i32 %7, %8
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load i32, ptr %10, align 8, !tbaa !17
  %12 = zext i1 %9 to i32
  %13 = add i32 %11, %12
  %14 = add i32 %5, %7
  store i32 %14, ptr %4, align 4, !tbaa !5
  %15 = lshr i32 %6, 29
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  %17 = add i32 %13, %15
  store i32 %17, ptr %16, align 8, !tbaa !17
  %.not8 = icmp eq i64 %2, 0
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %._crit_edge10
  %18 = getelementptr inbounds i8, ptr %0, i64 100
  %.pre11 = load i32, ptr %18, align 4, !tbaa !18
  br label %19

19:                                               ; preds = %.lr.ph, %30
  %20 = phi i32 [ %.pre11, %.lr.ph ], [ %31, %30 ]
  %.in = phi i64 [ %2, %.lr.ph ], [ %21, %30 ]
  %.079 = phi ptr [ %1, %.lr.ph ], [ %22, %30 ]
  %21 = add i64 %.in, -1
  %22 = getelementptr inbounds i8, ptr %.079, i64 1
  %23 = load i8, ptr %.079, align 1, !tbaa !19
  %24 = add i32 %20, 1
  store i32 %24, ptr %18, align 4, !tbaa !18
  %25 = zext i32 %20 to i64
  %26 = getelementptr inbounds i8, ptr %3, i64 %25
  store i8 %23, ptr %26, align 1, !tbaa !19
  %27 = load i32, ptr %18, align 4, !tbaa !18
  %28 = icmp eq i32 %27, 64
  br i1 %28, label %29, label %30

29:                                               ; preds = %19
  tail call void @_ZN4Poco10SHA1Engine11byteReverseEPji(ptr noundef nonnull %3, i32 noundef 64)
  tail call void @_ZN4Poco10SHA1Engine9transformEv(ptr noundef nonnull align 8 dereferenceable(128) %0)
  store i32 0, ptr %18, align 4, !tbaa !18
  br label %30

30:                                               ; preds = %29, %19
  %31 = phi i32 [ 0, %29 ], [ %27, %19 ]
  %.not = icmp eq i64 %21, 0
  br i1 %.not, label %._crit_edge, label %19, !llvm.loop !20

._crit_edge:                                      ; preds = %30, %._crit_edge10
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN4Poco10SHA1Engine11byteReverseEPji(ptr noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Poco10SHA1Engine9transformEv(ptr noundef nonnull align 8 dereferenceable(128)) local_unnamed_addr #0 align 2

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 = { 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" }

!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, !11, i64 28}
!6 = !{!"_ZTSN4Poco10SHA1EngineE", !7, i64 0, !8, i64 8, !12, i64 104}
!7 = !{!"_ZTSN4Poco12DigestEngineE"}
!8 = !{!"_ZTSN4Poco10SHA1Engine7ContextE", !9, i64 0, !11, i64 20, !11, i64 24, !9, i64 28, !11, i64 92}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"_ZTSSt6vectorIhSaIhEE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !16, i64 0, !16, i64 8, !16, i64 16}
!16 = !{!"any pointer", !9, i64 0}
!17 = !{!6, !11, i64 32}
!18 = !{!6, !11, i64 100}
!19 = !{!9, !9, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass