; LLVM IR from jwerle/libhypercore-crypto :: deps/sha256 (sha256)

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

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

; Function Attrs: nounwind uwtable
define dso_local void @sha256_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.sha256_t, ptr %8, i32 0, i32 1
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %11 = trunc i64 %10 to i32
  %12 = and i32 %11, 63
  store i32 %12, ptr %7, align 4, !tbaa !13
  br label %13

13:                                               ; preds = %36, %3
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp ugt i64 %14, 0
  br i1 %15, label %16, label %37

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i32 1
  store ptr %18, ptr %5, align 8, !tbaa !5
  %19 = load i8, ptr %17, align 1, !tbaa !15
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.sha256_t, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %7, align 4, !tbaa !13
  %23 = add i32 %22, 1
  store i32 %23, ptr %7, align 4, !tbaa !13
  %24 = zext i32 %22 to i64
  %25 = getelementptr inbounds [64 x i8], ptr %21, i64 0, i64 %24
  store i8 %19, ptr %25, align 1, !tbaa !15
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.sha256_t, ptr %26, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !11
  %29 = add i64 %28, 1
  store i64 %29, ptr %27, align 8, !tbaa !11
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = add i64 %30, -1
  store i64 %31, ptr %6, align 8, !tbaa !9
  %32 = load i32, ptr %7, align 4, !tbaa !13
  %33 = icmp eq i32 %32, 64
  br i1 %33, label %34, label %36

34:                                               ; preds = %16
  store i32 0, ptr %7, align 4, !tbaa !13
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sha256_write_byte_block(ptr noundef %35)
  br label %36

36:                                               ; preds = %34, %16
  br label %13, !llvm.loop !16

37:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @sha256_write_byte_block(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"sha256_t", !7, i64 0, !10, i64 32, !7, i64 40}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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: nounwind uwtable
define dso_local void @sha256_update(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %.not11 = icmp eq i64 %2, 0
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = trunc i64 %5 to i32
  %7 = and i32 %6, 63
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  br label %9

9:                                                ; preds = %.lr.ph, %20
  %.014 = phi i32 [ %7, %.lr.ph ], [ %.1, %20 ]
  %.0813 = phi i64 [ %2, %.lr.ph ], [ %17, %20 ]
  %.0912 = phi ptr [ %1, %.lr.ph ], [ %10, %20 ]
  %10 = getelementptr inbounds i8, ptr %.0912, i64 1
  %11 = load i8, ptr %.0912, align 1, !tbaa !10
  %12 = add nuw nsw i32 %.014, 1
  %13 = zext nneg i32 %.014 to i64
  %14 = getelementptr inbounds [64 x i8], ptr %8, i64 0, i64 %13
  store i8 %11, ptr %14, align 1, !tbaa !10
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = add i64 %15, 1
  store i64 %16, ptr %4, align 8, !tbaa !5
  %17 = add i64 %.0813, -1
  %18 = icmp eq i32 %12, 64
  br i1 %18, label %19, label %20

19:                                               ; preds = %9
  tail call void @sha256_write_byte_block(ptr noundef nonnull %0)
  br label %20

20:                                               ; preds = %19, %9
  %.1 = phi i32 [ 0, %19 ], [ %12, %9 ]
  %.not = icmp eq i64 %17, 0
  br i1 %.not, label %._crit_edge, label %9, !llvm.loop !11

._crit_edge:                                      ; preds = %20, %3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @sha256_write_byte_block(ptr noundef) local_unnamed_addr #0

attributes #0 = { 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, !9, i64 32}
!6 = !{!"sha256_t", !7, i64 0, !9, i64 32, !7, i64 40}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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