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

; 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_array_list_s = type { ptr }
%struct.rcutils_array_list_impl_s = type { i64, i64, ptr, 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.7 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [22 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

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

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

9:                                                ; preds = %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr null, %10
  br i1 %11, label %12, label %15

12:                                               ; preds = %9
  br label %13

13:                                               ; preds = %12
  call void @rcutils_set_error_state(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 132)
  br label %14

14:                                               ; preds = %13
  store i32 11, ptr %3, align 4
  br label %76

15:                                               ; preds = %9
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.rcutils_array_list_s, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = icmp eq ptr null, %19
  br i1 %20, label %21, label %24

21:                                               ; preds = %16
  br label %22

22:                                               ; preds = %21
  call void @rcutils_set_error_state(ptr noundef @.str.7, ptr noundef @.str.1, i64 noundef 132)
  br label %23

23:                                               ; preds = %22
  store i32 13, ptr %3, align 4
  br label %76

24:                                               ; preds = %16
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = icmp eq ptr null, %26
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  br label %29

29:                                               ; preds = %28
  call void @rcutils_set_error_state(ptr noundef @.str.8, ptr noundef @.str.1, i64 noundef 133)
  br label %30

30:                                               ; preds = %29
  store i32 11, ptr %3, align 4
  br label %76

31:                                               ; preds = %25
  br label %32

32:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !11
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.rcutils_array_list_s, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.rcutils_array_list_impl_s, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !13
  %38 = add i64 %37, 1
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.rcutils_array_list_s, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.rcutils_array_list_impl_s, ptr %41, i32 0, i32 1
  %43 = load i64, ptr %42, align 8, !tbaa !17
  %44 = icmp ugt i64 %38, %43
  br i1 %44, label %45, label %53

45:                                               ; preds = %32
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = call i32 @rcutils_array_list_increase_capacity(ptr noundef %46)
  store i32 %47, ptr %6, align 4, !tbaa !11
  %48 = load i32, ptr %6, align 4, !tbaa !11
  %49 = icmp ne i32 0, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %45
  %51 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %51, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %75

52:                                               ; preds = %45
  br label %53

53:                                               ; preds = %52, %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.rcutils_array_list_s, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.rcutils_array_list_impl_s, ptr %57, i32 0, i32 0
  %59 = load i64, ptr %58, align 8, !tbaa !13
  %60 = call ptr @rcutils_array_list_get_pointer_for_index(ptr noundef %54, i64 noundef %59)
  store ptr %60, ptr %8, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.rcutils_array_list_s, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.rcutils_array_list_impl_s, ptr %65, i32 0, i32 3
  %67 = load i64, ptr %66, align 8, !tbaa !18
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %61, ptr align 1 %62, i64 %67, i1 false)
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.rcutils_array_list_s, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.rcutils_array_list_impl_s, ptr %70, i32 0, i32 0
  %72 = load i64, ptr %71, align 8, !tbaa !13
  %73 = add i64 %72, 1
  store i64 %73, ptr %71, align 8, !tbaa !13
  %74 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %74, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %75

75:                                               ; preds = %53, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %76

76:                                               ; preds = %75, %30, %23, %14
  %77 = load i32, ptr %3, align 4
  ret i32 %77
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @rcutils_array_list_increase_capacity(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @rcutils_array_list_get_pointer_for_index(ptr noundef, i64 noundef) #2

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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, !6, i64 0}
!10 = !{!"rcutils_array_list_s", !6, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"rcutils_array_list_impl_s", !15, i64 0, !15, i64 8, !6, i64 16, !15, i64 24, !16, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!"rcutils_allocator_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!17 = !{!14, !15, i64 8}
!18 = !{!14, !15, 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.7 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [22 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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rcutils_array_list_add(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #2 {
  %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 132) #3
  br label %29

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

8:                                                ; preds = %5
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.1, i64 noundef 132) #3
  br label %29

9:                                                ; preds = %5
  %10 = icmp eq ptr %1, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %9
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i64 noundef 133) #3
  br label %29

12:                                               ; preds = %9
  %13 = load i64, ptr %6, align 8, !tbaa !10
  %14 = add i64 %13, 1
  %15 = getelementptr inbounds i8, ptr %6, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !14
  %17 = icmp ugt i64 %14, %16
  br i1 %17, label %18, label %20

18:                                               ; preds = %12
  %19 = tail call i32 @rcutils_array_list_increase_capacity(ptr noundef nonnull %0)
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %._crit_edge, label %29

._crit_edge:                                      ; preds = %18
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  %.pre21 = load i64, ptr %.pre, align 8, !tbaa !10
  br label %20

20:                                               ; preds = %._crit_edge, %12
  %21 = phi i64 [ %.pre21, %._crit_edge ], [ %13, %12 ]
  %22 = tail call ptr @rcutils_array_list_get_pointer_for_index(ptr noundef nonnull %0, i64 noundef %21)
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 24
  %25 = load i64, ptr %24, align 8, !tbaa !15
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %22, ptr nonnull align 1 %1, i64 %25, i1 false)
  %26 = load ptr, ptr %0, align 8, !tbaa !5
  %27 = load i64, ptr %26, align 8, !tbaa !10
  %28 = add i64 %27, 1
  store i64 %28, ptr %26, align 8, !tbaa !10
  br label %29

29:                                               ; preds = %20, %18, %11, %8, %4
  %.1 = phi i32 [ 11, %4 ], [ 13, %8 ], [ 11, %11 ], [ 0, %20 ], [ %19, %18 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @rcutils_array_list_increase_capacity(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden ptr @rcutils_array_list_get_pointer_for_index(ptr noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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, !7, i64 0}
!6 = !{!"rcutils_array_list_s", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"rcutils_array_list_impl_s", !12, i64 0, !12, i64 8, !7, i64 16, !12, i64 24, !13, i64 32}
!12 = !{!"long", !8, i64 0}
!13 = !{!"rcutils_allocator_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!14 = !{!11, !12, i64 8}
!15 = !{!11, !12, i64 24}


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