; LLVM IR from apache/kvrocks :: src/vendor/sha1.ll (Z10SHA1UpdateP8SHA1_CTXPKhj)

; 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.SHA1_CTX = type { [5 x i32], [2 x i32], [64 x i8] }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z13SHA1TransformPjPKh(ptr noundef, ptr noundef) #0

; 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 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z10SHA1UpdateP8SHA1_CTXPKhj(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.SHA1_CTX, ptr %9, i32 0, i32 1
  %11 = getelementptr inbounds [2 x i32], ptr %10, i64 0, i64 0
  %12 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %12, ptr %8, align 4, !tbaa !9
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = shl i32 %13, 3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.SHA1_CTX, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds [2 x i32], ptr %16, i64 0, i64 0
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = add i32 %18, %14
  store i32 %19, ptr %17, align 4, !tbaa !9
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp ult i32 %19, %20
  br i1 %21, label %22, label %28

22:                                               ; preds = %3
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.SHA1_CTX, ptr %23, i32 0, i32 1
  %25 = getelementptr inbounds [2 x i32], ptr %24, i64 0, i64 1
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = add i32 %26, 1
  store i32 %27, ptr %25, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %22, %3
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = lshr i32 %29, 29
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SHA1_CTX, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds [2 x i32], ptr %32, i64 0, i64 1
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = add i32 %34, %30
  store i32 %35, ptr %33, align 4, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = lshr i32 %36, 3
  %38 = and i32 %37, 63
  store i32 %38, ptr %8, align 4, !tbaa !9
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = add i32 %39, %40
  %42 = icmp ugt i32 %41, 63
  br i1 %42, label %43, label %76

43:                                               ; preds = %28
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.SHA1_CTX, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds [64 x i8], ptr %45, i64 0, i64 %47
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = sub i32 64, %50
  store i32 %51, ptr %7, align 4, !tbaa !9
  %52 = zext i32 %51 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %48, ptr align 1 %49, i64 %52, i1 false)
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.SHA1_CTX, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds [5 x i32], ptr %54, i64 0, i64 0
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.SHA1_CTX, ptr %56, i32 0, i32 2
  %58 = getelementptr inbounds [64 x i8], ptr %57, i64 0, i64 0
  call void @_Z13SHA1TransformPjPKh(ptr noundef %55, ptr noundef %58)
  br label %59

59:                                               ; preds = %72, %43
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = add i32 %60, 63
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = icmp ult i32 %61, %62
  br i1 %63, label %64, label %75

64:                                               ; preds = %59
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.SHA1_CTX, ptr %65, i32 0, i32 0
  %67 = getelementptr inbounds [5 x i32], ptr %66, i64 0, i64 0
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = zext i32 %69 to i64
  %71 = getelementptr inbounds i8, ptr %68, i64 %70
  call void @_Z13SHA1TransformPjPKh(ptr noundef %67, ptr noundef %71)
  br label %72

72:                                               ; preds = %64
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = add i32 %73, 64
  store i32 %74, ptr %7, align 4, !tbaa !9
  br label %59, !llvm.loop !11

75:                                               ; preds = %59
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %77

76:                                               ; preds = %28
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %76, %75
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.SHA1_CTX, ptr %78, i32 0, i32 2
  %80 = load i32, ptr %8, align 4, !tbaa !9
  %81 = zext i32 %80 to i64
  %82 = getelementptr inbounds [64 x i8], ptr %79, i64 0, i64 %81
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load i32, ptr %7, align 4, !tbaa !9
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds i8, ptr %83, i64 %85
  %87 = load i32, ptr %6, align 4, !tbaa !9
  %88 = load i32, ptr %7, align 4, !tbaa !9
  %89 = sub i32 %87, %88
  %90 = zext i32 %89 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %82, ptr align 1 %86, i64 %90, i1 false)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

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 = { 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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 void @_Z13SHA1TransformPjPKh(ptr noundef, ptr noundef) local_unnamed_addr #0

; 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: mustprogress nounwind uwtable
define dso_local void @_Z10SHA1UpdateP8SHA1_CTXPKhj(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
._crit_edge:
  %3 = getelementptr inbounds i8, ptr %0, i64 20
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = shl i32 %2, 3
  %6 = add i32 %4, %5
  store i32 %6, ptr %3, align 4, !tbaa !5
  %7 = icmp ult i32 %6, %4
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = zext i1 %7 to i32
  %11 = add i32 %9, %10
  %12 = lshr i32 %2, 29
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = add i32 %11, %12
  store i32 %14, ptr %13, align 4, !tbaa !5
  %15 = lshr i32 %4, 3
  %16 = and i32 %15, 63
  %17 = add i32 %16, %2
  %18 = icmp ugt i32 %17, 63
  br i1 %18, label %19, label %32

19:                                               ; preds = %._crit_edge
  %20 = getelementptr inbounds i8, ptr %0, i64 28
  %21 = zext nneg i32 %16 to i64
  %22 = getelementptr inbounds [64 x i8], ptr %20, i64 0, i64 %21
  %23 = sub nuw nsw i32 64, %16
  %24 = zext nneg i32 %23 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %22, ptr noundef nonnull align 1 dereferenceable(1) %1, i64 %24, i1 false)
  tail call void @_Z13SHA1TransformPjPKh(ptr noundef nonnull %0, ptr noundef nonnull %20)
  %25 = xor i32 %16, 127
  %26 = icmp ult i32 %25, %2
  br i1 %26, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %19, %.lr.ph
  %.02728 = phi i32 [ %29, %.lr.ph ], [ %23, %19 ]
  %27 = zext i32 %.02728 to i64
  %28 = getelementptr inbounds i8, ptr %1, i64 %27
  tail call void @_Z13SHA1TransformPjPKh(ptr noundef %0, ptr noundef %28)
  %29 = add i32 %.02728, 64
  %30 = add i32 %.02728, 127
  %31 = icmp ult i32 %30, %2
  br i1 %31, label %.lr.ph, label %.loopexit, !llvm.loop !9

32:                                               ; preds = %._crit_edge
  %33 = zext nneg i32 %16 to i64
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %19, %32
  %.1 = phi i32 [ 0, %32 ], [ %23, %19 ], [ %29, %.lr.ph ]
  %.0 = phi i64 [ %33, %32 ], [ 0, %19 ], [ 0, %.lr.ph ]
  %34 = getelementptr inbounds i8, ptr %0, i64 28
  %35 = getelementptr inbounds [64 x i8], ptr %34, i64 0, i64 %.0
  %36 = zext i32 %.1 to i64
  %37 = getelementptr inbounds i8, ptr %1, i64 %36
  %38 = sub i32 %2, %.1
  %39 = zext i32 %38 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %35, ptr align 1 %37, i64 %39, i1 false)
  ret void
}

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass