; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; 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) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @XSHA256_FinalRaw(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  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 1, ptr %5) #4
  store i8 0, ptr %5, align 1, !tbaa !9
  br label %6

6:                                                ; preds = %23, %2
  %7 = load i8, ptr %5, align 1, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = icmp slt i32 %8, 8
  br i1 %9, label %10, label %26

10:                                               ; preds = %6
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.XSHA256, ptr %11, i32 0, i32 0
  %13 = load i8, ptr %5, align 1, !tbaa !9
  %14 = zext i8 %13 to i64
  %15 = getelementptr inbounds [8 x i32], ptr %12, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = call i32 @__bswap_32(i32 noundef %16)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.XSHA256, ptr %18, i32 0, i32 0
  %20 = load i8, ptr %5, align 1, !tbaa !9
  %21 = zext i8 %20 to i64
  %22 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 %21
  store i32 %17, ptr %22, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %10
  %24 = load i8, ptr %5, align 1, !tbaa !9
  %25 = add i8 %24, 1
  store i8 %25, ptr %5, align 1, !tbaa !9
  br label %6, !llvm.loop !10

26:                                               ; preds = %6
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.XSHA256, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds [32 x i8], ptr %29, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %27, ptr align 8 %30, i64 32, i1 false)
  store i8 0, ptr %5, align 1, !tbaa !9
  br label %31

31:                                               ; preds = %48, %26
  %32 = load i8, ptr %5, align 1, !tbaa !9
  %33 = zext i8 %32 to i32
  %34 = icmp slt i32 %33, 8
  br i1 %34, label %35, label %51

35:                                               ; preds = %31
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.XSHA256, ptr %36, i32 0, i32 0
  %38 = load i8, ptr %5, align 1, !tbaa !9
  %39 = zext i8 %38 to i64
  %40 = getelementptr inbounds [8 x i32], ptr %37, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = call i32 @__bswap_32(i32 noundef %41)
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.XSHA256, ptr %43, i32 0, i32 0
  %45 = load i8, ptr %5, align 1, !tbaa !9
  %46 = zext i8 %45 to i64
  %47 = getelementptr inbounds [8 x i32], ptr %44, i64 0, i64 %46
  store i32 %42, ptr %47, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %35
  %49 = load i8, ptr %5, align 1, !tbaa !9
  %50 = add i8 %49, 1
  store i8 %50, ptr %5, align 1, !tbaa !9
  br label %31, !llvm.loop !12

51:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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" }
attributes #3 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; 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 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) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @XSHA256_FinalRaw(ptr nocapture noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #2 {
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %4 = tail call i32 @__bswap_32(i32 noundef %3)
  store i32 %4, ptr %0, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = tail call i32 @__bswap_32(i32 noundef %6)
  store i32 %7, ptr %5, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = tail call i32 @__bswap_32(i32 noundef %9)
  store i32 %10, ptr %8, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = tail call i32 @__bswap_32(i32 noundef %12)
  store i32 %13, ptr %11, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = tail call i32 @__bswap_32(i32 noundef %15)
  store i32 %16, ptr %14, align 4, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 20
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = tail call i32 @__bswap_32(i32 noundef %18)
  store i32 %19, ptr %17, align 4, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = tail call i32 @__bswap_32(i32 noundef %21)
  store i32 %22, ptr %20, align 4, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %0, i64 28
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = tail call i32 @__bswap_32(i32 noundef %24)
  store i32 %25, ptr %23, align 4, !tbaa !5
  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)
  %26 = load i32, ptr %0, align 4, !tbaa !5
  %27 = tail call i32 @__bswap_32(i32 noundef %26)
  store i32 %27, ptr %0, align 4, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = tail call i32 @__bswap_32(i32 noundef %28)
  store i32 %29, ptr %5, align 4, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = tail call i32 @__bswap_32(i32 noundef %30)
  store i32 %31, ptr %8, align 4, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !5
  %33 = tail call i32 @__bswap_32(i32 noundef %32)
  store i32 %33, ptr %11, align 4, !tbaa !5
  %34 = load i32, ptr %14, align 4, !tbaa !5
  %35 = tail call i32 @__bswap_32(i32 noundef %34)
  store i32 %35, ptr %14, align 4, !tbaa !5
  %36 = load i32, ptr %17, align 4, !tbaa !5
  %37 = tail call i32 @__bswap_32(i32 noundef %36)
  store i32 %37, ptr %17, align 4, !tbaa !5
  %38 = load i32, ptr %20, align 4, !tbaa !5
  %39 = tail call i32 @__bswap_32(i32 noundef %38)
  store i32 %39, ptr %20, align 4, !tbaa !5
  %40 = load i32, ptr %23, align 4, !tbaa !5
  %41 = tail call i32 @__bswap_32(i32 noundef %40)
  store i32 %41, ptr %23, align 4, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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