; LLVM IR from nasa/astrobee :: shared/config_reader/src (watch_files)

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

%"class.config_reader::WatchFiles::Watch" = type <{ ptr, i32, [4 x i8] }>
%"class.config_reader::WatchFiles" = type { %"class.std::vector", i32, i32 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<inotify_event, std::allocator<inotify_event>>::_Vector_impl" }
%"struct.std::_Vector_base<inotify_event, std::allocator<inotify_event>>::_Vector_impl" = type { %"struct.std::_Vector_base<inotify_event, std::allocator<inotify_event>>::_Vector_impl_data" }
%"struct.std::_Vector_base<inotify_event, std::allocator<inotify_event>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; 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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN13config_reader10WatchFiles11removeWatchEPNS0_5WatchE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %"class.config_reader::WatchFiles::Watch", ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp ne ptr %10, %7
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %33

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %14 = getelementptr inbounds %"class.config_reader::WatchFiles", ptr %7, i32 0, i32 1
  %15 = load i32, ptr %14, align 8, !tbaa !12
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %"class.config_reader::WatchFiles::Watch", ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !18
  %19 = call i32 @inotify_rm_watch(i32 noundef %15, i32 noundef %18) #3
  store i32 %19, ptr %6, align 4, !tbaa !19
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.config_reader::WatchFiles::Watch", ptr %20, i32 0, i32 0
  store ptr null, ptr %21, align 8, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %"class.config_reader::WatchFiles::Watch", ptr %22, i32 0, i32 1
  store i32 -1, ptr %23, align 8, !tbaa !18
  %24 = load i32, ptr %6, align 4, !tbaa !19
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %30

26:                                               ; preds = %13
  %27 = getelementptr inbounds %"class.config_reader::WatchFiles", ptr %7, i32 0, i32 2
  %28 = load i32, ptr %27, align 4, !tbaa !20
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr %27, align 4, !tbaa !20
  br label %30

30:                                               ; preds = %26, %13
  %31 = load i32, ptr %6, align 4, !tbaa !19
  %32 = icmp eq i32 %31, 0
  store i1 %32, ptr %3, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %33

33:                                               ; preds = %30, %12
  %34 = load i1, ptr %3, align 1
  ret i1 %34
}

; Function Attrs: nounwind
declare i32 @inotify_rm_watch(i32 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN13config_reader10WatchFiles5WatchE", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 24}
!13 = !{!"_ZTSN13config_reader10WatchFilesE", !14, i64 0, !11, i64 24, !11, i64 28}
!14 = !{!"_ZTSSt6vectorI13inotify_eventSaIS0_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseI13inotify_eventSaIS0_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseI13inotify_eventSaIS0_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseI13inotify_eventSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!10, !11, i64 8}
!19 = !{!11, !11, i64 0}
!20 = !{!13, !11, i64 28}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN13config_reader10WatchFiles11removeWatchEPNS0_5WatchE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr nocapture noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %.not = icmp eq ptr %3, %0
  br i1 %.not, label %4, label %15

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i32, ptr %5, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !17
  %9 = tail call i32 @inotify_rm_watch(i32 noundef %6, i32 noundef %8) #2
  store ptr null, ptr %1, align 8, !tbaa !5
  store i32 -1, ptr %7, align 8, !tbaa !17
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %15

11:                                               ; preds = %4
  %12 = getelementptr inbounds i8, ptr %0, i64 28
  %13 = load i32, ptr %12, align 4, !tbaa !18
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr %12, align 4, !tbaa !18
  br label %15

15:                                               ; preds = %4, %11, %2
  %.0 = phi i1 [ false, %2 ], [ true, %11 ], [ false, %4 ]
  ret i1 %.0
}

; Function Attrs: nounwind
declare i32 @inotify_rm_watch(i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 #1 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTSN13config_reader10WatchFiles5WatchE", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_ZTSN13config_reader10WatchFilesE", !13, i64 0, !10, i64 24, !10, i64 28}
!13 = !{!"_ZTSSt6vectorI13inotify_eventSaIS0_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseI13inotify_eventSaIS0_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseI13inotify_eventSaIS0_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseI13inotify_eventSaIS0_EE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!17 = !{!6, !10, i64 8}
!18 = !{!12, !10, i64 28}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass