; LLVM IR from specinfo-ua/UAPKI :: library/uapki/src/content-hasher.ll (ZN7UapkiNS13ContentHasher6digestE7HashAlg)

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

%"class.UapkiNS::ContentHasher" = type { i32, i32, ptr, i8, %"class.std::__cxx11::basic_string", ptr, i64, %"class.UapkiNS::SmartBA" }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.UapkiNS::SmartBA" = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS13ContentHasher6digestE7HashAlg(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %14, label %10

10:                                               ; preds = %2
  %11 = getelementptr inbounds %"class.UapkiNS::ContentHasher", ptr %7, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %10, %2
  br label %15

15:                                               ; preds = %14, %10
  %16 = getelementptr inbounds %"class.UapkiNS::ContentHasher", ptr %7, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !19
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = icmp eq i32 %17, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i32 0, ptr %3, align 4
  br label %48

21:                                               ; preds = %15
  %22 = getelementptr inbounds %"class.UapkiNS::ContentHasher", ptr %7, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !11
  call void @_ZN7UapkiNS13ContentHasher13setSourceTypeENS0_10SourceTypeE(ptr noundef nonnull align 8 dereferenceable(80) %7, i32 noundef %23)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !20
  %24 = getelementptr inbounds %"class.UapkiNS::ContentHasher", ptr %7, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !11
  switch i32 %25, label %39 [
    i32 1, label %26
    i32 2, label %33
    i32 3, label %36
  ]

26:                                               ; preds = %21
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = getelementptr inbounds %"class.UapkiNS::ContentHasher", ptr %7, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !22
  %30 = getelementptr inbounds %"class.UapkiNS::ContentHasher", ptr %7, i32 0, i32 7
  %31 = call noundef ptr @_ZN7UapkiNS7SmartBAadEv(ptr noundef nonnull align 8 dereferenceable(8) %30)
  %32 = call i32 @hash(i32 noundef %27, ptr noundef %29, ptr noundef %31)
  store i32 %32, ptr %6, align 4, !tbaa !20
  br label %40

33:                                               ; preds = %21
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = call noundef i32 @_ZN7UapkiNS13ContentHasher10digestFileE7HashAlg(ptr noundef nonnull align 8 dereferenceable(80) %7, i32 noundef %34)
  store i32 %35, ptr %6, align 4, !tbaa !20
  br label %40

36:                                               ; preds = %21
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = call noundef i32 @_ZN7UapkiNS13ContentHasher12digestMemoryE7HashAlg(ptr noundef nonnull align 8 dereferenceable(80) %7, i32 noundef %37)
  store i32 %38, ptr %6, align 4, !tbaa !20
  br label %40

39:                                               ; preds = %21
  store i32 4101, ptr %6, align 4, !tbaa !20
  br label %40

40:                                               ; preds = %39, %36, %33, %26
  %41 = load i32, ptr %6, align 4, !tbaa !20
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %46

43:                                               ; preds = %40
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = getelementptr inbounds %"class.UapkiNS::ContentHasher", ptr %7, i32 0, i32 1
  store i32 %44, ptr %45, align 4, !tbaa !19
  br label %46

46:                                               ; preds = %43, %40
  %47 = load i32, ptr %6, align 4, !tbaa !20
  store i32 %47, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %48

48:                                               ; preds = %46, %20
  %49 = load i32, ptr %3, align 4
  ret i32 %49
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7UapkiNS13ContentHasher13setSourceTypeENS0_10SourceTypeE(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef) #0 align 2

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

declare i32 @hash(i32 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7UapkiNS7SmartBAadEv(ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7UapkiNS13ContentHasher10digestFileE7HashAlg(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7UapkiNS13ContentHasher12digestMemoryE7HashAlg(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef) #0 align 2

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

attributes #0 = { mustprogress 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTS7HashAlg", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN7UapkiNS13ContentHasherE", !13, i64 0, !10, i64 4, !6, i64 8, !14, i64 16, !15, i64 24, !6, i64 56, !17, i64 64, !18, i64 72}
!13 = !{!"_ZTSN7UapkiNS13ContentHasher10SourceTypeE", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !17, i64 8, !7, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSN7UapkiNS7SmartBAE", !6, i64 0}
!19 = !{!12, !10, i64 4}
!20 = !{!21, !21, i64 0}
!21 = !{!"int", !7, i64 0}
!22 = !{!12, !6, i64 8}


; 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: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS13ContentHasher6digestE7HashAlg(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i32 %4, %1
  br i1 %5, label %.thread, label %6

6:                                                ; preds = %2
  %7 = load i32, ptr %0, align 8, !tbaa !17
  tail call void @_ZN7UapkiNS13ContentHasher13setSourceTypeENS0_10SourceTypeE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %7)
  %8 = load i32, ptr %0, align 8, !tbaa !17
  switch i32 %8, label %.thread [
    i32 1, label %9
    i32 2, label %15
    i32 3, label %17
  ]

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !18
  %12 = getelementptr inbounds i8, ptr %0, i64 72
  %13 = tail call noundef ptr @_ZN7UapkiNS7SmartBAadEv(ptr noundef nonnull align 8 dereferenceable(8) %12)
  %14 = tail call i32 @hash(i32 noundef %1, ptr noundef %11, ptr noundef %13)
  br label %19

15:                                               ; preds = %6
  %16 = tail call noundef i32 @_ZN7UapkiNS13ContentHasher10digestFileE7HashAlg(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %1)
  br label %19

17:                                               ; preds = %6
  %18 = tail call noundef i32 @_ZN7UapkiNS13ContentHasher12digestMemoryE7HashAlg(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %1)
  br label %19

19:                                               ; preds = %17, %15, %9
  %.0 = phi i32 [ %18, %17 ], [ %16, %15 ], [ %14, %9 ]
  %20 = icmp eq i32 %.0, 0
  br i1 %20, label %21, label %.thread

21:                                               ; preds = %19
  store i32 %1, ptr %3, align 4, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %6, %19, %21, %2
  %.09 = phi i32 [ 0, %2 ], [ 0, %21 ], [ %.0, %19 ], [ 4101, %6 ]
  ret i32 %.09
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7UapkiNS13ContentHasher13setSourceTypeENS0_10SourceTypeE(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef) local_unnamed_addr #0 align 2

declare i32 @hash(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7UapkiNS7SmartBAadEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7UapkiNS13ContentHasher10digestFileE7HashAlg(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7UapkiNS13ContentHasher12digestMemoryE7HashAlg(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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 = { "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 = { mustprogress 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, !10, i64 4}
!6 = !{!"_ZTSN7UapkiNS13ContentHasherE", !7, i64 0, !10, i64 4, !11, i64 8, !12, i64 16, !13, i64 24, !11, i64 56, !15, i64 64, !16, i64 72}
!7 = !{!"_ZTSN7UapkiNS13ContentHasher10SourceTypeE", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS7HashAlg", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !8, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !11, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!"_ZTSN7UapkiNS7SmartBAE", !11, i64 0}
!17 = !{!6, !7, i64 0}
!18 = !{!6, !11, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass