; 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
@.str.4 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [43 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @rcutils_char_array_init(ptr noundef, i64 noundef, ptr noundef) #1

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

declare zeroext i1 @rcutils_allocator_is_valid(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rcutils_char_array_resize(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  br label %18

18:                                               ; preds = %17
  call void @rcutils_set_error_state(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 83)
  br label %19

19:                                               ; preds = %18
  store i32 2, ptr %3, align 4
  br label %131

20:                                               ; preds = %14
  br label %21

21:                                               ; preds = %20
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = icmp eq i64 0, %22
  br i1 %23, label %24, label %27

24:                                               ; preds = %21
  br label %25

25:                                               ; preds = %24
  call void @rcutils_set_error_state(ptr noundef @.str.4, ptr noundef @.str.1, i64 noundef 86)
  br label %26

26:                                               ; preds = %25
  store i32 11, ptr %3, align 4
  br label %131

27:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %28, i32 0, i32 4
  store ptr %29, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call zeroext i1 @rcutils_allocator_is_valid(ptr noundef %30)
  br i1 %31, label %36, label %32

32:                                               ; preds = %27
  br label %33

33:                                               ; preds = %32
  call void @rcutils_set_error_state(ptr noundef @.str.2, ptr noundef @.str.1, i64 noundef 93)
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  store i32 2, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %130

36:                                               ; preds = %27
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %38, i32 0, i32 3
  %40 = load i64, ptr %39, align 8, !tbaa !11
  %41 = icmp eq i64 %37, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %36
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %130

43:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  store ptr %46, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %47, i32 0, i32 3
  %49 = load i64, ptr %48, align 8, !tbaa !11
  store i64 %49, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !16
  store i64 %52, ptr %10, align 8, !tbaa !9
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %53, i32 0, i32 1
  %55 = load i8, ptr %54, align 8, !tbaa !17, !range !18, !noundef !19
  %56 = trunc i8 %55 to i1
  br i1 %56, label %57, label %81

57:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = mul i64 %61, 1
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = call ptr @rcutils_reallocf(ptr noundef %60, i64 noundef %62, ptr noundef %63)
  store ptr %64, ptr %11, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %57
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = icmp eq ptr null, %66
  br i1 %67, label %68, label %72

68:                                               ; preds = %65
  br label %69

69:                                               ; preds = %68
  call void @rcutils_set_error_state(ptr noundef @.str.5, ptr noundef @.str.1, i64 noundef 109)
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70
  store i32 10, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %78

72:                                               ; preds = %65
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %76, i32 0, i32 0
  store ptr %75, ptr %77, align 8, !tbaa !15
  store i32 0, ptr %7, align 4
  br label %78

78:                                               ; preds = %74, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %79 = load i32, ptr %7, align 4
  switch i32 %79, label %129 [
    i32 0, label %80
  ]

80:                                               ; preds = %78
  br label %114

81:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = load i64, ptr %5, align 8, !tbaa !9
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = call i32 @rcutils_char_array_init(ptr noundef %82, i64 noundef %83, ptr noundef %84)
  store i32 %85, ptr %12, align 4, !tbaa !20
  %86 = load i32, ptr %12, align 4, !tbaa !20
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %90

88:                                               ; preds = %81
  %89 = load i32, ptr %12, align 4, !tbaa !20
  store i32 %89, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %111

90:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %91 = load i64, ptr %5, align 8, !tbaa !9
  %92 = load i64, ptr %9, align 8, !tbaa !9
  %93 = icmp ult i64 %91, %92
  br i1 %93, label %94, label %96

94:                                               ; preds = %90
  %95 = load i64, ptr %5, align 8, !tbaa !9
  br label %98

96:                                               ; preds = %90
  %97 = load i64, ptr %9, align 8, !tbaa !9
  br label %98

98:                                               ; preds = %96, %94
  %99 = phi i64 [ %95, %94 ], [ %97, %96 ]
  store i64 %99, ptr %13, align 8, !tbaa !9
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %100, i32 0, i32 0
  %102 = load ptr, ptr %101, align 8, !tbaa !15
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = load i64, ptr %13, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %102, ptr align 1 %103, i64 %104, i1 false)
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %105, i32 0, i32 0
  %107 = load ptr, ptr %106, align 8, !tbaa !15
  %108 = load i64, ptr %13, align 8, !tbaa !9
  %109 = sub i64 %108, 1
  %110 = getelementptr inbounds i8, ptr %107, i64 %109
  store i8 0, ptr %110, align 1, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  store i32 0, ptr %7, align 4
  br label %111

111:                                              ; preds = %98, %88
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %112 = load i32, ptr %7, align 4
  switch i32 %112, label %129 [
    i32 0, label %113
  ]

113:                                              ; preds = %111
  br label %114

114:                                              ; preds = %113, %80
  %115 = load i64, ptr %5, align 8, !tbaa !9
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %116, i32 0, i32 3
  store i64 %115, ptr %117, align 8, !tbaa !11
  %118 = load i64, ptr %5, align 8, !tbaa !9
  %119 = load i64, ptr %10, align 8, !tbaa !9
  %120 = icmp ult i64 %118, %119
  br i1 %120, label %121, label %123

121:                                              ; preds = %114
  %122 = load i64, ptr %5, align 8, !tbaa !9
  br label %125

123:                                              ; preds = %114
  %124 = load i64, ptr %10, align 8, !tbaa !9
  br label %125

125:                                              ; preds = %123, %121
  %126 = phi i64 [ %122, %121 ], [ %124, %123 ]
  %127 = load ptr, ptr %4, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %127, i32 0, i32 2
  store i64 %126, ptr %128, align 8, !tbaa !16
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %129

129:                                              ; preds = %125, %111, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %130

130:                                              ; preds = %129, %42, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %131

131:                                              ; preds = %130, %26, %19
  %132 = load i32, ptr %3, align 4
  ret i32 %132
}

declare ptr @rcutils_reallocf(ptr noundef, i64 noundef, ptr noundef) #2

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

@.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
@.str.4 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [43 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @rcutils_char_array_init(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

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

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

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

4:                                                ; preds = %2
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 83) #4
  br label %.critedge

5:                                                ; preds = %2
  %6 = icmp eq i64 %1, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %5
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i64 noundef 86) #4
  br label %.critedge

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

11:                                               ; preds = %8
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i64 noundef 93) #4
  br label %.critedge

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = icmp eq i64 %14, %1
  br i1 %15, label %.critedge, label %16

16:                                               ; preds = %12
  %17 = load ptr, ptr %0, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = load i64, ptr %18, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i8, ptr %20, align 8, !tbaa !15, !range !16, !noundef !17
  %22 = trunc nuw i8 %21 to i1
  br i1 %22, label %23, label %26

23:                                               ; preds = %16
  %24 = tail call ptr @rcutils_reallocf(ptr noundef %17, i64 noundef %1, ptr noundef nonnull %9) #4
  %.not45 = icmp eq ptr %24, null
  br i1 %.not45, label %.thread, label %25

.thread:                                          ; preds = %23
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i64 noundef 109) #4
  br label %.critedge

25:                                               ; preds = %23
  store ptr %24, ptr %0, align 8, !tbaa !13
  br label %34

26:                                               ; preds = %16
  %27 = tail call i32 @rcutils_char_array_init(ptr noundef nonnull %0, i64 noundef %1, ptr noundef nonnull %9)
  %.not = icmp eq i32 %27, 0
  br i1 %.not, label %28, label %.critedge

28:                                               ; preds = %26
  %29 = tail call i64 @llvm.umin.i64(i64 %14, i64 %1)
  %30 = load ptr, ptr %0, align 8, !tbaa !13
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %30, ptr align 1 %17, i64 %29, i1 false)
  %31 = load ptr, ptr %0, align 8, !tbaa !13
  %32 = getelementptr i8, ptr %31, i64 %29
  %33 = getelementptr i8, ptr %32, i64 -1
  store i8 0, ptr %33, align 1, !tbaa !18
  br label %34

34:                                               ; preds = %25, %28
  store i64 %1, ptr %13, align 8, !tbaa !5
  %35 = tail call i64 @llvm.umin.i64(i64 %19, i64 %1)
  store i64 %35, ptr %18, align 8, !tbaa !14
  br label %.critedge

.critedge:                                        ; preds = %.thread, %11, %12, %26, %34, %7, %4
  %.4 = phi i32 [ 2, %4 ], [ 11, %7 ], [ 2, %11 ], [ 0, %12 ], [ 0, %34 ], [ %27, %26 ], [ 10, %.thread ]
  ret i32 %.4
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #3

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !11, i64 24}
!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 = !{!6, !7, i64 0}
!14 = !{!6, !11, i64 16}
!15 = !{!6, !10, i64 8}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!8, !8, i64 0}


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