; LLVM IR from begeekmyfriend/CuckooFilter :: mozilla-sha1 (sha1)

; 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.SHA_CTX = type { [5 x i32], [80 x i32], i32, i32, 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 @SHA1_Update(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %9, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %65, %3
  %11 = load i32, ptr %8, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %68

14:                                               ; preds = %10
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.SHA_CTX, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.SHA_CTX, ptr %17, i32 0, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = sdiv i32 %19, 4
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [80 x i32], ptr %16, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = shl i32 %23, 8
  store i32 %24, ptr %22, align 4, !tbaa !9
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !13
  %30 = zext i8 %29 to i32
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SHA_CTX, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.SHA_CTX, ptr %33, i32 0, i32 2
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = sdiv i32 %35, 4
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [80 x i32], ptr %32, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = or i32 %39, %30
  store i32 %40, ptr %38, align 4, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.SHA_CTX, ptr %41, i32 0, i32 2
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %42, align 4, !tbaa !11
  %45 = srem i32 %44, 64
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %47, label %51

47:                                               ; preds = %14
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  call void @shaHashBlock(ptr noundef %48)
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.SHA_CTX, ptr %49, i32 0, i32 2
  store i32 0, ptr %50, align 4, !tbaa !11
  br label %51

51:                                               ; preds = %47, %14
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.SHA_CTX, ptr %52, i32 0, i32 4
  %54 = load i32, ptr %53, align 4, !tbaa !14
  %55 = add i32 %54, 8
  store i32 %55, ptr %53, align 4, !tbaa !14
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.SHA_CTX, ptr %56, i32 0, i32 4
  %58 = load i32, ptr %57, align 4, !tbaa !14
  %59 = icmp ult i32 %58, 8
  %60 = zext i1 %59 to i32
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.SHA_CTX, ptr %61, i32 0, i32 3
  %63 = load i32, ptr %62, align 4, !tbaa !15
  %64 = add i32 %63, %60
  store i32 %64, ptr %62, align 4, !tbaa !15
  br label %65

65:                                               ; preds = %51
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %8, align 4, !tbaa !9
  br label %10, !llvm.loop !16

68:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @shaHashBlock(ptr 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 340}
!12 = !{!"", !7, i64 0, !7, i64 20, !10, i64 340, !10, i64 344, !10, i64 348}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !10, i64 348}
!15 = !{!12, !10, i64 344}
!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"

; Function Attrs: nounwind uwtable
define dso_local void @SHA1_Update(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %2, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  %6 = getelementptr inbounds i8, ptr %0, i64 340
  %7 = getelementptr inbounds i8, ptr %0, i64 348
  %8 = getelementptr inbounds i8, ptr %0, i64 344
  %wide.trip.count = zext nneg i32 %2 to i64
  %.pre = load i32, ptr %6, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %.lr.ph, %30
  %10 = phi i32 [ %.pre, %.lr.ph ], [ %31, %30 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %30 ]
  %11 = sdiv i32 %10, 4
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [80 x i32], ptr %5, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !10
  %15 = shl i32 %14, 8
  store i32 %15, ptr %13, align 4, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = sdiv i32 %19, 4
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [80 x i32], ptr %5, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !10
  %24 = or i32 %23, %18
  store i32 %24, ptr %22, align 4, !tbaa !10
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %6, align 4, !tbaa !5
  %27 = and i32 %26, 63
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %9
  tail call void @shaHashBlock(ptr noundef nonnull %0)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %29, %9
  %31 = phi i32 [ 0, %29 ], [ %26, %9 ]
  %32 = load i32, ptr %7, align 4, !tbaa !12
  %33 = add i32 %32, 8
  store i32 %33, ptr %7, align 4, !tbaa !12
  %34 = icmp ugt i32 %32, -9
  %35 = zext i1 %34 to i32
  %36 = load i32, ptr %8, align 4, !tbaa !13
  %37 = add i32 %36, %35
  store i32 %37, ptr %8, align 4, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %9, !llvm.loop !14

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

; Function Attrs: nounwind uwtable
declare hidden void @shaHashBlock(ptr 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" }

!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 340}
!6 = !{!"", !7, i64 0, !7, i64 20, !9, i64 340, !9, i64 344, !9, i64 348}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!9, !9, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !9, i64 348}
!13 = !{!6, !9, i64 344}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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