; LLVM IR from dmr-goncalves/HumanAwareRobotNavigation :: src/husky/husky_base/src/horizon_legacy/Message.ll (ZN9clearpath7Message4sendEv)

; 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.clearpath::BadAckException" = type { %"class.clearpath::TransportException.base", i32 }
%"class.clearpath::TransportException.base" = type <{ %"class.clearpath::Exception", i32 }>
%"class.clearpath::Exception" = type { ptr }

@_ZTIPN9clearpath15BadAckExceptionE = external dso_local constant { ptr, ptr, i32, ptr }, align 8

; 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 @_ZN9clearpath7Message4sendEv(ptr noundef nonnull align 8 dereferenceable(273) %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %41, %1
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 2
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %4, align 4
  br label %44

13:                                               ; preds = %9
  %14 = invoke noundef nonnull align 8 dereferenceable(80) ptr @_ZN9clearpath9Transport8instanceEv()
          to label %15 unwind label %17

15:                                               ; preds = %13
  invoke void @_ZN9clearpath9Transport4sendEPNS_7MessageE(ptr noundef nonnull align 8 dereferenceable(80) %14, ptr noundef %8)
          to label %16 unwind label %17

16:                                               ; preds = %15
  store i32 1, ptr %4, align 4
  br label %44

17:                                               ; preds = %15, %13
  %18 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTIPN9clearpath15BadAckExceptionE
  %19 = extractvalue { ptr, i32 } %18, 0
  store ptr %19, ptr %5, align 8
  %20 = extractvalue { ptr, i32 } %18, 1
  store i32 %20, ptr %6, align 4
  br label %21

21:                                               ; preds = %17
  %22 = load i32, ptr %6, align 4
  %23 = call i32 @llvm.eh.typeid.for.p0(ptr @_ZTIPN9clearpath15BadAckExceptionE) #4
  %24 = icmp eq i32 %22, %23
  br i1 %24, label %25, label %46

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %26 = load ptr, ptr %5, align 8
  %27 = call ptr @__cxa_begin_catch(ptr %26) #4
  store ptr %27, ptr %7, align 8
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.clearpath::BadAckException", ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = icmp ne i32 %30, 1
  br i1 %31, label %32, label %39

32:                                               ; preds = %25
  %33 = call ptr @__cxa_allocate_exception(i64 8) #4
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %34, ptr %33, align 16, !tbaa !5
  invoke void @__cxa_throw(ptr %33, ptr @_ZTIPN9clearpath15BadAckExceptionE, ptr null) #5
          to label %55 unwind label %35

35:                                               ; preds = %32
  %36 = landingpad { ptr, i32 }
          cleanup
  %37 = extractvalue { ptr, i32 } %36, 0
  store ptr %37, ptr %5, align 8
  %38 = extractvalue { ptr, i32 } %36, 1
  store i32 %38, ptr %6, align 4
  call void @__cxa_end_catch() #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %46

39:                                               ; preds = %25
  call void @__cxa_end_catch() #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !9
  br label %9, !llvm.loop !17

44:                                               ; preds = %16, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  %45 = load i32, ptr %4, align 4
  switch i32 %45, label %55 [
    i32 2, label %47
    i32 1, label %49
  ]

46:                                               ; preds = %35, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %50

47:                                               ; preds = %44
  %48 = call noundef nonnull align 8 dereferenceable(80) ptr @_ZN9clearpath9Transport8instanceEv()
  call void @_ZN9clearpath9Transport4sendEPNS_7MessageE(ptr noundef nonnull align 8 dereferenceable(80) %48, ptr noundef %8)
  br label %49

49:                                               ; preds = %47, %44
  ret void

50:                                               ; preds = %46
  %51 = load ptr, ptr %5, align 8
  %52 = load i32, ptr %6, align 4
  %53 = insertvalue { ptr, i32 } poison, ptr %51, 0
  %54 = insertvalue { ptr, i32 } %53, i32 %52, 1
  resume { ptr, i32 } %54

55:                                               ; preds = %44, %32
  unreachable
}

declare noundef nonnull align 8 dereferenceable(80) ptr @_ZN9clearpath9Transport8instanceEv() #2

declare i32 @__gxx_personality_v0(...)

declare void @_ZN9clearpath9Transport4sendEPNS_7MessageE(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef) #2

; Function Attrs: nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #3

declare ptr @__cxa_begin_catch(ptr)

declare ptr @__cxa_allocate_exception(i64)

declare void @__cxa_throw(ptr, ptr, ptr)

declare void @__cxa_end_catch()

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 = { "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 memory(none) }
attributes #4 = { nounwind }
attributes #5 = { noreturn }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !16, i64 12}
!12 = !{!"_ZTSN9clearpath15BadAckExceptionE", !13, i64 0, !16, i64 12}
!13 = !{!"_ZTSN9clearpath18TransportExceptionE", !14, i64 0, !15, i64 8}
!14 = !{!"_ZTSN9clearpath9ExceptionE", !6, i64 0}
!15 = !{!"_ZTSN9clearpath18TransportException6errorsE", !7, i64 0}
!16 = !{!"_ZTSN9clearpath15BadAckException8ackFlagsE", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@_ZTIPN9clearpath15BadAckExceptionE = external dso_local constant { ptr, ptr, i32, ptr }, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9clearpath7Message4sendEv(ptr noundef nonnull align 8 dereferenceable(273) %0) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = invoke noundef nonnull align 8 dereferenceable(80) ptr @_ZN9clearpath9Transport8instanceEv()
          to label %3 unwind label %4

3:                                                ; preds = %1
  invoke void @_ZN9clearpath9Transport4sendEPNS_7MessageE(ptr noundef nonnull align 8 dereferenceable(80) %2, ptr noundef nonnull %0)
          to label %.loopexit unwind label %4

4:                                                ; preds = %3, %1
  %5 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTIPN9clearpath15BadAckExceptionE
  %6 = extractvalue { ptr, i32 } %5, 1
  %7 = tail call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTIPN9clearpath15BadAckExceptionE) #3
  %8 = icmp eq i32 %6, %7
  br i1 %8, label %9, label %.loopexit16

9:                                                ; preds = %4
  %10 = extractvalue { ptr, i32 } %5, 0
  %11 = tail call ptr @__cxa_begin_catch(ptr %10) #3
  %12 = getelementptr inbounds i8, ptr %11, i64 12
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not = icmp eq i32 %13, 1
  br i1 %.not, label %18, label %14

14:                                               ; preds = %25, %9
  %.lcssa22 = phi ptr [ %11, %9 ], [ %27, %25 ]
  %15 = tail call ptr @__cxa_allocate_exception(i64 8) #3
  store ptr %.lcssa22, ptr %15, align 16, !tbaa !14
  invoke void @__cxa_throw(ptr nonnull %15, ptr nonnull @_ZTIPN9clearpath15BadAckExceptionE, ptr null) #4
          to label %32 unwind label %16

16:                                               ; preds = %14
  %17 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_end_catch() #3
  br label %.loopexit16

18:                                               ; preds = %9
  tail call void @__cxa_end_catch() #3
  %19 = invoke noundef nonnull align 8 dereferenceable(80) ptr @_ZN9clearpath9Transport8instanceEv()
          to label %20 unwind label %21

20:                                               ; preds = %18
  invoke void @_ZN9clearpath9Transport4sendEPNS_7MessageE(ptr noundef nonnull align 8 dereferenceable(80) %19, ptr noundef nonnull %0)
          to label %.loopexit unwind label %21

21:                                               ; preds = %20, %18
  %22 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTIPN9clearpath15BadAckExceptionE
  %23 = extractvalue { ptr, i32 } %22, 1
  %24 = icmp eq i32 %23, %6
  br i1 %24, label %25, label %.loopexit16

25:                                               ; preds = %21
  %26 = extractvalue { ptr, i32 } %22, 0
  %27 = tail call ptr @__cxa_begin_catch(ptr %26) #3
  %28 = getelementptr inbounds i8, ptr %27, i64 12
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %29, 1
  br i1 %.not.1, label %30, label %14

30:                                               ; preds = %25
  tail call void @__cxa_end_catch() #3
  %31 = tail call noundef nonnull align 8 dereferenceable(80) ptr @_ZN9clearpath9Transport8instanceEv()
  tail call void @_ZN9clearpath9Transport4sendEPNS_7MessageE(ptr noundef nonnull align 8 dereferenceable(80) %31, ptr noundef nonnull %0)
  br label %.loopexit

.loopexit16:                                      ; preds = %4, %21, %16
  %.merged = phi { ptr, i32 } [ %17, %16 ], [ %5, %4 ], [ %22, %21 ]
  resume { ptr, i32 } %.merged

.loopexit:                                        ; preds = %3, %20, %30
  ret void

32:                                               ; preds = %14
  unreachable
}

declare noundef nonnull align 8 dereferenceable(80) ptr @_ZN9clearpath9Transport8instanceEv() local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

declare void @_ZN9clearpath9Transport4sendEPNS_7MessageE(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nosync nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #2

declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

declare void @__cxa_end_catch() local_unnamed_addr

attributes #0 = { 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 = { "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 = { nofree nosync nounwind memory(none) }
attributes #3 = { nounwind }
attributes #4 = { noreturn }

!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 12}
!6 = !{!"_ZTSN9clearpath15BadAckExceptionE", !7, i64 0, !13, i64 12}
!7 = !{!"_ZTSN9clearpath18TransportExceptionE", !8, i64 0, !12, i64 8}
!8 = !{!"_ZTSN9clearpath9ExceptionE", !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTSN9clearpath18TransportException6errorsE", !10, i64 0}
!13 = !{!"_ZTSN9clearpath15BadAckException8ackFlagsE", !10, i64 0}
!14 = !{!9, !9, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass