; LLVM IR from intel/cryptography-primitives :: sources/ippcp/hash/md5 (pcpmd5ca)

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

@MD5_cnt = external constant [0 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local void @cpFinalizeMD5(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 [128 x i8], align 16
  %10 = 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 128, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 56
  %13 = zext i1 %12 to i64
  %14 = select i1 %12, i32 64, i32 128
  store i32 %14, ptr %10, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds [128 x i8], ptr %9, i64 0, i64 0
  %17 = load i32, ptr %7, align 4, !tbaa !9
  call void @CopyBlock(ptr noundef %15, ptr noundef %16, i32 noundef %17)
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %7, align 4, !tbaa !9
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds [128 x i8], ptr %9, i64 0, i64 %20
  store i8 -128, ptr %21, align 1, !tbaa !13
  %22 = getelementptr inbounds [128 x i8], ptr %9, i64 0, i64 0
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %22, i64 %24
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = sub nsw i32 %26, %27
  %29 = sub nsw i32 %28, 8
  call void @PadBlock(i8 noundef zeroext 0, ptr noundef %25, i32 noundef %29)
  %30 = load i64, ptr %8, align 8, !tbaa !11
  %31 = shl i64 %30, 3
  store i64 %31, ptr %8, align 8, !tbaa !11
  %32 = load i64, ptr %8, align 8, !tbaa !11
  %33 = getelementptr inbounds [128 x i8], ptr %9, i64 0, i64 0
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  %37 = getelementptr inbounds i64, ptr %36, i64 -1
  store i64 %32, ptr %37, align 8, !tbaa !11
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds [128 x i8], ptr %9, i64 0, i64 0
  %40 = load i32, ptr %10, align 4, !tbaa !9
  call void @UpdateMD5(ptr noundef %38, ptr noundef %39, i32 noundef %40, ptr noundef @MD5_cnt)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 128, 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

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

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

declare void @UpdateMD5(ptr noundef, ptr noundef, i32 noundef, ptr 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 = { 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 #3 = { "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"

@MD5_cnt = external constant [0 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local void @cpFinalizeMD5(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) #4
  %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 = zext nneg i32 %7 to i64
  %16 = getelementptr inbounds i8, ptr %5, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 -8
  store i64 %14, ptr %17, align 8, !tbaa !8
  call void @UpdateMD5(ptr noundef %0, ptr noundef nonnull %5, i32 noundef %7, ptr noundef nonnull @MD5_cnt) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %5) #4
  ret void
}

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

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

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

declare void @UpdateMD5(ptr noundef, ptr noundef, i32 noundef, ptr 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

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 = { 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 #3 = { "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 = !{!"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