; LLVM IR from p4lang/p4c :: backends/tofino/bf-p4c/ir/ir_enums.ll (ZN2P42IR3MAUrsENS_7cstringERNS1_9MeterTypeE)

; 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.P4::cstring" = type { ptr }

@.str = external hidden unnamed_addr constant [1 x i8], align 1
@_ZN2P42IR3MAUL17meter_type_to_strE = external hidden global [8 x ptr], align 16
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK2P47cstringcvbEv(ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK2P47cstringeqEPKc(ptr noundef nonnull align 8 dereferenceable(8), ptr 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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef, ptr) #2

; 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) #3

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2P42IR3MAUrsENS_7cstringERNS1_9MeterTypeE(ptr %0, ptr noundef nonnull align 4 dereferenceable(4) %1) #4 {
  %3 = alloca i1, align 1
  %4 = alloca %"class.P4::cstring", align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %"class.P4::cstring", align 8
  %9 = getelementptr inbounds %"class.P4::cstring", ptr %4, i32 0, i32 0
  store ptr %0, ptr %9, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = call noundef zeroext i1 @_ZNK2P47cstringcvbEv(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br i1 %10, label %11, label %13

11:                                               ; preds = %2
  %12 = call noundef zeroext i1 @_ZNK2P47cstringeqEPKc(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef @.str)
  br i1 %12, label %13, label %15

13:                                               ; preds = %11, %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %14, align 4, !tbaa !9
  store i1 true, ptr %3, align 1
  br label %42

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %32, %15
  %17 = load i32, ptr %6, align 4, !tbaa !11
  %18 = icmp slt i32 %17, 8
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  store i32 2, ptr %7, align 4
  br label %35

20:                                               ; preds = %16
  %21 = load i32, ptr %6, align 4, !tbaa !11
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [8 x ptr], ptr @_ZN2P42IR3MAUL17meter_type_to_strE, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %4, i64 8, i1 false), !tbaa.struct !13
  %25 = getelementptr inbounds %"class.P4::cstring", ptr %8, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8
  %27 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %24, ptr %26)
  br i1 %27, label %28, label %31

28:                                               ; preds = %20
  %29 = load i32, ptr %6, align 4, !tbaa !11
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %29, ptr %30, align 4, !tbaa !9
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %35

31:                                               ; preds = %20
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %6, align 4, !tbaa !11
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %6, align 4, !tbaa !11
  br label %16, !llvm.loop !14

35:                                               ; preds = %28, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %36 = load i32, ptr %7, align 4
  switch i32 %36, label %44 [
    i32 2, label %37
    i32 1, label %42
  ]

37:                                               ; preds = %35
  %38 = call noundef zeroext i1 @_ZNK2P47cstringeqEPKc(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef @.str.1)
  br i1 %38, label %39, label %41

39:                                               ; preds = %37
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 6, ptr %40, align 4, !tbaa !9
  store i1 true, ptr %3, align 1
  br label %42

41:                                               ; preds = %37
  store i1 false, ptr %3, align 1
  br label %42

42:                                               ; preds = %41, %39, %35, %13
  %43 = load i1, ptr %3, align 1
  ret i1 %43

44:                                               ; preds = %35
  unreachable
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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 = !{!"_ZTSN2P42IR3MAU9MeterTypeE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i64 0, i64 8, !5}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

%"class.P4::cstring" = type { ptr }

@.str = external hidden unnamed_addr constant [1 x i8], align 1
@_ZN2P42IR3MAUL17meter_type_to_strE = external hidden local_unnamed_addr global [8 x ptr], align 16
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK2P47cstringeqEPKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef, ptr) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN2P42IR3MAUrsENS_7cstringERNS1_9MeterTypeE(ptr %0, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %1) local_unnamed_addr #0 {
  %3 = alloca %"class.P4::cstring", align 8
  store ptr %0, ptr %3, align 8
  %4 = call noundef zeroext i1 @_ZNK2P47cstringcvbEv(ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %4, label %5, label %.sink.split

5:                                                ; preds = %2
  %6 = call noundef zeroext i1 @_ZNK2P47cstringeqEPKc(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull @.str)
  br i1 %6, label %.sink.split, label %.preheader.preheader

.preheader.preheader:                             ; preds = %5
  %7 = load ptr, ptr @_ZN2P42IR3MAUL17meter_type_to_strE, align 16, !tbaa !5
  %.sroa.0.0.copyload = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %7, ptr %.sroa.0.0.copyload)
  br i1 %8, label %.sink.split, label %.preheader.1

.preheader.1:                                     ; preds = %.preheader.preheader
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2P42IR3MAUL17meter_type_to_strE, i64 8), align 8, !tbaa !5
  %.sroa.0.0.copyload.1 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %9, ptr %.sroa.0.0.copyload.1)
  br i1 %10, label %.sink.split, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2P42IR3MAUL17meter_type_to_strE, i64 16), align 16, !tbaa !5
  %.sroa.0.0.copyload.2 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %11, ptr %.sroa.0.0.copyload.2)
  br i1 %12, label %.sink.split, label %.preheader.3

.preheader.3:                                     ; preds = %.preheader.2
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2P42IR3MAUL17meter_type_to_strE, i64 24), align 8, !tbaa !5
  %.sroa.0.0.copyload.3 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %13, ptr %.sroa.0.0.copyload.3)
  br i1 %14, label %.sink.split, label %.preheader.4

.preheader.4:                                     ; preds = %.preheader.3
  %15 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2P42IR3MAUL17meter_type_to_strE, i64 32), align 16, !tbaa !5
  %.sroa.0.0.copyload.4 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %15, ptr %.sroa.0.0.copyload.4)
  br i1 %16, label %.sink.split, label %.preheader.5

.preheader.5:                                     ; preds = %.preheader.4
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2P42IR3MAUL17meter_type_to_strE, i64 40), align 8, !tbaa !5
  %.sroa.0.0.copyload.5 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %17, ptr %.sroa.0.0.copyload.5)
  br i1 %18, label %.sink.split, label %.preheader.6

.preheader.6:                                     ; preds = %.preheader.5
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2P42IR3MAUL17meter_type_to_strE, i64 48), align 16, !tbaa !5
  %.sroa.0.0.copyload.6 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %19, ptr %.sroa.0.0.copyload.6)
  br i1 %20, label %.sink.split, label %.preheader.7

.preheader.7:                                     ; preds = %.preheader.6
  %21 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2P42IR3MAUL17meter_type_to_strE, i64 56), align 8, !tbaa !5
  %.sroa.0.0.copyload.7 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %21, ptr %.sroa.0.0.copyload.7)
  br i1 %22, label %.sink.split, label %23

23:                                               ; preds = %.preheader.7
  %24 = call noundef zeroext i1 @_ZNK2P47cstringeqEPKc(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull @.str.1)
  br i1 %24, label %.sink.split, label %25

.sink.split:                                      ; preds = %23, %.preheader.preheader, %.preheader.1, %.preheader.2, %.preheader.3, %.preheader.4, %.preheader.5, %.preheader.6, %.preheader.7, %2, %5
  %.0914.lcssa.wide.sink = phi i32 [ 0, %5 ], [ 0, %2 ], [ 0, %.preheader.preheader ], [ 1, %.preheader.1 ], [ 2, %.preheader.2 ], [ 3, %.preheader.3 ], [ 4, %.preheader.4 ], [ 5, %.preheader.5 ], [ 6, %.preheader.6 ], [ 7, %.preheader.7 ], [ 6, %23 ]
  store i32 %.0914.lcssa.wide.sink, ptr %1, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %.sink.split, %23
  %.1 = phi i1 [ false, %23 ], [ true, %.sink.split ]
  ret i1 %.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, !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 = !{!"_ZTSN2P42IR3MAU9MeterTypeE", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass