; LLVM IR from vergecurrency/verge :: src/crypto/sha256.ll (Z9SHA256D64PhPKhm)

; 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"

@_ZN12_GLOBAL__N_117TransformD64_8wayE = external hidden global ptr, align 8
@_ZN12_GLOBAL__N_117TransformD64_4wayE = external hidden global ptr, align 8
@_ZN12_GLOBAL__N_112TransformD64E = external hidden global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9SHA256D64PhPKhm(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, 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
  %7 = load ptr, ptr @_ZN12_GLOBAL__N_117TransformD64_8wayE, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %24

9:                                                ; preds = %3
  br label %10

10:                                               ; preds = %13, %9
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = icmp uge i64 %11, 8
  br i1 %12, label %13, label %23

13:                                               ; preds = %10
  %14 = load ptr, ptr @_ZN12_GLOBAL__N_117TransformD64_8wayE, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  call void %14(ptr noundef %15, ptr noundef %16)
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 256
  store ptr %18, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 512
  store ptr %20, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = sub i64 %21, 8
  store i64 %22, ptr %6, align 8, !tbaa !9
  br label %10, !llvm.loop !11

23:                                               ; preds = %10
  br label %24

24:                                               ; preds = %23, %3
  %25 = load ptr, ptr @_ZN12_GLOBAL__N_117TransformD64_4wayE, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %42

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %31, %27
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = icmp uge i64 %29, 4
  br i1 %30, label %31, label %41

31:                                               ; preds = %28
  %32 = load ptr, ptr @_ZN12_GLOBAL__N_117TransformD64_4wayE, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  call void %32(ptr noundef %33, ptr noundef %34)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 128
  store ptr %36, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 256
  store ptr %38, ptr %5, align 8, !tbaa !5
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = sub i64 %39, 4
  store i64 %40, ptr %6, align 8, !tbaa !9
  br label %28, !llvm.loop !13

41:                                               ; preds = %28
  br label %42

42:                                               ; preds = %41, %24
  br label %43

43:                                               ; preds = %46, %42
  %44 = load i64, ptr %6, align 8, !tbaa !9
  %45 = icmp ne i64 %44, 0
  br i1 %45, label %46, label %56

46:                                               ; preds = %43
  %47 = load ptr, ptr @_ZN12_GLOBAL__N_112TransformD64E, align 8, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  call void %47(ptr noundef %48, ptr noundef %49)
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i64 32
  store ptr %51, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 64
  store ptr %53, ptr %5, align 8, !tbaa !5
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = add i64 %54, -1
  store i64 %55, ptr %6, align 8, !tbaa !9
  br label %43, !llvm.loop !14

56:                                               ; preds = %43
  ret void
}

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

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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"

@_ZN12_GLOBAL__N_117TransformD64_8wayE = external hidden local_unnamed_addr global ptr, align 8
@_ZN12_GLOBAL__N_117TransformD64_4wayE = external hidden local_unnamed_addr global ptr, align 8
@_ZN12_GLOBAL__N_112TransformD64E = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9SHA256D64PhPKhm(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr @_ZN12_GLOBAL__N_117TransformD64_8wayE, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  %6 = icmp ugt i64 %2, 7
  %or.cond = and i1 %6, %5
  br i1 %or.cond, label %.preheader36, label %.loopexit37

.preheader36:                                     ; preds = %3, %.preheader36
  %.028 = phi ptr [ %8, %.preheader36 ], [ %0, %3 ]
  %.023 = phi ptr [ %9, %.preheader36 ], [ %1, %3 ]
  %.0 = phi i64 [ %10, %.preheader36 ], [ %2, %3 ]
  %7 = load ptr, ptr @_ZN12_GLOBAL__N_117TransformD64_8wayE, align 8, !tbaa !5
  tail call void %7(ptr noundef %.028, ptr noundef %.023)
  %8 = getelementptr inbounds i8, ptr %.028, i64 256
  %9 = getelementptr inbounds i8, ptr %.023, i64 512
  %10 = add i64 %.0, -8
  %.old1 = icmp ugt i64 %10, 7
  br i1 %.old1, label %.preheader36, label %.loopexit37

.loopexit37:                                      ; preds = %.preheader36, %3
  %.129 = phi ptr [ %0, %3 ], [ %8, %.preheader36 ]
  %.124 = phi ptr [ %1, %3 ], [ %9, %.preheader36 ]
  %.1 = phi i64 [ %2, %3 ], [ %10, %.preheader36 ]
  %11 = load ptr, ptr @_ZN12_GLOBAL__N_117TransformD64_4wayE, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  %13 = icmp ugt i64 %.1, 3
  %or.cond4 = and i1 %13, %12
  br i1 %or.cond4, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %.loopexit37, %.preheader
  %.230 = phi ptr [ %15, %.preheader ], [ %.129, %.loopexit37 ]
  %.225 = phi ptr [ %16, %.preheader ], [ %.124, %.loopexit37 ]
  %.2 = phi i64 [ %17, %.preheader ], [ %.1, %.loopexit37 ]
  %14 = load ptr, ptr @_ZN12_GLOBAL__N_117TransformD64_4wayE, align 8, !tbaa !5
  tail call void %14(ptr noundef %.230, ptr noundef %.225)
  %15 = getelementptr inbounds i8, ptr %.230, i64 128
  %16 = getelementptr inbounds i8, ptr %.225, i64 256
  %17 = add i64 %.2, -4
  %.old3 = icmp ugt i64 %17, 3
  br i1 %.old3, label %.preheader, label %.loopexit

.loopexit:                                        ; preds = %.preheader, %.loopexit37
  %.331 = phi ptr [ %.129, %.loopexit37 ], [ %15, %.preheader ]
  %.326 = phi ptr [ %.124, %.loopexit37 ], [ %16, %.preheader ]
  %.3 = phi i64 [ %.1, %.loopexit37 ], [ %17, %.preheader ]
  %.not43 = icmp eq i64 %.3, 0
  br i1 %.not43, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.loopexit, %.lr.ph
  %.446 = phi i64 [ %21, %.lr.ph ], [ %.3, %.loopexit ]
  %.42745 = phi ptr [ %20, %.lr.ph ], [ %.326, %.loopexit ]
  %.43244 = phi ptr [ %19, %.lr.ph ], [ %.331, %.loopexit ]
  %18 = load ptr, ptr @_ZN12_GLOBAL__N_112TransformD64E, align 8, !tbaa !5
  tail call void %18(ptr noundef %.43244, ptr noundef %.42745)
  %19 = getelementptr inbounds i8, ptr %.43244, i64 32
  %20 = getelementptr inbounds i8, ptr %.42745, i64 64
  %21 = add i64 %.446, -1
  %.not = icmp eq i64 %21, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.loopexit
  ret void
}

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass