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

; 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::Message" = type <{ ptr, [256 x i8], i64, i8, [7 x i8] }>

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9clearpath7Message9setLengthEh(ptr noundef nonnull align 8 dereferenceable(273) %0, i8 noundef zeroext %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %8 = load i8, ptr %4, align 1, !tbaa !9
  %9 = zext i8 %8 to i32
  %10 = add nsw i32 %9, 3
  %11 = sext i32 %10 to i64
  store i64 %11, ptr %5, align 8, !tbaa !10
  %12 = load i64, ptr %5, align 8, !tbaa !10
  %13 = icmp ugt i64 %12, 256
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i32 1, ptr %6, align 4
  br label %27

15:                                               ; preds = %2
  %16 = load i64, ptr %5, align 8, !tbaa !10
  %17 = getelementptr inbounds %"class.clearpath::Message", ptr %7, i32 0, i32 2
  store i64 %16, ptr %17, align 8, !tbaa !12
  %18 = load i8, ptr %4, align 1, !tbaa !9
  %19 = getelementptr inbounds %"class.clearpath::Message", ptr %7, i32 0, i32 1
  %20 = getelementptr inbounds [256 x i8], ptr %19, i64 0, i64 1
  store i8 %18, ptr %20, align 1, !tbaa !9
  %21 = load i8, ptr %4, align 1, !tbaa !9
  %22 = zext i8 %21 to i32
  %23 = xor i32 %22, -1
  %24 = trunc i32 %23 to i8
  %25 = getelementptr inbounds %"class.clearpath::Message", ptr %7, i32 0, i32 1
  %26 = getelementptr inbounds [256 x i8], ptr %25, i64 0, i64 2
  store i8 %24, ptr %26, align 2, !tbaa !9
  store i32 0, ptr %6, align 4
  br label %27

27:                                               ; preds = %15, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  %28 = load i32, ptr %6, align 4
  switch i32 %28, label %30 [
    i32 0, label %29
    i32 1, label %29
  ]

29:                                               ; preds = %27, %27
  ret void

30:                                               ; preds = %27
  unreachable
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !11, i64 264}
!13 = !{!"_ZTSN9clearpath7MessageE", !7, i64 8, !11, i64 264, !14, i64 272}
!14 = !{!"bool", !7, 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @_ZN9clearpath7Message9setLengthEh(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(273) %0, i8 noundef zeroext %1) local_unnamed_addr #0 align 2 {
  %3 = icmp ugt i8 %1, -3
  br i1 %3, label %11, label %4

4:                                                ; preds = %2
  %5 = zext i8 %1 to i64
  %6 = add nuw nsw i64 %5, 3
  %7 = getelementptr inbounds i8, ptr %0, i64 264
  store i64 %6, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 9
  store i8 %1, ptr %8, align 1, !tbaa !11
  %9 = xor i8 %1, -1
  %10 = getelementptr inbounds i8, ptr %0, i64 10
  store i8 %9, ptr %10, align 2, !tbaa !11
  br label %11

11:                                               ; preds = %2, %4
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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, !9, i64 264}
!6 = !{!"_ZTSN9clearpath7MessageE", !7, i64 8, !9, i64 264, !10, i64 272}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass