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

; 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
@_ZN2P42IR3MAUL27color_mapram_address_to_strE = external hidden global [4 x ptr], align 16

; 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_18ColorMapramAddressE(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 3, ptr %14, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %13, %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 sle i32 %17, 3
  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 [4 x ptr], ptr @_ZN2P42IR3MAUL27color_mapram_address_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 %40 [
    i32 2, label %37
    i32 1, label %38
  ]

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

38:                                               ; preds = %37, %35
  %39 = load i1, ptr %3, align 1
  ret i1 %39

40:                                               ; 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 = !{!"_ZTSN2P42IR3MAU18ColorMapramAddressE", !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
@_ZN2P42IR3MAUL27color_mapram_address_to_strE = external hidden local_unnamed_addr global [4 x ptr], align 16

; 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_18ColorMapramAddressE(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 %7

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 %7, label %8

7:                                                ; preds = %5, %2
  store i32 3, ptr %1, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %7, %5
  %9 = load ptr, ptr @_ZN2P42IR3MAUL27color_mapram_address_to_strE, align 16, !tbaa !9
  %.sroa.0.0.copyload = load ptr, ptr %3, align 8, !tbaa !9
  %10 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %9, ptr %.sroa.0.0.copyload)
  br i1 %10, label %11, label %12

11:                                               ; preds = %18, %15, %12, %8
  %.0811.lcssa.wide = phi i32 [ 0, %8 ], [ 1, %12 ], [ 2, %15 ], [ 3, %18 ]
  store i32 %.0811.lcssa.wide, ptr %1, align 4, !tbaa !5
  br label %.loopexit

12:                                               ; preds = %8
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2P42IR3MAUL27color_mapram_address_to_strE, i64 8), align 8, !tbaa !9
  %.sroa.0.0.copyload.1 = load ptr, ptr %3, align 8, !tbaa !9
  %14 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %13, ptr %.sroa.0.0.copyload.1)
  br i1 %14, label %11, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2P42IR3MAUL27color_mapram_address_to_strE, i64 16), align 16, !tbaa !9
  %.sroa.0.0.copyload.2 = load ptr, ptr %3, align 8, !tbaa !9
  %17 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %16, ptr %.sroa.0.0.copyload.2)
  br i1 %17, label %11, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2P42IR3MAUL27color_mapram_address_to_strE, i64 24), align 8, !tbaa !9
  %.sroa.0.0.copyload.3 = load ptr, ptr %3, align 8, !tbaa !9
  %20 = call noundef zeroext i1 @_ZN2P4eqEPKcNS_7cstringE(ptr noundef %19, ptr %.sroa.0.0.copyload.3)
  br i1 %20, label %11, label %.loopexit

.loopexit:                                        ; preds = %18, %11
  %21 = phi i1 [ true, %11 ], [ false, %18 ]
  ret i1 %21
}

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 = !{!"_ZTSN2P42IR3MAU18ColorMapramAddressE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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