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

; 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_char_array_s = type { ptr, i8, i64, i64, %struct.rcutils_allocator_s }
%struct.rcutils_allocator_s = type { ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1

declare void @rcutils_set_error_state(ptr noundef, ptr noundef, i64 noundef) #0

declare zeroext i1 @rcutils_allocator_is_valid(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @rcutils_char_array_fini(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %1
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr null, %7
  br i1 %8, label %9, label %12

9:                                                ; preds = %6
  br label %10

10:                                               ; preds = %9
  call void @rcutils_set_error_state(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 62)
  br label %11

11:                                               ; preds = %10
  store i32 2, ptr %2, align 4
  br label %47

12:                                               ; preds = %6
  br label %13

13:                                               ; preds = %12
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %14, i32 0, i32 1
  %16 = load i8, ptr %15, align 8, !tbaa !9, !range !14, !noundef !15
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %40

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %19, i32 0, i32 4
  store ptr %20, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call zeroext i1 @rcutils_allocator_is_valid(ptr noundef %21)
  br i1 %22, label %27, label %23

23:                                               ; preds = %18
  br label %24

24:                                               ; preds = %23
  call void @rcutils_set_error_state(ptr noundef @.str.2, ptr noundef @.str.1, i64 noundef 68)
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  store i32 2, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %37

27:                                               ; preds = %18
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.rcutils_allocator_s, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.rcutils_allocator_s, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  call void %30(ptr noundef %33, ptr noundef %36)
  store i32 0, ptr %5, align 4
  br label %37

37:                                               ; preds = %27, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %38 = load i32, ptr %5, align 4
  switch i32 %38, label %49 [
    i32 0, label %39
    i32 1, label %47
  ]

39:                                               ; preds = %37
  br label %40

40:                                               ; preds = %39, %13
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %41, i32 0, i32 0
  store ptr null, ptr %42, align 8, !tbaa !17
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %43, i32 0, i32 2
  store i64 0, ptr %44, align 8, !tbaa !19
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %45, i32 0, i32 3
  store i64 0, ptr %46, align 8, !tbaa !20
  store i32 0, ptr %2, align 4
  br label %47

47:                                               ; preds = %40, %37, %11
  %48 = load i32, ptr %2, align 4
  ret i32 %48

49:                                               ; preds = %37
  unreachable
}

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

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

attributes #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 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"rcutils_char_array_s", !6, i64 0, !11, i64 8, !12, i64 16, !12, i64 24, !13, i64 32}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"rcutils_allocator_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!13, !6, i64 8}
!17 = !{!10, !6, i64 0}
!18 = !{!13, !6, i64 32}
!19 = !{!10, !12, i64 16}
!20 = !{!10, !12, i64 24}


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

@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1

declare void @rcutils_set_error_state(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare zeroext i1 @rcutils_allocator_is_valid(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @rcutils_char_array_fini(ptr noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %3, label %4

3:                                                ; preds = %1
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 62) #3
  br label %19

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i8, ptr %5, align 8, !tbaa !5, !range !13, !noundef !14
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %8, label %17

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = tail call zeroext i1 @rcutils_allocator_is_valid(ptr noundef nonnull %9) #3
  br i1 %10, label %.thread, label %16

.thread:                                          ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = load ptr, ptr %0, align 8, !tbaa !16
  %14 = getelementptr inbounds i8, ptr %0, i64 64
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  tail call void %12(ptr noundef %13, ptr noundef %15) #3
  br label %17

16:                                               ; preds = %8
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i64 noundef 68) #3
  br label %19

17:                                               ; preds = %.thread, %4
  store ptr null, ptr %0, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %18, i8 0, i64 16, i1 false)
  br label %19

19:                                               ; preds = %16, %17, %3
  %.1 = phi i32 [ 2, %3 ], [ 2, %16 ], [ 0, %17 ]
  ret i32 %.1
}

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

attributes #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 = { 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: write) }
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, !10, i64 8}
!6 = !{!"rcutils_char_array_s", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 24, !12, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"rcutils_allocator_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!12, !7, i64 8}
!16 = !{!6, !7, i64 0}
!17 = !{!12, !7, i64 32}


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