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

; 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_allocator_s = type { ptr, ptr, ptr, ptr, ptr }
%struct.rcutils_dir_iter_s = type { ptr, %struct.rcutils_allocator_s, ptr }
%struct.rcutils_dir_iter_state_s = type { ptr }

@.str.10 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 x i8], align 1

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

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

declare zeroext i1 @rcutils_allocator_is_valid(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @rcutils_dir_iter_end(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.rcutils_allocator_s, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp eq ptr null, %5
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  br label %51

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 40, ptr %3) #4
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.rcutils_dir_iter_s, ptr %9, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %10, i64 40, i1 false), !tbaa.struct !9
  %11 = call zeroext i1 @rcutils_allocator_is_valid(ptr noundef %3)
  br i1 %11, label %16, label %12

12:                                               ; preds = %8
  br label %13

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

14:                                               ; preds = %13
  br label %15

15:                                               ; preds = %14
  store i32 1, ptr %4, align 4
  br label %49

16:                                               ; preds = %8
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.rcutils_dir_iter_s, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !10
  %20 = icmp ne ptr null, %19
  br i1 %20, label %21, label %43

21:                                               ; preds = %16
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.rcutils_dir_iter_s, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !10
  %25 = getelementptr inbounds %struct.rcutils_dir_iter_state_s, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = icmp ne ptr null, %26
  br i1 %27, label %28, label %35

28:                                               ; preds = %21
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.rcutils_dir_iter_s, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !10
  %32 = getelementptr inbounds %struct.rcutils_dir_iter_state_s, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = call i32 @closedir(ptr noundef %33)
  br label %35

35:                                               ; preds = %28, %21
  %36 = getelementptr inbounds %struct.rcutils_allocator_s, ptr %3, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.rcutils_dir_iter_s, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !10
  %41 = getelementptr inbounds %struct.rcutils_allocator_s, ptr %3, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  call void %37(ptr noundef %40, ptr noundef %42)
  br label %43

43:                                               ; preds = %35, %16
  %44 = getelementptr inbounds %struct.rcutils_allocator_s, ptr %3, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.rcutils_allocator_s, ptr %3, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  call void %45(ptr noundef %46, ptr noundef %48)
  store i32 0, ptr %4, align 4
  br label %49

49:                                               ; preds = %43, %15
  call void @llvm.lifetime.end.p0(i64 40, ptr %3) #4
  %50 = load i32, ptr %4, align 4
  switch i32 %50, label %52 [
    i32 0, label %51
    i32 1, label %51
  ]

51:                                               ; preds = %49, %49, %7
  ret void

52:                                               ; preds = %49
  unreachable
}

declare void @rcutils_set_error_state(ptr noundef, ptr noundef, i64 noundef) #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) #3

declare i32 @closedir(ptr noundef) #1

attributes #0 = { nocallback nofree nosync 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 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 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 8, !5, i64 32, i64 8, !5}
!10 = !{!11, !6, i64 48}
!11 = !{!"rcutils_dir_iter_s", !6, i64 0, !12, i64 8, !6, i64 48}
!12 = !{!"rcutils_allocator_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!14, !6, i64 0}
!14 = !{!"rcutils_dir_iter_state_s", !6, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !6, i64 32}


; 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_allocator_s = type { ptr, ptr, ptr, ptr, ptr }

@.str.10 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @rcutils_dir_iter_end(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca %struct.rcutils_allocator_s, align 8
  %3 = icmp eq ptr %0, null
  br i1 %3, label %27, label %4

4:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %2) #5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %2, ptr noundef nonnull align 8 dereferenceable(40) %5, i64 40, i1 false), !tbaa.struct !5
  %6 = call zeroext i1 @rcutils_allocator_is_valid(ptr noundef nonnull %2) #5
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  call void @rcutils_set_error_state(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.10, i64 noundef 506) #5
  br label %26

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  %10 = load ptr, ptr %9, align 8, !tbaa !10
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %21, label %11

11:                                               ; preds = %8
  %12 = load ptr, ptr %10, align 8, !tbaa !13
  %.not9 = icmp eq ptr %12, null
  br i1 %.not9, label %15, label %13

13:                                               ; preds = %11
  %14 = call i32 @closedir(ptr noundef nonnull %12)
  %.pre = load ptr, ptr %9, align 8, !tbaa !10
  br label %15

15:                                               ; preds = %13, %11
  %16 = phi ptr [ %.pre, %13 ], [ %10, %11 ]
  %17 = getelementptr inbounds i8, ptr %2, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %2, i64 32
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  call void %18(ptr noundef %16, ptr noundef %20) #5
  br label %21

21:                                               ; preds = %15, %8
  %22 = getelementptr inbounds i8, ptr %2, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %2, i64 32
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  call void %23(ptr noundef nonnull %0, ptr noundef %25) #5
  br label %26

26:                                               ; preds = %21, %7
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %2) #5
  br label %27

27:                                               ; preds = %1, %26
  ret void
}

declare void @rcutils_set_error_state(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #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) #3

; Function Attrs: nofree nounwind
declare noundef i32 @closedir(ptr nocapture noundef) local_unnamed_addr #4

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass