; 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.1 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [59 x i8], align 1

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

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

; 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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rcutils_char_array_vsprintf(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = call i32 @_rcutils_char_array_vsprintf(ptr noundef %12, ptr noundef %13, ptr noundef %14)
  store i32 %15, ptr %8, align 4, !tbaa !9
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %3
  br label %19

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

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  store i32 2, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %68

22:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = add i64 %24, 1
  store i64 %25, ptr %10, align 8, !tbaa !11
  %26 = load i64, ptr %10, align 8, !tbaa !11
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %27, i32 0, i32 3
  %29 = load i64, ptr %28, align 8, !tbaa !13
  %30 = icmp ugt i64 %26, %29
  br i1 %30, label %31, label %63

31:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i64, ptr %10, align 8, !tbaa !11
  %34 = call i32 @rcutils_char_array_expand_as_needed(ptr noundef %32, i64 noundef %33)
  store i32 %34, ptr %11, align 4, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %31
  %38 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %38, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %60

39:                                               ; preds = %31
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = call i32 @_rcutils_char_array_vsprintf(ptr noundef %40, ptr noundef %41, ptr noundef %42)
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = icmp ne i32 %43, %44
  br i1 %45, label %46, label %59

46:                                               ; preds = %39
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = call i32 @rcutils_char_array_fini(ptr noundef %47)
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %54

50:                                               ; preds = %46
  br label %51

51:                                               ; preds = %50
  call void @rcutils_set_error_state(ptr noundef @.str.7, ptr noundef @.str.1, i64 noundef 181)
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  br label %58

54:                                               ; preds = %46
  br label %55

55:                                               ; preds = %54
  call void @rcutils_set_error_state(ptr noundef @.str.8, ptr noundef @.str.1, i64 noundef 183)
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57, %53
  store i32 2, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %60

59:                                               ; preds = %39
  store i32 0, ptr %9, align 4
  br label %60

60:                                               ; preds = %59, %58, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %61 = load i32, ptr %9, align 4
  switch i32 %61, label %67 [
    i32 0, label %62
  ]

62:                                               ; preds = %60
  br label %63

63:                                               ; preds = %62, %22
  %64 = load i64, ptr %10, align 8, !tbaa !11
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.rcutils_char_array_s, ptr %65, i32 0, i32 2
  store i64 %64, ptr %66, align 8, !tbaa !17
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %67

67:                                               ; preds = %63, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %68

68:                                               ; preds = %67, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %69 = load i32, ptr %4, align 4
  ret i32 %69
}

; Function Attrs: nounwind uwtable
declare hidden i32 @_rcutils_char_array_vsprintf(ptr noundef, ptr noundef, ptr noundef) #1

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 24}
!14 = !{!"rcutils_char_array_s", !6, i64 0, !15, i64 8, !12, i64 16, !12, i64 24, !16, i64 32}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"rcutils_allocator_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!17 = !{!14, !12, i64 16}


; 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.1 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [59 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rcutils_char_array_vsprintf(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 @_rcutils_char_array_vsprintf(ptr noundef %0, ptr noundef %1, ptr noundef %2)
  %5 = icmp slt i32 %4, 0
  br i1 %5, label %6, label %7

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

7:                                                ; preds = %3
  %narrow = add nuw i32 %4, 1
  %8 = zext i32 %narrow to i64
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = icmp ult i64 %10, %8
  br i1 %11, label %12, label %21

12:                                               ; preds = %7
  %13 = tail call i32 @rcutils_char_array_expand_as_needed(ptr noundef nonnull %0, i64 noundef %8)
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %14, label %.thread

14:                                               ; preds = %12
  %15 = tail call i32 @_rcutils_char_array_vsprintf(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2)
  %.not23 = icmp eq i32 %15, %4
  br i1 %.not23, label %21, label %16

16:                                               ; preds = %14
  %17 = tail call i32 @rcutils_char_array_fini(ptr noundef nonnull %0)
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

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

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

21:                                               ; preds = %14, %7
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %8, ptr %22, align 8, !tbaa !13
  br label %.thread

.thread:                                          ; preds = %19, %20, %12, %21, %6
  %.2 = phi i32 [ 2, %6 ], [ 0, %21 ], [ 2, %19 ], [ 2, %20 ], [ %13, %12 ]
  ret i32 %.2
}

; Function Attrs: nounwind uwtable
declare hidden i32 @_rcutils_char_array_vsprintf(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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 = { 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, !11, i64 16}


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