; LLVM IR from xunil-cloud/CloudReverb :: audio_engine/Utils/Sha256.ll (ZN6SHA2566updateEPKhj)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6SHA2569transformEPKhj(ptr noundef nonnull align 4 dereferenceable(168), ptr noundef, i32 noundef) #0 align 2

; 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 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 @_ZN6SHA2566updateEPKhj(ptr noundef nonnull align 4 dereferenceable(168) %0, ptr noundef %1, i32 noundef %2) #0 align 2 {
  %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
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = 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
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %14 = getelementptr inbounds %class.SHA256, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = sub i32 64, %15
  store i32 %16, ptr %10, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr %10, align 4, !tbaa !9
  %19 = icmp ult i32 %17, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %3
  %21 = load i32, ptr %6, align 4, !tbaa !9
  br label %24

22:                                               ; preds = %3
  %23 = load i32, ptr %10, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %22, %20
  %25 = phi i32 [ %21, %20 ], [ %23, %22 ]
  store i32 %25, ptr %9, align 4, !tbaa !9
  %26 = getelementptr inbounds %class.SHA256, ptr %13, i32 0, i32 2
  %27 = getelementptr inbounds %class.SHA256, ptr %13, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds [128 x i8], ptr %26, i64 0, i64 %29
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %30, ptr align 1 %31, i64 %33, i1 false)
  %34 = getelementptr inbounds %class.SHA256, ptr %13, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = add i32 %35, %36
  %38 = icmp ult i32 %37, 64
  br i1 %38, label %39, label %44

39:                                               ; preds = %24
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = getelementptr inbounds %class.SHA256, ptr %13, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = add i32 %42, %40
  store i32 %43, ptr %41, align 4, !tbaa !11
  store i32 1, ptr %12, align 4
  br label %77

44:                                               ; preds = %24
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = sub i32 %45, %46
  store i32 %47, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = udiv i32 %48, 64
  store i32 %49, ptr %7, align 4, !tbaa !9
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  store ptr %53, ptr %11, align 8, !tbaa !5
  %54 = getelementptr inbounds %class.SHA256, ptr %13, i32 0, i32 2
  %55 = getelementptr inbounds [128 x i8], ptr %54, i64 0, i64 0
  call void @_ZN6SHA2569transformEPKhj(ptr noundef nonnull align 4 dereferenceable(168) %13, ptr noundef %55, i32 noundef 1)
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load i32, ptr %7, align 4, !tbaa !9
  call void @_ZN6SHA2569transformEPKhj(ptr noundef nonnull align 4 dereferenceable(168) %13, ptr noundef %56, i32 noundef %57)
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = urem i32 %58, 64
  store i32 %59, ptr %9, align 4, !tbaa !9
  %60 = getelementptr inbounds %class.SHA256, ptr %13, i32 0, i32 2
  %61 = getelementptr inbounds [128 x i8], ptr %60, i64 0, i64 0
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = shl i32 %63, 6
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %62, i64 %65
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = zext i32 %67 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %61, ptr align 1 %66, i64 %68, i1 false)
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = getelementptr inbounds %class.SHA256, ptr %13, i32 0, i32 1
  store i32 %69, ptr %70, align 4, !tbaa !11
  %71 = load i32, ptr %7, align 4, !tbaa !9
  %72 = add i32 %71, 1
  %73 = shl i32 %72, 6
  %74 = getelementptr inbounds %class.SHA256, ptr %13, i32 0, i32 0
  %75 = load i32, ptr %74, align 4, !tbaa !13
  %76 = add i32 %75, %73
  store i32 %76, ptr %74, align 4, !tbaa !13
  store i32 0, ptr %12, align 4
  br label %77

77:                                               ; preds = %44, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %78 = load i32, ptr %12, align 4
  switch i32 %78, label %80 [
    i32 0, label %79
    i32 1, label %79
  ]

79:                                               ; preds = %77, %77
  ret void

80:                                               ; preds = %77
  unreachable
}

; 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

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 = !{!12, !10, i64 4}
!12 = !{!"_ZTS6SHA256", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 136}
!13 = !{!12, !10, 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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6SHA2569transformEPKhj(ptr noundef nonnull align 4 dereferenceable(168), ptr noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6SHA2566updateEPKhj(ptr noundef nonnull align 4 dereferenceable(168) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sub i32 64, %5
  %7 = tail call i32 @llvm.umin.i32(i32 %6, i32 %2)
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = zext i32 %5 to i64
  %10 = getelementptr inbounds [128 x i8], ptr %8, i64 0, i64 %9
  %11 = zext i32 %7 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %10, ptr align 1 %1, i64 %11, i1 false)
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = add i32 %12, %2
  %14 = icmp ult i32 %13, 64
  br i1 %14, label %27, label %15

15:                                               ; preds = %3
  %16 = sub i32 %2, %7
  %17 = lshr i32 %16, 6
  %18 = getelementptr inbounds i8, ptr %1, i64 %11
  tail call void @_ZN6SHA2569transformEPKhj(ptr noundef nonnull align 4 dereferenceable(168) %0, ptr noundef nonnull %8, i32 noundef 1)
  tail call void @_ZN6SHA2569transformEPKhj(ptr noundef nonnull align 4 dereferenceable(168) %0, ptr noundef %18, i32 noundef %17)
  %19 = and i32 %16, 63
  %20 = and i32 %16, -64
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %18, i64 %21
  %23 = zext nneg i32 %19 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %8, ptr align 1 %22, i64 %23, i1 false)
  %24 = add i32 %20, 64
  %25 = load i32, ptr %0, align 4, !tbaa !10
  %26 = add i32 %24, %25
  store i32 %26, ptr %0, align 4, !tbaa !10
  br label %27

27:                                               ; preds = %3, %15
  %.sink = phi i32 [ %19, %15 ], [ %13, %3 ]
  store i32 %.sink, ptr %4, align 4
  ret void
}

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !7, i64 4}
!6 = !{!"_ZTS6SHA256", !7, i64 0, !7, i64 4, !8, i64 8, !8, i64 136}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass