; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/C (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.CSha256 = type { [8 x i32], i64, [64 x i8] }

; Function Attrs: nounwind uwtable
declare dso_local void @Sha256_Init(ptr 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @Sha256_Final(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  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 4, ptr %5) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.CSha256, ptr %10, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = trunc i64 %12 to i32
  %14 = and i32 %13, 63
  store i32 %14, ptr %5, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.CSha256, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %5, align 4, !tbaa !12
  %18 = add i32 %17, 1
  store i32 %18, ptr %5, align 4, !tbaa !12
  %19 = zext i32 %17 to i64
  %20 = getelementptr inbounds [64 x i8], ptr %16, i64 0, i64 %19
  store i8 -128, ptr %20, align 1, !tbaa !14
  br label %21

21:                                               ; preds = %31, %2
  %22 = load i32, ptr %5, align 4, !tbaa !12
  %23 = icmp ne i32 %22, 56
  br i1 %23, label %24, label %38

24:                                               ; preds = %21
  %25 = load i32, ptr %5, align 4, !tbaa !12
  %26 = and i32 %25, 63
  store i32 %26, ptr %5, align 4, !tbaa !12
  %27 = load i32, ptr %5, align 4, !tbaa !12
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %24
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  call void @Sha256_WriteByteBlock(ptr noundef %30)
  br label %31

31:                                               ; preds = %29, %24
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.CSha256, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %5, align 4, !tbaa !12
  %35 = add i32 %34, 1
  store i32 %35, ptr %5, align 4, !tbaa !12
  %36 = zext i32 %34 to i64
  %37 = getelementptr inbounds [64 x i8], ptr %33, i64 0, i64 %36
  store i8 0, ptr %37, align 1, !tbaa !14
  br label %21, !llvm.loop !15

38:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.CSha256, ptr %39, i32 0, i32 1
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = shl i64 %41, 3
  store i64 %42, ptr %7, align 8, !tbaa !17
  %43 = load i64, ptr %7, align 8, !tbaa !17
  %44 = lshr i64 %43, 32
  %45 = trunc i64 %44 to i32
  %46 = call i32 @llvm.bswap.i32(i32 %45)
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.CSha256, ptr %47, i32 0, i32 2
  %49 = getelementptr inbounds [64 x i8], ptr %48, i64 0, i64 0
  %50 = getelementptr inbounds i8, ptr %49, i64 64
  %51 = getelementptr inbounds i8, ptr %50, i64 -8
  store i32 %46, ptr %51, align 4, !tbaa !12
  %52 = load i64, ptr %7, align 8, !tbaa !17
  %53 = trunc i64 %52 to i32
  %54 = call i32 @llvm.bswap.i32(i32 %53)
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.CSha256, ptr %55, i32 0, i32 2
  %57 = getelementptr inbounds [64 x i8], ptr %56, i64 0, i64 0
  %58 = getelementptr inbounds i8, ptr %57, i64 64
  %59 = getelementptr inbounds i8, ptr %58, i64 -4
  store i32 %54, ptr %59, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  call void @Sha256_WriteByteBlock(ptr noundef %60)
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %61

61:                                               ; preds = %87, %38
  %62 = load i32, ptr %6, align 4, !tbaa !12
  %63 = icmp ult i32 %62, 8
  br i1 %63, label %64, label %90

64:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.CSha256, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %6, align 4, !tbaa !12
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds [8 x i32], ptr %66, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !12
  store i32 %70, ptr %8, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.CSha256, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %6, align 4, !tbaa !12
  %74 = add i32 %73, 1
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds [8 x i32], ptr %72, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !12
  store i32 %77, ptr %9, align 4, !tbaa !12
  %78 = load i32, ptr %8, align 4, !tbaa !12
  %79 = call i32 @llvm.bswap.i32(i32 %78)
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %79, ptr %80, align 4, !tbaa !12
  %81 = load i32, ptr %9, align 4, !tbaa !12
  %82 = call i32 @llvm.bswap.i32(i32 %81)
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds i8, ptr %83, i64 4
  store i32 %82, ptr %84, align 4, !tbaa !12
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds i8, ptr %85, i64 8
  store ptr %86, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %87

87:                                               ; preds = %64
  %88 = load i32, ptr %6, align 4, !tbaa !12
  %89 = add i32 %88, 2
  store i32 %89, ptr %6, align 4, !tbaa !12
  br label %61, !llvm.loop !18

90:                                               ; preds = %61
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  call void @Sha256_Init(ptr noundef %91)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.bswap.i32(i32) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !11, i64 32}
!10 = !{!"", !7, i64 0, !11, i64 32, !7, i64 40}
!11 = !{!"long long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !16}


; 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
declare dso_local void @Sha256_Init(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @Sha256_Final(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = trunc i64 %4 to i32
  %6 = and i32 %5, 63
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = and i64 %4, 63
  %9 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %8
  store i8 -128, ptr %9, align 1, !tbaa !10
  %.02628 = add nuw nsw i32 %6, 1
  %.not29 = icmp eq i32 %.02628, 56
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %13
  %.02630 = phi i32 [ %.026, %13 ], [ %.02628, %2 ]
  %10 = and i32 %.02630, 63
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %.lr.ph
  tail call void @Sha256_WriteByteBlock(ptr noundef nonnull %0)
  br label %13

13:                                               ; preds = %12, %.lr.ph
  %14 = zext nneg i32 %10 to i64
  %15 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %14
  store i8 0, ptr %15, align 1, !tbaa !10
  %.026 = add nuw nsw i32 %10, 1
  %.not = icmp eq i32 %.026, 56
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %13
  %.pre = load i64, ptr %3, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %16 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %4, %2 ]
  %17 = shl i64 %16, 3
  %18 = lshr i64 %17, 32
  %19 = trunc nuw i64 %18 to i32
  %20 = tail call i32 @llvm.bswap.i32(i32 %19)
  %21 = getelementptr inbounds i8, ptr %0, i64 96
  store i32 %20, ptr %21, align 4, !tbaa !13
  %22 = trunc i64 %17 to i32
  %23 = tail call i32 @llvm.bswap.i32(i32 %22)
  %24 = getelementptr inbounds i8, ptr %0, i64 100
  store i32 %23, ptr %24, align 4, !tbaa !13
  tail call void @Sha256_WriteByteBlock(ptr noundef nonnull %0)
  %25 = load i32, ptr %0, align 4, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %0, i64 4
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = tail call i32 @llvm.bswap.i32(i32 %25)
  store i32 %28, ptr %1, align 4, !tbaa !13
  %29 = tail call i32 @llvm.bswap.i32(i32 %27)
  %30 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %29, ptr %30, align 4, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %1, i64 8
  %32 = getelementptr inbounds i8, ptr %0, i64 8
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = getelementptr inbounds i8, ptr %0, i64 12
  %35 = load i32, ptr %34, align 4, !tbaa !13
  %36 = tail call i32 @llvm.bswap.i32(i32 %33)
  store i32 %36, ptr %31, align 4, !tbaa !13
  %37 = tail call i32 @llvm.bswap.i32(i32 %35)
  %38 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %37, ptr %38, align 4, !tbaa !13
  %39 = getelementptr inbounds i8, ptr %1, i64 16
  %40 = getelementptr inbounds i8, ptr %0, i64 16
  %41 = load i32, ptr %40, align 4, !tbaa !13
  %42 = getelementptr inbounds i8, ptr %0, i64 20
  %43 = load i32, ptr %42, align 4, !tbaa !13
  %44 = tail call i32 @llvm.bswap.i32(i32 %41)
  store i32 %44, ptr %39, align 4, !tbaa !13
  %45 = tail call i32 @llvm.bswap.i32(i32 %43)
  %46 = getelementptr inbounds i8, ptr %1, i64 20
  store i32 %45, ptr %46, align 4, !tbaa !13
  %47 = getelementptr inbounds i8, ptr %1, i64 24
  %48 = getelementptr inbounds i8, ptr %0, i64 24
  %49 = load i32, ptr %48, align 4, !tbaa !13
  %50 = getelementptr inbounds i8, ptr %0, i64 28
  %51 = load i32, ptr %50, align 4, !tbaa !13
  %52 = tail call i32 @llvm.bswap.i32(i32 %49)
  store i32 %52, ptr %47, align 4, !tbaa !13
  %53 = tail call i32 @llvm.bswap.i32(i32 %51)
  %54 = getelementptr inbounds i8, ptr %1, i64 28
  store i32 %53, ptr %54, align 4, !tbaa !13
  tail call void @Sha256_Init(ptr noundef nonnull %0)
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.bswap.i32(i32) #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 = { mustprogress 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 32}
!6 = !{!"", !7, i64 0, !9, i64 32, !7, i64 40}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long long", !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}


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