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

@_ZL17standard_crc_algs = external hidden global [41 x %struct.crc_alg_info_], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z28build_standard_crc_algorithmP19bfn_hash_algorithm_13bfn_crc_alg_t(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %struct.crc_alg_info_, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = icmp sge i32 %6, 0
  br i1 %7, label %8, label %14

8:                                                ; preds = %2
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp sle i32 %9, 6
  br i1 %10, label %11, label %14

11:                                               ; preds = %8
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %12, i32 0, i32 4
  store i32 8, ptr %13, align 4, !tbaa !11
  br label %44

14:                                               ; preds = %8, %2
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = icmp sge i32 %15, 7
  br i1 %16, label %17, label %23

17:                                               ; preds = %14
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = icmp sle i32 %18, 27
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %21, i32 0, i32 4
  store i32 16, ptr %22, align 4, !tbaa !11
  br label %43

23:                                               ; preds = %17, %14
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = icmp sge i32 %24, 28
  br i1 %25, label %26, label %32

26:                                               ; preds = %23
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = icmp sle i32 %27, 36
  br i1 %28, label %29, label %32

29:                                               ; preds = %26
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %30, i32 0, i32 4
  store i32 32, ptr %31, align 4, !tbaa !11
  br label %42

32:                                               ; preds = %26, %23
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = icmp sge i32 %33, 37
  br i1 %34, label %35, label %41

35:                                               ; preds = %32
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = icmp sle i32 %36, 40
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %39, i32 0, i32 4
  store i32 64, ptr %40, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %38, %35, %32
  br label %42

42:                                               ; preds = %41, %29
  br label %43

43:                                               ; preds = %42, %20
  br label %44

44:                                               ; preds = %43, %11
  call void @llvm.lifetime.start.p0(i64 40, ptr %5) #4
  %45 = load i32, ptr %4, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [41 x %struct.crc_alg_info_], ptr @_ZL17standard_crc_algs, i64 0, i64 %46
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %47, i64 40, i1 false), !tbaa.struct !17
  %48 = getelementptr inbounds %struct.crc_alg_info_, ptr %5, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !20
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %50, i32 0, i32 6
  store i64 %49, ptr %51, align 8, !tbaa !22
  %52 = getelementptr inbounds %struct.crc_alg_info_, ptr %5, i32 0, i32 2
  %53 = load i8, ptr %52, align 8, !tbaa !23, !range !24, !noundef !25
  %54 = trunc i8 %53 to i1
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %55, i32 0, i32 5
  %57 = zext i1 %54 to i8
  store i8 %57, ptr %56, align 8, !tbaa !26
  %58 = getelementptr inbounds %struct.crc_alg_info_, ptr %5, i32 0, i32 3
  %59 = load i64, ptr %58, align 8, !tbaa !27
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %60, i32 0, i32 7
  store i64 %59, ptr %61, align 8, !tbaa !28
  %62 = getelementptr inbounds %struct.crc_alg_info_, ptr %5, i32 0, i32 4
  %63 = load i64, ptr %62, align 8, !tbaa !29
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %64, i32 0, i32 8
  store i64 %63, ptr %65, align 8, !tbaa !30
  %66 = getelementptr inbounds %struct.crc_alg_info_, ptr %5, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !31
  %68 = call noundef i32 @_ZL19crc_alg_str_to_typePKc(ptr noundef %67)
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.bfn_hash_algorithm_, ptr %69, i32 0, i32 3
  store i32 %68, ptr %70, align 8, !tbaa !32
  call void @llvm.lifetime.end.p0(i64 40, ptr %5) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL19crc_alg_str_to_typePKc(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 = !{!"_ZTS13bfn_crc_alg_t", !7, i64 0}
!11 = !{!12, !15, i64 12}
!12 = !{!"_ZTS19bfn_hash_algorithm_", !13, i64 0, !14, i64 4, !14, i64 5, !10, i64 8, !15, i64 12, !14, i64 16, !16, i64 24, !16, i64 32, !16, i64 40, !6, i64 48}
!13 = !{!"_ZTS19bfn_hash_alg_type_t", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{i64 0, i64 8, !5, i64 8, i64 8, !18, i64 16, i64 1, !19, i64 24, i64 8, !18, i64 32, i64 8, !18}
!18 = !{!16, !16, i64 0}
!19 = !{!14, !14, i64 0}
!20 = !{!21, !16, i64 8}
!21 = !{!"_ZTS13crc_alg_info_", !6, i64 0, !16, i64 8, !14, i64 16, !16, i64 24, !16, i64 32}
!22 = !{!12, !16, i64 24}
!23 = !{!21, !14, i64 16}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = !{!12, !14, i64 16}
!27 = !{!21, !16, i64 24}
!28 = !{!12, !16, i64 32}
!29 = !{!21, !16, i64 32}
!30 = !{!12, !16, i64 40}
!31 = !{!21, !6, i64 0}
!32 = !{!12, !10, 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"

%struct.crc_alg_info_ = type { ptr, i64, i8, i64, i64 }

@_ZL17standard_crc_algs = external hidden local_unnamed_addr global [41 x %struct.crc_alg_info_], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z28build_standard_crc_algorithmP19bfn_hash_algorithm_13bfn_crc_alg_t(ptr nocapture noundef writeonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %or.cond = icmp ult i32 %1, 7
  br i1 %or.cond, label %.sink.split, label %3

3:                                                ; preds = %2
  %4 = add i32 %1, -7
  %or.cond3 = icmp ult i32 %4, 21
  br i1 %or.cond3, label %.sink.split, label %5

5:                                                ; preds = %3
  %6 = add i32 %1, -28
  %or.cond5 = icmp ult i32 %6, 9
  br i1 %or.cond5, label %.sink.split, label %7

7:                                                ; preds = %5
  %8 = add i32 %1, -37
  %or.cond7 = icmp ult i32 %8, 4
  br i1 %or.cond7, label %.sink.split, label %10

.sink.split:                                      ; preds = %7, %5, %3, %2
  %.sink = phi i32 [ 8, %2 ], [ 16, %3 ], [ 32, %5 ], [ 64, %7 ]
  %9 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %.sink, ptr %9, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %.sink.split, %7
  %11 = sext i32 %1 to i64
  %12 = getelementptr inbounds [41 x %struct.crc_alg_info_], ptr @_ZL17standard_crc_algs, i64 0, i64 %11
  %.sroa.0.0.copyload = load ptr, ptr %12, align 8, !tbaa !15
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 8
  %.sroa.4.0.copyload = load i64, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !16
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 16
  %.sroa.5.0.copyload = load i8, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !17
  %.sroa.68.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 24
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = and i8 %.sroa.5.0.copyload, 1
  store i8 %15, ptr %14, align 8, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  %17 = load <2 x i64>, ptr %.sroa.68.0..sroa_idx, align 8, !tbaa !16
  store i64 %.sroa.4.0.copyload, ptr %13, align 8, !tbaa !19
  store <2 x i64> %17, ptr %16, align 8, !tbaa !16
  %18 = tail call noundef i32 @_ZL19crc_alg_str_to_typePKc(ptr noundef %.sroa.0.0.copyload)
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %18, ptr %19, align 8, !tbaa !20
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL19crc_alg_str_to_typePKc(ptr noundef) local_unnamed_addr #1

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" }
attributes #1 = { inlinehint 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, !12, i64 12}
!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 = !{!14, !14, i64 0}
!16 = !{!13, !13, i64 0}
!17 = !{!10, !10, i64 0}
!18 = !{!6, !10, i64 16}
!19 = !{!6, !13, i64 24}
!20 = !{!6, !11, i64 8}


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