; LLVM IR from p4lang/p4c :: backends/tofino/bf-utils/dynamic_hash (bfn_hash_algorithm)

; 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.bfn_hash_algorithm_ = type { i32, i8, i8, i32, i32, i8, i64, i64, i64, ptr }

@_ZL14bfn_crc_errors = external hidden global [3 x ptr], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z13determine_msbm(i64 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z16verify_algorithmP19bfn_hash_algorithm_PPKc(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %6, i32 0, i32 6
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = and i64 %8, 1
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %18

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

14:                                               ; preds = %11
  %15 = load ptr, ptr @_ZL14bfn_crc_errors, align 16, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %15, ptr %16, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %14, %11
  store i1 false, ptr %3, align 1
  br label %63

18:                                               ; preds = %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %19, i32 0, i32 7
  %21 = load i64, ptr %20, align 8, !tbaa !16
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %40

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %24, i32 0, i32 7
  %26 = load i64, ptr %25, align 8, !tbaa !16
  %27 = call noundef i32 @_Z13determine_msbm(i64 noundef %26)
  %28 = add nsw i32 %27, 1
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %29, i32 0, i32 4
  %31 = load i32, ptr %30, align 4, !tbaa !17
  %32 = icmp sgt i32 %28, %31
  br i1 %32, label %33, label %40

33:                                               ; preds = %23
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  %37 = load ptr, ptr getelementptr inbounds ([3 x ptr], ptr @_ZL14bfn_crc_errors, i64 0, i64 1), align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %37, ptr %38, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %36, %33
  store i1 false, ptr %3, align 1
  br label %63

40:                                               ; preds = %23, %18
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %41, i32 0, i32 8
  %43 = load i64, ptr %42, align 8, !tbaa !18
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %45, label %62

45:                                               ; preds = %40
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %46, i32 0, i32 8
  %48 = load i64, ptr %47, align 8, !tbaa !18
  %49 = call noundef i32 @_Z13determine_msbm(i64 noundef %48)
  %50 = add nsw i32 %49, 1
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %51, i32 0, i32 4
  %53 = load i32, ptr %52, align 4, !tbaa !17
  %54 = icmp sgt i32 %50, %53
  br i1 %54, label %55, label %62

55:                                               ; preds = %45
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %61

58:                                               ; preds = %55
  %59 = load ptr, ptr getelementptr inbounds ([3 x ptr], ptr @_ZL14bfn_crc_errors, i64 0, i64 2), align 16, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %59, ptr %60, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %58, %55
  store i1 false, ptr %3, align 1
  br label %63

62:                                               ; preds = %45, %40
  store i1 true, ptr %3, align 1
  br label %63

63:                                               ; preds = %62, %61, %39, %17
  %64 = load i1, ptr %3, align 1
  ret i1 %64
}

attributes #0 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !15, i64 24}
!10 = !{!"_ZTS19bfn_hash_algorithm_", !11, i64 0, !12, i64 4, !12, i64 5, !13, i64 8, !14, i64 12, !12, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !6, i64 48}
!11 = !{!"_ZTS19bfn_hash_alg_type_t", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!"_ZTS13bfn_crc_alg_t", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!10, !15, i64 32}
!17 = !{!10, !14, i64 12}
!18 = !{!10, !15, i64 40}


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

@_ZL14bfn_crc_errors = external hidden local_unnamed_addr global [3 x ptr], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z13determine_msbm(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z16verify_algorithmP19bfn_hash_algorithm_PPKc(ptr nocapture noundef readonly %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = and i64 %4, 1
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  %.not22 = icmp eq ptr %1, null
  br i1 %.not22, label %24, label %.sink.split

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load i64, ptr %9, align 8, !tbaa !15
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %16, label %11

11:                                               ; preds = %8
  %12 = tail call noundef i32 @_Z13determine_msbm(i64 noundef %10)
  %13 = getelementptr inbounds i8, ptr %0, i64 12
  %14 = load i32, ptr %13, align 4, !tbaa !16
  %.not17 = icmp slt i32 %12, %14
  br i1 %.not17, label %16, label %15

15:                                               ; preds = %11
  %.not21 = icmp eq ptr %1, null
  br i1 %.not21, label %24, label %.sink.split

16:                                               ; preds = %11, %8
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  %18 = load i64, ptr %17, align 8, !tbaa !17
  %.not18 = icmp eq i64 %18, 0
  br i1 %.not18, label %24, label %19

19:                                               ; preds = %16
  %20 = tail call noundef i32 @_Z13determine_msbm(i64 noundef %18)
  %21 = getelementptr inbounds i8, ptr %0, i64 12
  %22 = load i32, ptr %21, align 4, !tbaa !16
  %.not19 = icmp slt i32 %20, %22
  br i1 %.not19, label %24, label %23

23:                                               ; preds = %19
  %.not20 = icmp eq ptr %1, null
  br i1 %.not20, label %24, label %.sink.split

.sink.split:                                      ; preds = %23, %15, %7
  %.sink.in = phi ptr [ @_ZL14bfn_crc_errors, %7 ], [ getelementptr inbounds (i8, ptr @_ZL14bfn_crc_errors, i64 8), %15 ], [ getelementptr inbounds (i8, ptr @_ZL14bfn_crc_errors, i64 16), %23 ]
  %.sink = load ptr, ptr %.sink.in, align 8, !tbaa !18
  store ptr %.sink, ptr %1, align 8, !tbaa !18
  br label %24

24:                                               ; preds = %.sink.split, %16, %19, %23, %15, %7
  %.0 = phi i1 [ false, %7 ], [ false, %15 ], [ false, %23 ], [ true, %19 ], [ true, %16 ], [ false, %.sink.split ]
  ret i1 %.0
}

attributes #0 = { 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, !13, i64 24}
!6 = !{!"_ZTS19bfn_hash_algorithm_", !7, i64 0, !10, i64 4, !10, i64 5, !11, i64 8, !12, i64 12, !10, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !14, i64 48}
!7 = !{!"_ZTS19bfn_hash_alg_type_t", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"_ZTS13bfn_crc_alg_t", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!6, !13, i64 32}
!16 = !{!6, !12, i64 12}
!17 = !{!6, !13, i64 40}
!18 = !{!14, !14, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass