; LLVM IR from ros2/rcutils :: src (error_handling)

; 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"

%struct.rcutils_error_string_s = type { [1024 x i8] }
%struct.rcutils_error_state_s = type { [768 x i8], [229 x i8], i64 }

@gtls_rcutils_error_string_is_formatted = external dso_local thread_local global i8, align 1
@gtls_rcutils_error_is_set = external dso_local thread_local global i8, align 1
@gtls_rcutils_error_string = external dso_local thread_local global %struct.rcutils_error_string_s, align 1
@gtls_rcutils_error_state = external dso_local thread_local global %struct.rcutils_error_state_s, align 8
@.str.5 = external hidden unnamed_addr constant [1024 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: nounwind uwtable
define dso_local void @rcutils_reset_error() #1 {
  %1 = alloca %struct.rcutils_error_state_s, align 8
  %2 = alloca %struct.rcutils_error_string_s, align 1
  %3 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @gtls_rcutils_error_state)
  call void @llvm.memset.p0.i64(ptr align 8 %1, i8 0, i64 1008, i1 false)
  %4 = getelementptr inbounds %struct.rcutils_error_state_s, ptr %1, i32 0, i32 0
  %5 = getelementptr inbounds %struct.rcutils_error_state_s, ptr %1, i32 0, i32 1
  %6 = getelementptr inbounds %struct.rcutils_error_state_s, ptr %1, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %1, i64 1008, i1 false), !tbaa.struct !5
  %7 = call align 1 ptr @llvm.threadlocal.address.p0(ptr align 1 @gtls_rcutils_error_string_is_formatted)
  store i8 0, ptr %7, align 1, !tbaa !11
  %8 = call align 1 ptr @llvm.threadlocal.address.p0(ptr align 1 @gtls_rcutils_error_string)
  %9 = getelementptr inbounds %struct.rcutils_error_string_s, ptr %2, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %9, ptr align 1 @.str.5, i64 1024, i1 false), !tbaa.struct !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %8, ptr align 1 %2, i64 1024, i1 false), !tbaa.struct !13
  %10 = call align 1 ptr @llvm.threadlocal.address.p0(ptr align 1 @gtls_rcutils_error_is_set)
  store i8 0, ptr %10, align 1, !tbaa !11
  ret void
}

; 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) #2

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

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{i64 0, i64 768, !6, i64 768, i64 229, !6, i64 1000, i64 8, !9}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i64 0, i64 1024, !6}


; 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"

%struct.rcutils_error_string_s = type { [1024 x i8] }
%struct.rcutils_error_state_s = type { [768 x i8], [229 x i8], i64 }

@gtls_rcutils_error_string_is_formatted = external dso_local thread_local local_unnamed_addr global i8, align 1
@gtls_rcutils_error_is_set = external dso_local thread_local local_unnamed_addr global i8, align 1
@gtls_rcutils_error_string = external dso_local thread_local local_unnamed_addr global %struct.rcutils_error_string_s, align 1
@gtls_rcutils_error_state = external dso_local thread_local local_unnamed_addr global %struct.rcutils_error_state_s, align 8
@.str.5 = external hidden unnamed_addr constant [1024 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @rcutils_reset_error() local_unnamed_addr #1 {
  %1 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @gtls_rcutils_error_state)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1008) %1, i8 0, i64 1008, i1 false)
  %2 = tail call align 1 ptr @llvm.threadlocal.address.p0(ptr align 1 @gtls_rcutils_error_string_is_formatted)
  store i8 0, ptr %2, align 1, !tbaa !5
  %3 = tail call align 1 ptr @llvm.threadlocal.address.p0(ptr align 1 @gtls_rcutils_error_string)
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1024) %3, ptr noundef nonnull align 1 dereferenceable(1024) @.str.5, i64 1024, i1 false), !tbaa.struct !9
  %4 = tail call align 1 ptr @llvm.threadlocal.address.p0(ptr align 1 @gtls_rcutils_error_is_set)
  store i8 0, ptr %4, align 1, !tbaa !5
  ret void
}

; Function Attrs: mustprogress 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) #2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

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


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass