; LLVM IR from kala13x/libxutils :: src/crypt (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.XSHA256 = type { %union.xsha256_digest_t, %union.xsha256_block_t, i64, i64 }
%union.xsha256_digest_t = type { [8 x i32] }
%union.xsha256_block_t = type { [16 x i32] }

; Function Attrs: nounwind uwtable
define dso_local void @XSHA256_Update(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
  %7 = 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
  br label %8

8:                                                ; preds = %60, %3
  %9 = load i64, ptr %6, align 8, !tbaa !9
  %10 = icmp ugt i64 %9, 0
  br i1 %10, label %11, label %61

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.XSHA256, ptr %13, i32 0, i32 3
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = sub i64 64, %15
  %17 = icmp ult i64 %12, %16
  br i1 %17, label %18, label %20

18:                                               ; preds = %11
  %19 = load i64, ptr %6, align 8, !tbaa !9
  br label %25

20:                                               ; preds = %11
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.XSHA256, ptr %21, i32 0, i32 3
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = sub i64 64, %23
  br label %25

25:                                               ; preds = %20, %18
  %26 = phi i64 [ %19, %18 ], [ %24, %20 ]
  store i64 %26, ptr %7, align 8, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.XSHA256, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds [64 x i8], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.XSHA256, ptr %30, i32 0, i32 3
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %29, i64 %32
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %33, ptr align 1 %34, i64 %35, i1 false)
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.XSHA256, ptr %37, i32 0, i32 2
  %39 = load i64, ptr %38, align 8, !tbaa !13
  %40 = add i64 %39, %36
  store i64 %40, ptr %38, align 8, !tbaa !13
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.XSHA256, ptr %42, i32 0, i32 3
  %44 = load i64, ptr %43, align 8, !tbaa !11
  %45 = add i64 %44, %41
  store i64 %45, ptr %43, align 8, !tbaa !11
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  store ptr %48, ptr %5, align 8, !tbaa !5
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = sub i64 %50, %49
  store i64 %51, ptr %6, align 8, !tbaa !9
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.XSHA256, ptr %52, i32 0, i32 3
  %54 = load i64, ptr %53, align 8, !tbaa !11
  %55 = icmp eq i64 %54, 64
  br i1 %55, label %56, label %60

56:                                               ; preds = %25
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  call void @XSHA256_ProcessBlock(ptr noundef %57)
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.XSHA256, ptr %58, i32 0, i32 3
  store i64 0, ptr %59, align 8, !tbaa !11
  br label %60

60:                                               ; preds = %56, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %8, !llvm.loop !14

61:                                               ; preds = %8
  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: 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: nounwind uwtable
declare dso_local void @XSHA256_ProcessBlock(ptr noundef) #0

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

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" }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 104}
!12 = !{!"XSHA256", !7, i64 0, !7, i64 32, !10, i64 96, !10, i64 104}
!13 = !{!12, !10, i64 96}
!14 = distinct !{!14, !15}
!15 = !{!"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 @XSHA256_Update(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not21 = icmp eq i64 %2, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %4 = getelementptr inbounds i8, ptr %0, i64 104
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = getelementptr inbounds i8, ptr %0, i64 96
  %.pre = load i64, ptr %4, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %.lr.ph, %19
  %8 = phi i64 [ %.pre, %.lr.ph ], [ %20, %19 ]
  %.023 = phi ptr [ %1, %.lr.ph ], [ %15, %19 ]
  %.01922 = phi i64 [ %2, %.lr.ph ], [ %16, %19 ]
  %9 = sub i64 64, %8
  %.019. = tail call i64 @llvm.umin.i64(i64 %.01922, i64 %9)
  %10 = getelementptr inbounds i8, ptr %5, i64 %8
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %10, ptr align 1 %.023, i64 %.019., i1 false)
  %11 = load i64, ptr %6, align 8, !tbaa !10
  %12 = add i64 %11, %.019.
  store i64 %12, ptr %6, align 8, !tbaa !10
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = add i64 %13, %.019.
  store i64 %14, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.023, i64 %.019.
  %16 = sub i64 %.01922, %.019.
  %17 = icmp eq i64 %14, 64
  br i1 %17, label %18, label %19

18:                                               ; preds = %7
  tail call void @XSHA256_ProcessBlock(ptr noundef nonnull %0)
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %18, %7
  %20 = phi i64 [ 0, %18 ], [ %14, %7 ]
  %.not = icmp eq i64 %16, 0
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !11

._crit_edge:                                      ; preds = %19, %3
  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: nounwind uwtable
declare dso_local void @XSHA256_ProcessBlock(ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #2

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


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