; LLVM IR from IanHarvey/minicrypt :: src (sha2_mini)

; 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.SHA256Mini_ctx = type { i64, [64 x i8], [8 x i32] }

@.str = external hidden unnamed_addr constant [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.SHA256Mini_Final = external hidden unnamed_addr constant [51 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden void @SHA256Mini_compress(ptr noundef, ptr noundef) #1

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

21:                                               ; preds = %2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds [64 x i8], ptr %23, i64 0, i64 0
  %25 = load i32, ptr %5, align 4, !tbaa !12
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  %28 = load i32, ptr %5, align 4, !tbaa !12
  %29 = sub i32 64, %28
  %30 = zext i32 %29 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %27, i8 0, i64 %30, i1 false)
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %31, i32 0, i32 2
  %33 = getelementptr inbounds [8 x i32], ptr %32, i64 0, i64 0
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds [64 x i8], ptr %35, i64 0, i64 0
  call void @SHA256Mini_compress(ptr noundef %33, ptr noundef %36)
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %37

37:                                               ; preds = %21, %2
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %38, i32 0, i32 1
  %40 = getelementptr inbounds [64 x i8], ptr %39, i64 0, i64 0
  %41 = load i32, ptr %5, align 4, !tbaa !12
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = load i32, ptr %5, align 4, !tbaa !12
  %45 = sub i32 64, %44
  %46 = zext i32 %45 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %43, i8 0, i64 %46, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %47, i32 0, i32 0
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = shl i64 %49, 3
  store i64 %50, ptr %6, align 8, !tbaa !15
  %51 = load i64, ptr %6, align 8, !tbaa !15
  %52 = lshr i64 %51, 3
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %53, i32 0, i32 0
  %55 = load i64, ptr %54, align 8, !tbaa !9
  %56 = icmp eq i64 %52, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %37
  br label %59

58:                                               ; preds = %37
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 180, ptr noundef @__PRETTY_FUNCTION__.SHA256Mini_Final) #5
  unreachable

59:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %60, i32 0, i32 1
  %62 = getelementptr inbounds [64 x i8], ptr %61, i64 0, i64 0
  %63 = getelementptr inbounds i8, ptr %62, i64 63
  store ptr %63, ptr %7, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %67, %59
  %65 = load i64, ptr %6, align 8, !tbaa !15
  %66 = icmp ugt i64 %65, 0
  br i1 %66, label %67, label %75

67:                                               ; preds = %64
  %68 = load i64, ptr %6, align 8, !tbaa !15
  %69 = and i64 %68, 255
  %70 = trunc i64 %69 to i8
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i32 -1
  store ptr %72, ptr %7, align 8, !tbaa !5
  store i8 %70, ptr %71, align 1, !tbaa !14
  %73 = load i64, ptr %6, align 8, !tbaa !15
  %74 = lshr i64 %73, 8
  store i64 %74, ptr %6, align 8, !tbaa !15
  br label %64, !llvm.loop !16

75:                                               ; preds = %64
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %76, i32 0, i32 2
  %78 = getelementptr inbounds [8 x i32], ptr %77, i64 0, i64 0
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %79, i32 0, i32 1
  %81 = getelementptr inbounds [64 x i8], ptr %80, i64 0, i64 0
  call void @SHA256Mini_compress(ptr noundef %78, ptr noundef %81)
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %82, i32 0, i32 2
  %84 = getelementptr inbounds [8 x i32], ptr %83, i64 0, i64 0
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  call void @put_BE32(ptr noundef %84, ptr noundef %85, i32 noundef 8)
  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 4, ptr %5) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @put_BE32(ptr noundef, ptr noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { noreturn nounwind "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 }
attributes #5 = { noreturn 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 0}
!10 = !{!"", !11, i64 0, !7, i64 8, !7, i64 72}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.str = external hidden unnamed_addr constant [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.SHA256Mini_Final = external hidden unnamed_addr constant [51 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @SHA256Mini_Final(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i64, ptr %0, align 8, !tbaa !5
  %4 = trunc i64 %3 to i32
  %5 = and i32 %4, 63
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = add nuw nsw i32 %5, 1
  %8 = and i64 %3, 63
  %9 = getelementptr inbounds [64 x i8], ptr %6, i64 0, i64 %8
  store i8 -128, ptr %9, align 1, !tbaa !10
  %10 = icmp ugt i32 %5, 55
  br i1 %10, label %11, label %17

11:                                               ; preds = %2
  %12 = zext nneg i32 %7 to i64
  %13 = getelementptr inbounds i8, ptr %6, i64 %12
  %14 = xor i32 %5, 63
  %15 = zext nneg i32 %14 to i64
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %13, i8 0, i64 %15, i1 false)
  %16 = getelementptr inbounds i8, ptr %0, i64 72
  tail call void @SHA256Mini_compress(ptr noundef nonnull %16, ptr noundef nonnull %6)
  br label %17

17:                                               ; preds = %11, %2
  %.024 = phi i32 [ 0, %11 ], [ %7, %2 ]
  %18 = zext nneg i32 %.024 to i64
  %19 = getelementptr inbounds i8, ptr %6, i64 %18
  %20 = sub nuw nsw i32 64, %.024
  %21 = zext nneg i32 %20 to i64
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %19, i8 0, i64 %21, i1 false)
  %22 = load i64, ptr %0, align 8, !tbaa !5
  %23 = icmp ult i64 %22, 2305843009213693952
  br i1 %23, label %25, label %24

24:                                               ; preds = %17
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 180, ptr noundef nonnull @__PRETTY_FUNCTION__.SHA256Mini_Final) #3
  unreachable

25:                                               ; preds = %17
  %.not26 = icmp eq i64 %22, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %25
  %26 = getelementptr inbounds i8, ptr %0, i64 71
  %27 = shl nuw i64 %22, 3
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.028 = phi ptr [ %29, %.lr.ph ], [ %26, %.lr.ph.preheader ]
  %.02327 = phi i64 [ %30, %.lr.ph ], [ %27, %.lr.ph.preheader ]
  %28 = trunc i64 %.02327 to i8
  %29 = getelementptr inbounds i8, ptr %.028, i64 -1
  store i8 %28, ptr %.028, align 1, !tbaa !10
  %30 = lshr i64 %.02327, 8
  %.not = icmp ult i64 %.02327, 256
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %25
  %31 = getelementptr inbounds i8, ptr %0, i64 72
  tail call void @SHA256Mini_compress(ptr noundef nonnull %31, ptr noundef nonnull %6)
  tail call void @put_BE32(ptr noundef nonnull %31, ptr noundef %1, i32 noundef 8)
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

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: write) }
attributes #2 = { noreturn nounwind "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 = { noreturn 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !8, i64 8, !8, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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