; LLVM IR from MiRoboticsLab/cyberdog_ros2 :: cyberdog_interaction/cyberdog_touch/src (TouchSensorHandler)

; 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.TouchSensorHandler = type { %class.InputEventCircularReader, i32, %struct.input_event, %struct.pollfd }
%class.InputEventCircularReader = type { ptr, ptr, ptr, ptr, i64 }
%struct.input_event = type { %struct.timeval, i16, i16, i32 }
%struct.timeval = type { i64, i64 }
%struct.pollfd = type { i32, i16, i16 }

@.str = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN18TouchSensorHandler13processEventsEP11input_eventi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, i32 noundef) #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN18TouchSensorHandler15pollTouchEventsEP11input_eventi(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %70, %3
  %15 = getelementptr inbounds %class.TouchSensorHandler, ptr %13, i32 0, i32 3
  %16 = getelementptr inbounds %struct.pollfd, ptr %15, i32 0, i32 2
  %17 = load i16, ptr %16, align 2, !tbaa !11
  %18 = sext i16 %17 to i32
  %19 = and i32 %18, 1
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %38

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = call noundef i32 @_ZN18TouchSensorHandler13processEventsEP11input_eventi(ptr noundef nonnull align 8 dereferenceable(80) %13, ptr noundef %22, i32 noundef %23)
  store i32 %24, ptr %10, align 4, !tbaa !9
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp sle i32 %25, %26
  br i1 %27, label %28, label %31

28:                                               ; preds = %21
  %29 = getelementptr inbounds %class.TouchSensorHandler, ptr %13, i32 0, i32 3
  %30 = getelementptr inbounds %struct.pollfd, ptr %29, i32 0, i32 2
  store i16 0, ptr %30, align 2, !tbaa !11
  br label %31

31:                                               ; preds = %28, %21
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = sub nsw i32 %33, %32
  store i32 %34, ptr %7, align 4, !tbaa !9
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = add nsw i32 %36, %35
  store i32 %37, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %38

38:                                               ; preds = %31, %14
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %63

41:                                               ; preds = %38
  %42 = getelementptr inbounds %class.TouchSensorHandler, ptr %13, i32 0, i32 3
  %43 = call i32 @poll(ptr noundef %42, i64 noundef 1, i32 noundef 1000)
  store i32 %43, ptr %9, align 4, !tbaa !9
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = icmp slt i32 %44, 0
  br i1 %45, label %46, label %55

46:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %47 = call ptr @__errno_location() #6
  %48 = load i32, ptr %47, align 4, !tbaa !9
  store i32 %48, ptr %11, align 4, !tbaa !9
  %49 = call ptr @__errno_location() #6
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = call ptr @strerror(i32 noundef %50) #5
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %51)
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = sub nsw i32 0, %53
  store i32 %54, ptr %4, align 4
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %74

55:                                               ; preds = %41
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %61

58:                                               ; preds = %55
  %59 = getelementptr inbounds %class.TouchSensorHandler, ptr %13, i32 0, i32 3
  %60 = getelementptr inbounds %struct.pollfd, ptr %59, i32 0, i32 2
  store i16 0, ptr %60, align 2, !tbaa !11
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %74

61:                                               ; preds = %55
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62, %38
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %70

67:                                               ; preds = %64
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = icmp ne i32 %68, 0
  br label %70

70:                                               ; preds = %67, %64
  %71 = phi i1 [ false, %64 ], [ %69, %67 ]
  br i1 %71, label %14, label %72, !llvm.loop !19

72:                                               ; preds = %70
  %73 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %73, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %74

74:                                               ; preds = %72, %58, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %75 = load i32, ptr %4, align 4
  ret i32 %75
}

declare i32 @poll(ptr noundef, i64 noundef, i32 noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #4

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 willreturn memory(none) "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 "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 }
attributes #6 = { nounwind willreturn memory(none) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !17, i64 78}
!12 = !{!"_ZTS18TouchSensorHandler", !13, i64 0, !10, i64 40, !15, i64 48, !18, i64 72}
!13 = !{!"_ZTS24InputEventCircularReader", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTS11input_event", !16, i64 0, !17, i64 16, !17, i64 18, !10, i64 20}
!16 = !{!"_ZTS7timeval", !14, i64 0, !14, i64 8}
!17 = !{!"short", !7, i64 0}
!18 = !{!"_ZTS6pollfd", !10, i64 0, !17, i64 4, !17, i64 6}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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 [20 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN18TouchSensorHandler13processEventsEP11input_eventi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN18TouchSensorHandler15pollTouchEventsEP11input_eventi(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 72
  %5 = getelementptr inbounds i8, ptr %0, i64 78
  br label %6

6:                                                ; preds = %25, %3
  %.019 = phi i32 [ 0, %3 ], [ %.120, %25 ]
  %.016 = phi i32 [ %2, %3 ], [ %.1, %25 ]
  %7 = load i16, ptr %5, align 2, !tbaa !5
  %8 = and i16 %7, 1
  %.not = icmp eq i16 %8, 0
  br i1 %.not, label %15, label %9

9:                                                ; preds = %6
  %10 = tail call noundef i32 @_ZN18TouchSensorHandler13processEventsEP11input_eventi(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %1, i32 noundef %.016)
  %.not22 = icmp sgt i32 %10, %.016
  br i1 %.not22, label %12, label %11

11:                                               ; preds = %9
  store i16 0, ptr %5, align 2, !tbaa !5
  br label %12

12:                                               ; preds = %11, %9
  %13 = sub nsw i32 %.016, %10
  %14 = add nsw i32 %10, %.019
  br label %15

15:                                               ; preds = %12, %6
  %.120 = phi i32 [ %14, %12 ], [ %.019, %6 ]
  %.1 = phi i32 [ %13, %12 ], [ %.016, %6 ]
  %.not24 = icmp eq i32 %.1, 0
  br i1 %.not24, label %.thread, label %16

16:                                               ; preds = %15
  %17 = tail call i32 @poll(ptr noundef nonnull %4, i64 noundef 1, i32 noundef 1000)
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %25

19:                                               ; preds = %16
  %20 = tail call ptr @__errno_location() #5
  %21 = load i32, ptr %20, align 4, !tbaa !17
  %22 = tail call ptr @strerror(i32 noundef %21) #6
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef %22)
  %24 = sub nsw i32 0, %21
  br label %.thread

25:                                               ; preds = %16
  %26 = icmp eq i32 %17, 0
  br i1 %26, label %27, label %6

27:                                               ; preds = %25
  store i16 0, ptr %5, align 2, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %15, %27, %19
  %.0 = phi i32 [ %24, %19 ], [ 0, %27 ], [ %.120, %15 ]
  ret i32 %.0
}

declare i32 @poll(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #4

attributes #0 = { 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 #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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 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 #4 = { 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 willreturn memory(none) }
attributes #6 = { 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, !15, i64 78}
!6 = !{!"_ZTS18TouchSensorHandler", !7, i64 0, !12, i64 40, !13, i64 48, !16, i64 72}
!7 = !{!"_ZTS24InputEventCircularReader", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !11, i64 32}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!"_ZTS11input_event", !14, i64 0, !15, i64 16, !15, i64 18, !12, i64 20}
!14 = !{!"_ZTS7timeval", !11, i64 0, !11, i64 8}
!15 = !{!"short", !9, i64 0}
!16 = !{!"_ZTS6pollfd", !12, i64 0, !15, i64 4, !15, i64 6}
!17 = !{!12, !12, i64 0}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass