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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN18TouchSensorHandler13processEventsEP11input_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 i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %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
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 1
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  store i32 -22, ptr %4, align 4
  br label %84

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %18 = getelementptr inbounds %class.TouchSensorHandler, ptr %13, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = call noundef i64 @_ZN24InputEventCircularReader4fillEi(ptr noundef nonnull align 8 dereferenceable(40) %13, i32 noundef %19)
  store i64 %20, ptr %8, align 8, !tbaa !19
  %21 = load i64, ptr %8, align 8, !tbaa !19
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %17
  %24 = load i64, ptr %8, align 8, !tbaa !19
  %25 = trunc i64 %24 to i32
  store i32 %25, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %83

26:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  br label %27

27:                                               ; preds = %72, %26
  %28 = load i64, ptr %8, align 8, !tbaa !19
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = call noundef i64 @_ZN24InputEventCircularReader9readEventEPPK11input_event(ptr noundef nonnull align 8 dereferenceable(40) %13, ptr noundef %11)
  %32 = icmp ne i64 %31, 0
  br label %33

33:                                               ; preds = %30, %27
  %34 = phi i1 [ false, %27 ], [ %32, %30 ]
  br i1 %34, label %35, label %75

35:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.input_event, ptr %36, i32 0, i32 1
  %38 = load i16, ptr %37, align 8, !tbaa !20
  %39 = zext i16 %38 to i32
  store i32 %39, ptr %12, align 4, !tbaa !9
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 1
  br i1 %41, label %42, label %72

42:                                               ; preds = %35
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.input_event, ptr %43, i32 0, i32 2
  %45 = load i16, ptr %44, align 2, !tbaa !21
  %46 = zext i16 %45 to i32
  %47 = icmp eq i32 %46, 301
  br i1 %47, label %66, label %48

48:                                               ; preds = %42
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.input_event, ptr %49, i32 0, i32 2
  %51 = load i16, ptr %50, align 2, !tbaa !21
  %52 = zext i16 %51 to i32
  %53 = icmp eq i32 %52, 303
  br i1 %53, label %66, label %54

54:                                               ; preds = %48
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.input_event, ptr %55, i32 0, i32 2
  %57 = load i16, ptr %56, align 2, !tbaa !21
  %58 = zext i16 %57 to i32
  %59 = icmp eq i32 %58, 307
  br i1 %59, label %66, label %60

60:                                               ; preds = %54
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.input_event, ptr %61, i32 0, i32 2
  %63 = load i16, ptr %62, align 2, !tbaa !21
  %64 = zext i16 %63 to i32
  %65 = icmp eq i32 %64, 313
  br i1 %65, label %66, label %69

66:                                               ; preds = %60, %54, %48, %42
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %67, ptr align 8 %68, i64 24, i1 false)
  br label %69

69:                                               ; preds = %66, %60
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %10, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %69, %35
  %73 = load i64, ptr %8, align 8, !tbaa !19
  %74 = add nsw i64 %73, -1
  store i64 %74, ptr %8, align 8, !tbaa !19
  call void @_ZN24InputEventCircularReader4nextEv(ptr noundef nonnull align 8 dereferenceable(40) %13)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %27, !llvm.loop !22

75:                                               ; preds = %33
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = icmp sgt i32 %76, %77
  br i1 %78, label %79, label %81

79:                                               ; preds = %75
  %80 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %80, ptr %10, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %79, %75
  %82 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %82, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %83

83:                                               ; preds = %81, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %84

84:                                               ; preds = %83, %16
  %85 = load i32, ptr %4, align 4
  ret i32 %85
}

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

declare noundef i64 @_ZN24InputEventCircularReader4fillEi(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) #2

declare noundef i64 @_ZN24InputEventCircularReader9readEventEPPK11input_event(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef) #2

; 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 void @_ZN24InputEventCircularReader4nextEv(ptr noundef nonnull align 8 dereferenceable(40)) #2

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

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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 40}
!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 = !{!14, !14, i64 0}
!20 = !{!15, !17, i64 16}
!21 = !{!15, !17, i64 18}
!22 = distinct !{!22, !23}
!23 = !{!"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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN18TouchSensorHandler13processEventsEP11input_eventi(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr nocapture noundef writeonly %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = icmp slt i32 %2, 1
  br i1 %5, label %30, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = tail call noundef i64 @_ZN24InputEventCircularReader4fillEi(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %8)
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %6
  %12 = trunc i64 %9 to i32
  br label %30

13:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %.not21 = icmp eq i64 %9, 0
  br i1 %.not21, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %13, %28
  %.01323 = phi i32 [ %.114, %28 ], [ 0, %13 ]
  %.01522 = phi i64 [ %29, %28 ], [ %9, %13 ]
  %14 = call noundef i64 @_ZN24InputEventCircularReader9readEventEPPK11input_event(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull %4)
  %.not20 = icmp eq i64 %14, 0
  br i1 %.not20, label %.critedge, label %15

15:                                               ; preds = %.lr.ph
  %16 = load ptr, ptr %4, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load i16, ptr %17, align 8, !tbaa !18
  %19 = icmp eq i16 %18, 1
  br i1 %19, label %20, label %28

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %16, i64 18
  %22 = load i16, ptr %21, align 2, !tbaa !19
  %23 = add i16 %22, -301
  %24 = call i16 @llvm.fshl.i16(i16 %23, i16 %23, i16 15)
  switch i16 %24, label %26 [
    i16 0, label %25
    i16 1, label %25
    i16 3, label %25
    i16 6, label %25
  ]

25:                                               ; preds = %20, %20, %20, %20
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef nonnull align 8 dereferenceable(24) %16, i64 24, i1 false)
  br label %26

26:                                               ; preds = %20, %25
  %27 = add nsw i32 %.01323, 1
  br label %28

28:                                               ; preds = %26, %15
  %.114 = phi i32 [ %27, %26 ], [ %.01323, %15 ]
  %29 = add nsw i64 %.01522, -1
  call void @_ZN24InputEventCircularReader4nextEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %.not = icmp eq i64 %29, 0
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !20

.critedge:                                        ; preds = %.lr.ph, %28, %13
  %.013.lcssa = phi i32 [ 0, %13 ], [ %.114, %28 ], [ %.01323, %.lr.ph ]
  %spec.select = call i32 @llvm.smin.i32(i32 %.013.lcssa, i32 %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  br label %30

30:                                               ; preds = %11, %.critedge, %3
  %.1 = phi i32 [ -22, %3 ], [ %12, %11 ], [ %spec.select, %.critedge ]
  ret i32 %.1
}

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

declare noundef i64 @_ZN24InputEventCircularReader4fillEi(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) local_unnamed_addr #2

declare noundef i64 @_ZN24InputEventCircularReader9readEventEPPK11input_event(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef) local_unnamed_addr #2

; 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

declare void @_ZN24InputEventCircularReader4nextEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.fshl.i16(i16, i16, i16) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!6, !12, i64 40}
!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 = !{!8, !8, i64 0}
!18 = !{!13, !15, i64 16}
!19 = !{!13, !15, i64 18}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass