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

; 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
define dso_local void @SHA256Mini_Update(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %11, ptr %7, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %64, %3
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp ugt i64 %13, 0
  br i1 %14, label %15, label %79

15:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %16, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = and i64 %18, 63
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %8, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %21 = load i32, ptr %8, align 4, !tbaa !13
  %22 = sub i32 64, %21
  store i32 %22, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = load i32, ptr %9, align 4, !tbaa !13
  %25 = zext i32 %24 to i64
  %26 = icmp uge i64 %23, %25
  br i1 %26, label %27, label %53

27:                                               ; preds = %15
  %28 = load i32, ptr %8, align 4, !tbaa !13
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %35

30:                                               ; preds = %27
  %31 = load ptr, ptr %4, 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 %7, align 8, !tbaa !5
  call void @SHA256Mini_compress(ptr noundef %33, ptr noundef %34)
  br label %51

35:                                               ; preds = %27
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds [64 x i8], ptr %37, i64 0, i64 0
  %39 = load i32, ptr %8, align 4, !tbaa !13
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !13
  %44 = zext i32 %43 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %41, ptr align 1 %42, i64 %44, i1 false)
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %45, i32 0, i32 2
  %47 = getelementptr inbounds [8 x i32], ptr %46, i64 0, i64 0
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %48, i32 0, i32 1
  %50 = getelementptr inbounds [64 x i8], ptr %49, i64 0, i64 0
  call void @SHA256Mini_compress(ptr noundef %47, ptr noundef %50)
  br label %51

51:                                               ; preds = %35, %30
  %52 = load i32, ptr %9, align 4, !tbaa !13
  store i32 %52, ptr %10, align 4, !tbaa !13
  br label %64

53:                                               ; preds = %15
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %54, i32 0, i32 1
  %56 = getelementptr inbounds [64 x i8], ptr %55, i64 0, i64 0
  %57 = load i32, ptr %8, align 4, !tbaa !13
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %56, i64 %58
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %59, ptr align 1 %60, i64 %61, i1 false)
  %62 = load i64, ptr %6, align 8, !tbaa !9
  %63 = trunc i64 %62 to i32
  store i32 %63, ptr %10, align 4, !tbaa !13
  br label %64

64:                                               ; preds = %53, %51
  %65 = load i32, ptr %10, align 4, !tbaa !13
  %66 = zext i32 %65 to i64
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.SHA256Mini_ctx, ptr %67, i32 0, i32 0
  %69 = load i64, ptr %68, align 8, !tbaa !11
  %70 = add i64 %69, %66
  store i64 %70, ptr %68, align 8, !tbaa !11
  %71 = load i32, ptr %10, align 4, !tbaa !13
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = zext i32 %71 to i64
  %74 = getelementptr inbounds i8, ptr %72, i64 %73
  store ptr %74, ptr %7, align 8, !tbaa !5
  %75 = load i32, ptr %10, align 4, !tbaa !13
  %76 = zext i32 %75 to i64
  %77 = load i64, ptr %6, align 8, !tbaa !9
  %78 = sub i64 %77, %76
  store i64 %78, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %12, !llvm.loop !15

79:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @SHA256Mini_compress(ptr noundef, ptr noundef) #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

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: 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 0}
!12 = !{!"", !10, i64 0, !7, i64 8, !7, i64 72}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !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"

; Function Attrs: nounwind uwtable
define dso_local void @SHA256Mini_Update(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not31 = icmp eq i64 %2, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph

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

6:                                                ; preds = %.lr.ph, %22
  %7 = phi i64 [ %.pre, %.lr.ph ], [ %25, %22 ]
  %.02633 = phi i64 [ %2, %.lr.ph ], [ %27, %22 ]
  %.02732 = phi ptr [ %1, %.lr.ph ], [ %26, %22 ]
  %8 = trunc i64 %7 to i32
  %9 = and i32 %8, 63
  %10 = sub nuw nsw i32 64, %9
  %11 = zext nneg i32 %10 to i64
  %.not30 = icmp ult i64 %.02633, %11
  br i1 %.not30, label %18, label %12

12:                                               ; preds = %6
  %13 = icmp eq i32 %9, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %12
  tail call void @SHA256Mini_compress(ptr noundef nonnull %5, ptr noundef %.02732)
  br label %22

15:                                               ; preds = %12
  %16 = and i64 %7, 63
  %17 = getelementptr inbounds i8, ptr %4, i64 %16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %17, ptr noundef nonnull align 1 dereferenceable(1) %.02732, i64 %11, i1 false)
  tail call void @SHA256Mini_compress(ptr noundef nonnull %5, ptr noundef nonnull %4)
  br label %22

18:                                               ; preds = %6
  %19 = and i64 %7, 63
  %20 = getelementptr inbounds i8, ptr %4, i64 %19
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %20, ptr align 1 %.02732, i64 %.02633, i1 false)
  %21 = trunc nuw nsw i64 %.02633 to i32
  br label %22

22:                                               ; preds = %14, %15, %18
  %.0 = phi i32 [ %21, %18 ], [ %10, %15 ], [ 64, %14 ]
  %23 = zext nneg i32 %.0 to i64
  %24 = load i64, ptr %0, align 8, !tbaa !5
  %25 = add i64 %24, %23
  store i64 %25, ptr %0, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %.02732, i64 %23
  %27 = sub i64 %.02633, %23
  %.not = icmp eq i64 %27, 0
  br i1 %.not, label %._crit_edge, label %6, !llvm.loop !10

._crit_edge:                                      ; preds = %22, %3
  ret void
}

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

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) }

!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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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