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

; 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._cpHashAttr = type { i32, i32, i32, i32, [2 x i64] }
%struct._cpHashCtx = type { i32, i32, i64, i64, ptr, ptr, [8 x i64], i32, [128 x i8] }

@cpHashAlgAttr = external constant [0 x %struct._cpHashAttr], align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsHashFinal(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp eq ptr null, %8
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store i32 -8, ptr %3, align 4
  br label %40

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr null, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  store i32 -8, ptr %3, align 4
  br label %40

15:                                               ; preds = %11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._cpHashCtx, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i64 @IPP_UINT_PTR(ptr noundef %19)
  %21 = trunc i64 %20 to i32
  %22 = xor i32 %18, %21
  %23 = icmp eq i32 %22, 1129136465
  br i1 %23, label %25, label %24

24:                                               ; preds = %15
  store i32 -13, ptr %3, align 4
  br label %40

25:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._cpHashCtx, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !13
  store i32 %28, ptr %6, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %29 = load i32, ptr %6, align 4, !tbaa !14
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds [0 x %struct._cpHashAttr], ptr @cpHashAlgAttr, i64 0, i64 %30
  %32 = getelementptr inbounds %struct._cpHashAttr, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !15
  store i32 %33, ptr %7, align 4, !tbaa !14
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !14
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  call void @cpComputeDigest(ptr noundef %34, i32 noundef %35, ptr noundef %36)
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !14
  %39 = call i32 @cpReInitHash(ptr noundef %37, i32 noundef %38)
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %40

40:                                               ; preds = %25, %24, %14, %10
  %41 = load i32, ptr %3, align 4
  ret i32 %41
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(ptr noundef) #1

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

declare void @cpComputeDigest(ptr noundef, i32 noundef, ptr noundef) #3

declare i32 @cpReInitHash(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) #2

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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 0}
!10 = !{!"_cpHashCtx", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !11, i64 104, !7, i64 108}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !11, i64 4}
!16 = !{!"_cpHashAttr", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !7, i64 16}


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

%struct._cpHashAttr = type { i32, i32, i32, i32, [2 x i64] }

@cpHashAlgAttr = external local_unnamed_addr constant [0 x %struct._cpHashAttr], align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 -13, 1) i32 @ippsHashFinal(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %18, label %5

5:                                                ; preds = %2
  %6 = load i32, ptr %1, align 8, !tbaa !5
  %7 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %1)
  %8 = trunc i64 %7 to i32
  %9 = xor i32 %6, %8
  %10 = icmp eq i32 %9, 1129136465
  br i1 %10, label %11, label %18

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %1, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds [0 x %struct._cpHashAttr], ptr @cpHashAlgAttr, i64 0, i64 %14, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !13
  tail call void @cpComputeDigest(ptr noundef nonnull %0, i32 noundef %16, ptr noundef nonnull %1) #3
  %17 = tail call i32 @cpReInitHash(ptr noundef nonnull %1, i32 noundef %13) #3
  br label %18

18:                                               ; preds = %5, %2, %11
  %.0 = phi i32 [ 0, %11 ], [ -8, %2 ], [ -13, %5 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(ptr noundef) local_unnamed_addr #1

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

declare i32 @cpReInitHash(ptr noundef, i32 noundef) local_unnamed_addr #2

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 = { 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 #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 = { 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 = !{!"_cpHashCtx", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !11, i64 24, !11, i64 32, !8, i64 40, !7, i64 104, !8, i64 108}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!14, !7, i64 4}
!14 = !{!"_cpHashAttr", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16}


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