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

; 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::Transport" = type { i8, ptr, i32, %"class.std::__cxx11::list", [4 x i64] }
%"class.std::__cxx11::list" = type { %"class.std::__cxx11::_List_base" }
%"class.std::__cxx11::_List_base" = type { %"struct.std::__cxx11::_List_base<clearpath::Message *, std::allocator<clearpath::Message *>>::_List_impl" }
%"struct.std::__cxx11::_List_base<clearpath::Message *, std::allocator<clearpath::Message *>>::_List_impl" = type { %"struct.std::__detail::_List_node_header" }
%"struct.std::__detail::_List_node_header" = type { %"struct.std::__detail::_List_node_base", i64 }
%"struct.std::__detail::_List_node_base" = type { ptr, ptr }

@_ZZN9clearpath9Transport9rxMessageEvE6rx_buf = external hidden global [256 x i8], align 16
@_ZZN9clearpath9Transport9rxMessageEvE6rx_inx = external hidden global i64, align 8
@_ZZN9clearpath9Transport9rxMessageEvE7msg_len = external hidden global i64, 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 noundef ptr @_ZN9clearpath9Transport9rxMessageEv(ptr noundef nonnull align 8 dereferenceable(80) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  %7 = icmp ne i64 %6, 0
  br i1 %7, label %9, label %8

8:                                                ; preds = %1
  call void @llvm.memset.p0.i64(ptr align 16 @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i8 -70, i64 256, i1 false)
  br label %9

9:                                                ; preds = %8, %1
  br label %10

10:                                               ; preds = %71, %9
  %11 = getelementptr inbounds %"class.clearpath::Transport", ptr %5, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i64 %13
  %15 = call noundef i32 @_Z8ReadDataPvPci(ptr noundef %12, ptr noundef %14, i32 noundef 1)
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %72

17:                                               ; preds = %10
  %18 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  switch i64 %18, label %60 [
    i64 0, label %19
    i64 1, label %32
    i64 2, label %35
  ]

19:                                               ; preds = %17
  %20 = load i8, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, align 16, !tbaa !20
  %21 = zext i8 %20 to i32
  %22 = icmp eq i32 %21, 170
  br i1 %22, label %23, label %26

23:                                               ; preds = %19
  %24 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  %25 = add i64 %24, 1
  store i64 %25, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  br label %31

26:                                               ; preds = %19
  %27 = getelementptr inbounds %"class.clearpath::Transport", ptr %5, i32 0, i32 4
  %28 = getelementptr inbounds [4 x i64], ptr %27, i64 0, i64 0
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = add i64 %29, 1
  store i64 %30, ptr %28, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %26, %23
  br label %71

32:                                               ; preds = %17
  %33 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  %34 = add i64 %33, 1
  store i64 %34, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  br label %71

35:                                               ; preds = %17
  %36 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  %37 = add i64 %36, 1
  store i64 %37, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  %38 = load i8, ptr getelementptr inbounds ([256 x i8], ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i64 0, i64 1), align 1, !tbaa !20
  %39 = sext i8 %38 to i32
  %40 = add nsw i32 %39, 3
  %41 = sext i32 %40 to i64
  store i64 %41, ptr @_ZZN9clearpath9Transport9rxMessageEvE7msg_len, align 8, !tbaa !9
  %42 = load i8, ptr getelementptr inbounds ([256 x i8], ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i64 0, i64 1), align 1, !tbaa !20
  %43 = sext i8 %42 to i32
  %44 = load i8, ptr getelementptr inbounds ([256 x i8], ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i64 0, i64 2), align 2, !tbaa !20
  %45 = sext i8 %44 to i32
  %46 = xor i32 %43, %45
  %47 = trunc i32 %46 to i8
  %48 = zext i8 %47 to i32
  %49 = icmp ne i32 %48, 255
  br i1 %49, label %53, label %50

50:                                               ; preds = %35
  %51 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE7msg_len, align 8, !tbaa !9
  %52 = icmp ult i64 %51, 14
  br i1 %52, label %53, label %59

53:                                               ; preds = %50, %35
  %54 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  %55 = getelementptr inbounds %"class.clearpath::Transport", ptr %5, i32 0, i32 4
  %56 = getelementptr inbounds [4 x i64], ptr %55, i64 0, i64 0
  %57 = load i64, ptr %56, align 8, !tbaa !9
  %58 = add i64 %57, %54
  store i64 %58, ptr %56, align 8, !tbaa !9
  store i64 0, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %53, %50
  br label %71

60:                                               ; preds = %17
  %61 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  %63 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  %64 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE7msg_len, align 8, !tbaa !9
  %65 = icmp ult i64 %63, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %60
  br label %71

67:                                               ; preds = %60
  store i64 0, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %68 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE7msg_len, align 8, !tbaa !9
  %69 = call noundef ptr @_ZN9clearpath7Message7factoryEPvm(ptr noundef @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i64 noundef %68)
  store ptr %69, ptr %4, align 8, !tbaa !5
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %70, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %73

71:                                               ; preds = %66, %59, %32, %31
  br label %10, !llvm.loop !21

72:                                               ; preds = %10
  store ptr null, ptr %2, align 8
  br label %73

73:                                               ; preds = %72, %67
  %74 = load ptr, ptr %2, align 8
  ret ptr %74
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare noundef i32 @_Z8ReadDataPvPci(ptr noundef, ptr noundef, i32 noundef) #3

declare noundef ptr @_ZN9clearpath7Message7factoryEPvm(ptr noundef, i64 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: write) }
attributes #3 = { "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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTSN9clearpath9TransportE", !13, i64 0, !6, i64 8, !14, i64 16, !15, i64 24, !7, i64 48}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTSNSt7__cxx114listIPN9clearpath7MessageESaIS3_EEE", !16, i64 0}
!16 = !{!"_ZTSNSt7__cxx1110_List_baseIPN9clearpath7MessageESaIS3_EEE", !17, i64 0}
!17 = !{!"_ZTSNSt7__cxx1110_List_baseIPN9clearpath7MessageESaIS3_EE10_List_implE", !18, i64 0}
!18 = !{!"_ZTSNSt8__detail17_List_node_headerE", !19, i64 0, !10, i64 16}
!19 = !{!"_ZTSNSt8__detail15_List_node_baseE", !6, i64 0, !6, i64 8}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

@_ZZN9clearpath9Transport9rxMessageEvE6rx_buf = external hidden global [256 x i8], align 16
@_ZZN9clearpath9Transport9rxMessageEvE6rx_inx = external hidden local_unnamed_addr global i64, align 8
@_ZZN9clearpath9Transport9rxMessageEvE7msg_len = external hidden local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN9clearpath9Transport9rxMessageEv(ptr nocapture noundef nonnull align 8 dereferenceable(80) %0) local_unnamed_addr #0 align 2 {
  %2 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !5
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %3, label %4

3:                                                ; preds = %1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i8 -70, i64 256, i1 false)
  br label %4

4:                                                ; preds = %3, %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i64 %2
  %8 = tail call noundef i32 @_Z8ReadDataPvPci(ptr noundef %6, ptr noundef nonnull %7, i32 noundef 1)
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  br label %11

11:                                               ; preds = %.lr.ph, %38
  %12 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !5
  switch i64 %12, label %32 [
    i64 0, label %13
    i64 1, label %20
    i64 2, label %21
  ]

13:                                               ; preds = %11
  %14 = load i8, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, align 16, !tbaa !19
  %15 = icmp eq i8 %14, -86
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  store i64 1, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !5
  br label %38

17:                                               ; preds = %13
  %18 = load i64, ptr %10, align 8, !tbaa !5
  %19 = add i64 %18, 1
  store i64 %19, ptr %10, align 8, !tbaa !5
  br label %38

20:                                               ; preds = %11
  store i64 2, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !5
  br label %38

21:                                               ; preds = %11
  store i64 3, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !5
  %22 = load i8, ptr getelementptr inbounds (i8, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i64 1), align 1, !tbaa !19
  %23 = sext i8 %22 to i64
  %24 = add nsw i64 %23, 3
  store i64 %24, ptr @_ZZN9clearpath9Transport9rxMessageEvE7msg_len, align 8, !tbaa !5
  %25 = load i8, ptr getelementptr inbounds (i8, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i64 2), align 2, !tbaa !19
  %26 = xor i8 %25, %22
  %27 = icmp ne i8 %26, -1
  %28 = icmp ult i64 %24, 14
  %or.cond = select i1 %27, i1 true, i1 %28
  br i1 %or.cond, label %29, label %38

29:                                               ; preds = %21
  %30 = load i64, ptr %10, align 8, !tbaa !5
  %31 = add i64 %30, 3
  store i64 %31, ptr %10, align 8, !tbaa !5
  store i64 0, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !5
  br label %38

32:                                               ; preds = %11
  %33 = add i64 %12, 1
  store i64 %33, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !5
  %34 = load i64, ptr @_ZZN9clearpath9Transport9rxMessageEvE7msg_len, align 8, !tbaa !5
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %38, label %36

36:                                               ; preds = %32
  store i64 0, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_inx, align 8, !tbaa !5
  %37 = tail call noundef ptr @_ZN9clearpath7Message7factoryEPvm(ptr noundef nonnull @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i64 noundef %34)
  br label %.loopexit

38:                                               ; preds = %32, %29, %21, %16, %17, %20
  %39 = phi i64 [ %33, %32 ], [ 0, %29 ], [ 3, %21 ], [ 1, %16 ], [ 0, %17 ], [ 2, %20 ]
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr @_ZZN9clearpath9Transport9rxMessageEvE6rx_buf, i64 %39
  %42 = tail call noundef i32 @_Z8ReadDataPvPci(ptr noundef %40, ptr noundef nonnull %41, i32 noundef 1)
  %43 = icmp eq i32 %42, 1
  br i1 %43, label %11, label %.loopexit, !llvm.loop !20

.loopexit:                                        ; preds = %38, %4, %36
  %.0 = phi ptr [ %37, %36 ], [ null, %4 ], [ null, %38 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

declare noundef i32 @_Z8ReadDataPvPci(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare noundef ptr @_ZN9clearpath7Message7factoryEPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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" }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"_ZTSN9clearpath9TransportE", !11, i64 0, !12, i64 8, !13, i64 16, !14, i64 24, !7, i64 48}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSNSt7__cxx114listIPN9clearpath7MessageESaIS3_EEE", !15, i64 0}
!15 = !{!"_ZTSNSt7__cxx1110_List_baseIPN9clearpath7MessageESaIS3_EEE", !16, i64 0}
!16 = !{!"_ZTSNSt7__cxx1110_List_baseIPN9clearpath7MessageESaIS3_EE10_List_implE", !17, i64 0}
!17 = !{!"_ZTSNSt8__detail17_List_node_headerE", !18, i64 0, !6, i64 16}
!18 = !{!"_ZTSNSt8__detail15_List_node_baseE", !12, i64 0, !12, i64 8}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass