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

; 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" = 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 }
%struct.inotify_event = type { i32, i32, i32, i32, [0 x i8] }

; 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
declare dso_local noundef i64 @_ZNKSt6vectorI13inotify_eventSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN13config_reader10WatchFiles9getEventsEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca [512 x i8], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 512, ptr %3) #4
  br label %9

9:                                                ; preds = %43, %1
  br label %10

10:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %11 = getelementptr inbounds %"class.config_reader::WatchFiles", ptr %8, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds [512 x i8], ptr %3, i64 0, i64 0
  %14 = call i64 @read(i32 noundef %12, ptr noundef %13, i64 noundef 512)
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %4, align 4, !tbaa !16
  %16 = load i32, ptr %4, align 4, !tbaa !16
  %17 = icmp slt i32 %16, 16
  br i1 %17, label %18, label %19

18:                                               ; preds = %10
  store i32 3, ptr %5, align 4
  br label %41

19:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !16
  br label %20

20:                                               ; preds = %24, %19
  %21 = load i32, ptr %6, align 4, !tbaa !16
  %22 = load i32, ptr %4, align 4, !tbaa !16
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %40

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %25 = getelementptr inbounds [512 x i8], ptr %3, i64 0, i64 0
  %26 = load i32, ptr %6, align 4, !tbaa !16
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  store ptr %28, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.config_reader::WatchFiles", ptr %8, i32 0, i32 0
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZNSt6vectorI13inotify_eventSaIS0_EE9push_backERKS0_(ptr noundef nonnull align 8 dereferenceable(24) %29, ptr noundef nonnull align 4 dereferenceable(16) %30)
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.inotify_event, ptr %31, i32 0, i32 3
  %33 = load i32, ptr %32, align 4, !tbaa !16
  %34 = zext i32 %33 to i64
  %35 = add i64 16, %34
  %36 = load i32, ptr %6, align 4, !tbaa !16
  %37 = sext i32 %36 to i64
  %38 = add i64 %37, %35
  %39 = trunc i64 %38 to i32
  store i32 %39, ptr %6, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %20, !llvm.loop !17

40:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  store i32 0, ptr %5, align 4
  br label %41

41:                                               ; preds = %40, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %42 = load i32, ptr %5, align 4
  switch i32 %42, label %48 [
    i32 0, label %43
    i32 3, label %44
  ]

43:                                               ; preds = %41
  br label %9, !llvm.loop !19

44:                                               ; preds = %41
  %45 = getelementptr inbounds %"class.config_reader::WatchFiles", ptr %8, i32 0, i32 0
  %46 = call noundef i64 @_ZNKSt6vectorI13inotify_eventSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %45) #4
  %47 = trunc i64 %46 to i32
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 512, ptr %3) #4
  ret i32 %47

48:                                               ; preds = %41
  unreachable
}

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorI13inotify_eventSaIS0_EE9push_backERKS0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(16)) #2 align 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 = { mustprogress 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 = { "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 #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++ TBAA"}
!9 = !{!10, !15, i64 24}
!10 = !{!"_ZTSN13config_reader10WatchFilesE", !11, i64 0, !15, i64 24, !15, i64 28}
!11 = !{!"_ZTSSt6vectorI13inotify_eventSaIS0_EE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseI13inotify_eventSaIS0_EE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseI13inotify_eventSaIS0_EE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseI13inotify_eventSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!"int", !7, i64 0}
!16 = !{!15, !15, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI13inotify_eventSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN13config_reader10WatchFiles9getEventsEv(ptr noundef nonnull align 8 dereferenceable(32) %0) local_unnamed_addr #2 align 2 {
  %2 = alloca [512 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 512, ptr nonnull %2) #4
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = call i64 @read(i32 noundef %4, ptr noundef nonnull %2, i64 noundef 512)
  %6 = trunc i64 %5 to i32
  %7 = icmp slt i32 %6, 16
  br i1 %7, label %._crit_edge, label %.preheader

.loopexit:                                        ; preds = %13
  %8 = load i32, ptr %3, align 8, !tbaa !5
  %9 = call i64 @read(i32 noundef %8, ptr noundef nonnull %2, i64 noundef 512)
  %10 = trunc i64 %9 to i32
  %11 = icmp slt i32 %10, 16
  br i1 %11, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %1, %.loopexit
  %12 = phi i32 [ %10, %.loopexit ], [ %6, %1 ]
  br label %13

13:                                               ; preds = %.preheader, %13
  %.0812 = phi i32 [ 0, %.preheader ], [ %19, %13 ]
  %14 = sext i32 %.0812 to i64
  %15 = getelementptr inbounds i8, ptr %2, i64 %14
  call void @_ZNSt6vectorI13inotify_eventSaIS0_EE9push_backERKS0_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 4 dereferenceable(16) %15)
  %16 = getelementptr inbounds i8, ptr %15, i64 12
  %17 = load i32, ptr %16, align 4, !tbaa !15
  %18 = add i32 %.0812, 16
  %19 = add i32 %18, %17
  %20 = icmp slt i32 %19, %12
  br i1 %20, label %13, label %.loopexit, !llvm.loop !16

._crit_edge:                                      ; preds = %.loopexit, %1
  %21 = call noundef i64 @_ZNKSt6vectorI13inotify_eventSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  %22 = trunc i64 %21 to i32
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %2) #4
  ret i32 %22
}

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorI13inotify_eventSaIS0_EE9push_backERKS0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #2 align 2

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass