; 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] }

@XSHA256P = external hidden constant <{ i8, [63 x i8] }>, align 16

; Function Attrs: nounwind uwtable
declare dso_local void @XSHA256_Update(ptr noundef, ptr noundef, i64 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: 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

; Function Attrs: nounwind uwtable
define dso_local void @XSHA256_Final(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.XSHA256, ptr %8, i32 0, i32 3
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = icmp ult i64 %10, 56
  br i1 %11, label %12, label %17

12:                                               ; preds = %2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.XSHA256, ptr %13, i32 0, i32 3
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = sub i64 56, %15
  br label %22

17:                                               ; preds = %2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.XSHA256, ptr %18, i32 0, i32 3
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = sub i64 120, %20
  br label %22

22:                                               ; preds = %17, %12
  %23 = phi i64 [ %16, %12 ], [ %21, %17 ]
  store i64 %23, ptr %5, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.XSHA256, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !13
  %27 = mul i64 %26, 8
  store i64 %27, ptr %7, align 8, !tbaa !12
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load i64, ptr %5, align 8, !tbaa !12
  call void @XSHA256_Update(ptr noundef %28, ptr noundef @XSHA256P, i64 noundef %29)
  %30 = load i64, ptr %7, align 8, !tbaa !12
  %31 = lshr i64 %30, 32
  %32 = trunc i64 %31 to i32
  %33 = call i32 @__bswap_32(i32 noundef %32)
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.XSHA256, ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds [16 x i32], ptr %35, i64 0, i64 14
  store i32 %33, ptr %36, align 8, !tbaa !14
  %37 = load i64, ptr %7, align 8, !tbaa !12
  %38 = trunc i64 %37 to i32
  %39 = call i32 @__bswap_32(i32 noundef %38)
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.XSHA256, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds [16 x i32], ptr %41, i64 0, i64 15
  store i32 %39, ptr %42, align 4, !tbaa !14
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  call void @XSHA256_ProcessBlock(ptr noundef %43)
  store i64 0, ptr %6, align 8, !tbaa !12
  br label %44

44:                                               ; preds = %58, %22
  %45 = load i64, ptr %6, align 8, !tbaa !12
  %46 = icmp ult i64 %45, 8
  br i1 %46, label %47, label %61

47:                                               ; preds = %44
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.XSHA256, ptr %48, i32 0, i32 0
  %50 = load i64, ptr %6, align 8, !tbaa !12
  %51 = getelementptr inbounds [8 x i32], ptr %49, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !14
  %53 = call i32 @__bswap_32(i32 noundef %52)
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.XSHA256, ptr %54, i32 0, i32 0
  %56 = load i64, ptr %6, align 8, !tbaa !12
  %57 = getelementptr inbounds [8 x i32], ptr %55, i64 0, i64 %56
  store i32 %53, ptr %57, align 4, !tbaa !14
  br label %58

58:                                               ; preds = %47
  %59 = load i64, ptr %6, align 8, !tbaa !12
  %60 = add i64 %59, 1
  store i64 %60, ptr %6, align 8, !tbaa !12
  br label %44, !llvm.loop !15

61:                                               ; preds = %44
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %69

64:                                               ; preds = %61
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.XSHA256, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds [32 x i8], ptr %67, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %65, ptr align 8 %68, i64 32, i1 false)
  br label %69

69:                                               ; preds = %64, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 noundef) #3

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 = { inlinehint 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 #4 = { 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, !11, i64 104}
!10 = !{!"XSHA256", !7, i64 0, !7, i64 32, !11, i64 96, !11, i64 104}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 96}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@XSHA256P = external hidden constant <{ i8, [63 x i8] }>, align 16

; Function Attrs: nounwind uwtable
declare dso_local void @XSHA256_Update(ptr noundef, ptr noundef, i64 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: nounwind uwtable
declare dso_local void @XSHA256_ProcessBlock(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @XSHA256_Final(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 104
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp ult i64 %4, 56
  %. = select i1 %5, i64 56, i64 120
  %6 = sub i64 %., %4
  %7 = getelementptr inbounds i8, ptr %0, i64 96
  %8 = load i64, ptr %7, align 8, !tbaa !10
  %9 = shl i64 %8, 3
  tail call void @XSHA256_Update(ptr noundef %0, ptr noundef nonnull @XSHA256P, i64 noundef %6)
  %10 = lshr i64 %9, 32
  %11 = trunc nuw i64 %10 to i32
  %12 = tail call i32 @__bswap_32(i32 noundef %11)
  %13 = getelementptr inbounds i8, ptr %0, i64 88
  store i32 %12, ptr %13, align 8, !tbaa !11
  %14 = trunc i64 %9 to i32
  %15 = tail call i32 @__bswap_32(i32 noundef %14)
  %16 = getelementptr inbounds i8, ptr %0, i64 92
  store i32 %15, ptr %16, align 4, !tbaa !11
  tail call void @XSHA256_ProcessBlock(ptr noundef %0)
  %17 = load i32, ptr %0, align 4, !tbaa !11
  %18 = tail call i32 @__bswap_32(i32 noundef %17)
  store i32 %18, ptr %0, align 4, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = tail call i32 @__bswap_32(i32 noundef %20)
  store i32 %21, ptr %19, align 4, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = tail call i32 @__bswap_32(i32 noundef %23)
  store i32 %24, ptr %22, align 4, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %0, i64 12
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = tail call i32 @__bswap_32(i32 noundef %26)
  store i32 %27, ptr %25, align 4, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = tail call i32 @__bswap_32(i32 noundef %29)
  store i32 %30, ptr %28, align 4, !tbaa !11
  %31 = getelementptr inbounds i8, ptr %0, i64 20
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = tail call i32 @__bswap_32(i32 noundef %32)
  store i32 %33, ptr %31, align 4, !tbaa !11
  %34 = getelementptr inbounds i8, ptr %0, i64 24
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = tail call i32 @__bswap_32(i32 noundef %35)
  store i32 %36, ptr %34, align 4, !tbaa !11
  %37 = getelementptr inbounds i8, ptr %0, i64 28
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = tail call i32 @__bswap_32(i32 noundef %38)
  store i32 %39, ptr %37, align 4, !tbaa !11
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %41, label %40

40:                                               ; preds = %2
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(32) %0, i64 32, i1 false)
  br label %41

41:                                               ; preds = %40, %2
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 noundef) local_unnamed_addr #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 = { inlinehint 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 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 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass