; LLVM IR from p4lang/p4c :: backends/tofino/bf-asm/bson.ll (ZN4jsonlsERSoNS_9bson_wrapIKNS_3objEEE)

; 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.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"struct.json::bson_wrap.48" = type { ptr }
%"struct.json::bson_wrap.47" = type { ptr }
%"struct.json::bson_wrap.46" = type { ptr }

@_ZSt4cerr = external global %"class.std::basic_ostream", align 8
@.str.11 = external hidden unnamed_addr constant [49 x i8], align 1

; 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: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN4jsonlsERSoNS_9bson_wrapIKNS_3objEEE(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca %"struct.json::bson_wrap.48", align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %"struct.json::bson_wrap.47", align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca %"struct.json::bson_wrap.46", align 8
  %11 = getelementptr inbounds %"struct.json::bson_wrap.48", ptr %4, i32 0, i32 0
  store ptr %1, ptr %11, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %12 = getelementptr inbounds %"struct.json::bson_wrap.48", ptr %4, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds ptr, ptr %14, i64 17
  %16 = load ptr, ptr %15, align 8
  %17 = call noundef ptr %16(ptr noundef nonnull align 8 dereferenceable(8) %13)
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %28

20:                                               ; preds = %2
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call ptr @_ZN4json6binaryIKNS_3mapEEENS_9bson_wrapIT_EERS4_(ptr noundef nonnull align 8 dereferenceable(80) %22)
  %24 = getelementptr inbounds %"struct.json::bson_wrap.47", ptr %7, i32 0, i32 0
  store ptr %23, ptr %24, align 8
  %25 = getelementptr inbounds %"struct.json::bson_wrap.47", ptr %7, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8
  %27 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN4jsonlsERSoNS_9bson_wrapIKNS_3mapEEE(ptr noundef nonnull align 8 dereferenceable(8) %21, ptr %26)
  store ptr %27, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %29

28:                                               ; preds = %2
  store i32 0, ptr %8, align 4
  br label %29

29:                                               ; preds = %28, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %30 = load i32, ptr %8, align 4
  switch i32 %30, label %57 [
    i32 0, label %31
    i32 1, label %55
  ]

31:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %32 = getelementptr inbounds %"struct.json::bson_wrap.48", ptr %4, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds ptr, ptr %34, i64 15
  %36 = load ptr, ptr %35, align 8
  %37 = call noundef ptr %36(ptr noundef nonnull align 8 dereferenceable(8) %33)
  store ptr %37, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %48

40:                                               ; preds = %31
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = call ptr @_ZN4json6binaryIKNS_6vectorEEENS_9bson_wrapIT_EERS4_(ptr noundef nonnull align 8 dereferenceable(32) %42)
  %44 = getelementptr inbounds %"struct.json::bson_wrap.46", ptr %10, i32 0, i32 0
  store ptr %43, ptr %44, align 8
  %45 = getelementptr inbounds %"struct.json::bson_wrap.46", ptr %10, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8
  %47 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN4jsonlsERSoNS_9bson_wrapIKNS_6vectorEEE(ptr noundef nonnull align 8 dereferenceable(8) %41, ptr %46)
  store ptr %47, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %49

48:                                               ; preds = %31
  store i32 0, ptr %8, align 4
  br label %49

49:                                               ; preds = %48, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %50 = load i32, ptr %8, align 4
  switch i32 %50, label %57 [
    i32 0, label %51
    i32 1, label %55
  ]

51:                                               ; preds = %49
  %52 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cerr, ptr noundef @.str.11)
  %53 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %52, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %54, ptr %3, align 8
  br label %55

55:                                               ; preds = %51, %49, %29
  %56 = load ptr, ptr %3, align 8
  ret ptr %56

57:                                               ; preds = %49, %29
  unreachable
}

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

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZN4json6binaryIKNS_6vectorEEENS_9bson_wrapIT_EERS4_(ptr noundef nonnull align 8 dereferenceable(32)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 #3 = { 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, !6, i64 0}
!10 = !{!"_ZTSN4json9bson_wrapIKNS_3objEEE", !6, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}


; 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.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cerr = external global %"class.std::basic_ostream", align 8
@.str.11 = external hidden unnamed_addr constant [49 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN4jsonlsERSoNS_9bson_wrapIKNS_6vectorEEE(ptr noundef nonnull align 8 dereferenceable(8), ptr) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN4jsonlsERSoNS_9bson_wrapIKNS_3mapEEE(ptr noundef nonnull align 8 dereferenceable(8), ptr) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN4jsonlsERSoNS_9bson_wrapIKNS_3objEEE(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 136
  %5 = load ptr, ptr %4, align 8
  %6 = tail call noundef ptr %5(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %.not.not = icmp eq ptr %6, null
  br i1 %.not.not, label %10, label %7

7:                                                ; preds = %2
  %8 = tail call ptr @_ZN4json6binaryIKNS_3mapEEENS_9bson_wrapIT_EERS4_(ptr noundef nonnull align 8 dereferenceable(80) %6)
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN4jsonlsERSoNS_9bson_wrapIKNS_3mapEEE(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr %8)
  br label %21

10:                                               ; preds = %2
  %11 = load ptr, ptr %1, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 120
  %13 = load ptr, ptr %12, align 8
  %14 = tail call noundef ptr %13(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %.not16.not = icmp eq ptr %14, null
  br i1 %.not16.not, label %18, label %15

15:                                               ; preds = %10
  %16 = tail call ptr @_ZN4json6binaryIKNS_6vectorEEENS_9bson_wrapIT_EERS4_(ptr noundef nonnull align 8 dereferenceable(32) %14)
  %17 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN4jsonlsERSoNS_9bson_wrapIKNS_6vectorEEE(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr %16)
  br label %21

18:                                               ; preds = %10
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cerr, ptr noundef nonnull @.str.11)
  %20 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %19, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %21

21:                                               ; preds = %15, %7, %18
  %.2 = phi ptr [ %9, %7 ], [ %17, %15 ], [ %0, %18 ]
  ret ptr %.2
}

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZN4json6binaryIKNS_3mapEEENS_9bson_wrapIT_EERS4_(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZN4json6binaryIKNS_6vectorEEENS_9bson_wrapIT_EERS4_(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1

attributes #0 = { inlinehint 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 = { 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" }

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


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