; LLVM IR from intel/cryptography-primitives :: sources/ippcp/hash/sha1 (pcpsha1ca)

; 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"

@sha1_cnt = external hidden constant [4 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local void @cpFinalizeSHA1(ptr noundef %0, ptr noundef %1, i32 noundef %2, i64 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca [128 x i8], align 16
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store ptr @UpdateSHA1, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 128, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 56
  %14 = zext i1 %13 to i64
  %15 = select i1 %13, i32 64, i32 128
  store i32 %15, ptr %11, align 4, !tbaa !9
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 0
  %18 = load i32, ptr %7, align 4, !tbaa !9
  call void @CopyBlock(ptr noundef %16, ptr noundef %17, i32 noundef %18)
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %7, align 4, !tbaa !9
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 %21
  store i8 -128, ptr %22, align 1, !tbaa !13
  %23 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 0
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = load i32, ptr %11, align 4, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = sub nsw i32 %27, %28
  %30 = sub nsw i32 %29, 8
  call void @PadBlock(i8 noundef zeroext 0, ptr noundef %26, i32 noundef %30)
  %31 = load i64, ptr %8, align 8, !tbaa !11
  %32 = shl i64 %31, 3
  %33 = lshr i64 %32, 32
  %34 = and i64 %33, 4294967295
  %35 = trunc i64 %34 to i32
  %36 = lshr i32 %35, 24
  %37 = load i64, ptr %8, align 8, !tbaa !11
  %38 = shl i64 %37, 3
  %39 = lshr i64 %38, 32
  %40 = and i64 %39, 4294967295
  %41 = trunc i64 %40 to i32
  %42 = shl i32 %41, 8
  %43 = or i32 %36, %42
  %44 = and i32 %43, 16711935
  %45 = load i64, ptr %8, align 8, !tbaa !11
  %46 = shl i64 %45, 3
  %47 = lshr i64 %46, 32
  %48 = and i64 %47, 4294967295
  %49 = trunc i64 %48 to i32
  %50 = lshr i32 %49, 8
  %51 = load i64, ptr %8, align 8, !tbaa !11
  %52 = shl i64 %51, 3
  %53 = lshr i64 %52, 32
  %54 = and i64 %53, 4294967295
  %55 = trunc i64 %54 to i32
  %56 = shl i32 %55, 24
  %57 = or i32 %50, %56
  %58 = and i32 %57, -16711936
  %59 = or i32 %44, %58
  %60 = zext i32 %59 to i64
  %61 = load i64, ptr %8, align 8, !tbaa !11
  %62 = shl i64 %61, 3
  %63 = trunc i64 %62 to i32
  %64 = lshr i32 %63, 24
  %65 = load i64, ptr %8, align 8, !tbaa !11
  %66 = shl i64 %65, 3
  %67 = trunc i64 %66 to i32
  %68 = shl i32 %67, 8
  %69 = or i32 %64, %68
  %70 = and i32 %69, 16711935
  %71 = load i64, ptr %8, align 8, !tbaa !11
  %72 = shl i64 %71, 3
  %73 = trunc i64 %72 to i32
  %74 = lshr i32 %73, 8
  %75 = load i64, ptr %8, align 8, !tbaa !11
  %76 = shl i64 %75, 3
  %77 = trunc i64 %76 to i32
  %78 = shl i32 %77, 24
  %79 = or i32 %74, %78
  %80 = and i32 %79, -16711936
  %81 = or i32 %70, %80
  %82 = zext i32 %81 to i64
  %83 = shl i64 %82, 32
  %84 = or i64 %60, %83
  store i64 %84, ptr %8, align 8, !tbaa !11
  %85 = load i64, ptr %8, align 8, !tbaa !11
  %86 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 0
  %87 = load i32, ptr %11, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds i8, ptr %86, i64 %88
  %90 = getelementptr inbounds i64, ptr %89, i64 -1
  store i64 %85, ptr %90, align 8, !tbaa !11
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 0
  %94 = load i32, ptr %11, align 4, !tbaa !9
  call void %91(ptr noundef %92, ptr noundef %93, i32 noundef %94, ptr noundef @sha1_cnt)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

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

declare void @UpdateSHA1(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CopyBlock(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @PadBlock(i8 noundef zeroext, ptr noundef, i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!7, !7, i64 0}


; 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"

@sha1_cnt = external hidden constant [4 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local void @cpFinalizeSHA1(ptr noundef %0, ptr noundef %1, i32 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca [128 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %5) #5
  %6 = icmp slt i32 %2, 56
  %7 = select i1 %6, i32 64, i32 128
  call void @CopyBlock(ptr noundef %1, ptr noundef nonnull %5, i32 noundef %2)
  %8 = sext i32 %2 to i64
  %9 = getelementptr inbounds [128 x i8], ptr %5, i64 0, i64 %8
  store i8 -128, ptr %9, align 1, !tbaa !5
  %10 = sext i32 %2 to i64
  %11 = getelementptr i8, ptr %5, i64 %10
  %12 = getelementptr i8, ptr %11, i64 1
  %reass.sub = sub i32 %7, %2
  %13 = add i32 %reass.sub, -9
  call void @PadBlock(i8 noundef zeroext 0, ptr noundef nonnull %12, i32 noundef %13)
  %14 = shl i64 %3, 3
  %15 = lshr i64 %14, 32
  %16 = trunc nuw i64 %15 to i32
  %17 = call i32 @llvm.fshl.i32(i32 %16, i32 %16, i32 8)
  %18 = and i32 %17, 16711935
  %19 = call i32 @llvm.fshl.i32(i32 %16, i32 %16, i32 24)
  %20 = and i32 %19, -16711936
  %21 = or disjoint i32 %18, %20
  %22 = zext i32 %21 to i64
  %23 = trunc i64 %14 to i32
  %24 = call i32 @llvm.fshl.i32(i32 %23, i32 %23, i32 8)
  %25 = and i32 %24, 16711935
  %26 = call i32 @llvm.fshl.i32(i32 %23, i32 %23, i32 24)
  %27 = and i32 %26, -134152448
  %28 = or disjoint i32 %25, %27
  %29 = zext i32 %28 to i64
  %30 = shl nuw i64 %29, 32
  %31 = or disjoint i64 %30, %22
  %32 = zext nneg i32 %7 to i64
  %33 = getelementptr inbounds i8, ptr %5, i64 %32
  %34 = getelementptr inbounds i8, ptr %33, i64 -8
  store i64 %31, ptr %34, align 8, !tbaa !8
  call void @UpdateSHA1(ptr noundef %0, ptr noundef nonnull %5, i32 noundef %7, ptr noundef nonnull @sha1_cnt) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %5) #5
  ret void
}

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

declare void @UpdateSHA1(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CopyBlock(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @PadBlock(i8 noundef zeroext, ptr noundef, i32 noundef) local_unnamed_addr #3

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, i32) #4

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 willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass