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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN24InputEventCircularReader4fillEi(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !11
  %11 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 4
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %14, label %83

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 4
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = mul i64 %19, 24
  %21 = call i64 @read(i32 noundef %15, ptr noundef %17, i64 noundef %20)
  store i64 %21, ptr %7, align 8, !tbaa !11
  %22 = load i64, ptr %7, align 8, !tbaa !11
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %28, label %24

24:                                               ; preds = %14
  %25 = load i64, ptr %7, align 8, !tbaa !11
  %26 = urem i64 %25, 24
  %27 = icmp ne i64 %26, 0
  br i1 %27, label %28, label %39

28:                                               ; preds = %24, %14
  %29 = load i64, ptr %7, align 8, !tbaa !11
  %30 = icmp slt i64 %29, 0
  br i1 %30, label %31, label %35

31:                                               ; preds = %28
  %32 = call ptr @__errno_location() #6
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = sub nsw i32 0, %33
  br label %36

35:                                               ; preds = %28
  br label %36

36:                                               ; preds = %35, %31
  %37 = phi i32 [ %34, %31 ], [ -22, %35 ]
  %38 = sext i32 %37 to i64
  store i64 %38, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %80

39:                                               ; preds = %24
  %40 = load i64, ptr %7, align 8, !tbaa !11
  %41 = udiv i64 %40, 24
  store i64 %41, ptr %6, align 8, !tbaa !11
  %42 = load i64, ptr %6, align 8, !tbaa !11
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %44, label %79

44:                                               ; preds = %39
  %45 = load i64, ptr %6, align 8, !tbaa !11
  %46 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = getelementptr inbounds %struct.input_event, ptr %47, i64 %45
  store ptr %48, ptr %46, align 8, !tbaa !15
  %49 = load i64, ptr %6, align 8, !tbaa !11
  %50 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 4
  %51 = load i64, ptr %50, align 8, !tbaa !13
  %52 = sub i64 %51, %49
  store i64 %52, ptr %50, align 8, !tbaa !13
  %53 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = icmp ugt ptr %54, %56
  br i1 %57, label %58, label %78

58:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %59 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !16
  %63 = ptrtoint ptr %60 to i64
  %64 = ptrtoint ptr %62 to i64
  %65 = sub i64 %63, %64
  %66 = sdiv exact i64 %65, 24
  store i64 %66, ptr %9, align 8, !tbaa !11
  %67 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !17
  %69 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !16
  %71 = load i64, ptr %9, align 8, !tbaa !11
  %72 = mul i64 %71, 24
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %68, ptr align 8 %70, i64 %72, i1 false)
  %73 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !17
  %75 = load i64, ptr %9, align 8, !tbaa !11
  %76 = getelementptr inbounds %struct.input_event, ptr %74, i64 %75
  %77 = getelementptr inbounds %class.InputEventCircularReader, ptr %10, i32 0, i32 2
  store ptr %76, ptr %77, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %78

78:                                               ; preds = %58, %44
  br label %79

79:                                               ; preds = %78, %39
  store i32 0, ptr %8, align 4
  br label %80

80:                                               ; preds = %79, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %81 = load i32, ptr %8, align 4
  switch i32 %81, label %85 [
    i32 0, label %82
  ]

82:                                               ; preds = %80
  br label %83

83:                                               ; preds = %82, %2
  %84 = load i64, ptr %6, align 8, !tbaa !11
  store i64 %84, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %85

85:                                               ; preds = %83, %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %86 = load i64, ptr %3, align 8
  ret i64 %86
}

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

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

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

; 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) #4

; 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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 32}
!14 = !{!"_ZTS24InputEventCircularReader", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32}
!15 = !{!14, !6, i64 16}
!16 = !{!14, !6, i64 8}
!17 = !{!14, !6, i64 0}


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

; Function Attrs: mustprogress nofree uwtable
define dso_local noundef i64 @_ZN24InputEventCircularReader4fillEi(ptr nocapture noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %35, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = mul i64 %4, 24
  %9 = tail call i64 @read(i32 noundef %1, ptr noundef %7, i64 noundef %8)
  %10 = icmp sgt i64 %9, -1
  %11 = urem i64 %9, 24
  %12 = udiv i64 %9, 24
  %.not21 = icmp eq i64 %11, 0
  %or.cond = and i1 %10, %.not21
  br i1 %or.cond, label %19, label %13

13:                                               ; preds = %5
  br i1 %10, label %35, label %14

14:                                               ; preds = %13
  %15 = tail call ptr @__errno_location() #4
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = sub nsw i32 0, %16
  %18 = sext i32 %17 to i64
  br label %35

19:                                               ; preds = %5
  %.not22 = icmp ult i64 %9, 24
  br i1 %.not22, label %35, label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %6, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.input_event, ptr %21, i64 %12
  store ptr %22, ptr %6, align 8, !tbaa !11
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = sub i64 %23, %12
  store i64 %24, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = icmp ugt ptr %22, %26
  br i1 %27, label %28, label %35

28:                                               ; preds = %20
  %29 = ptrtoint ptr %22 to i64
  %30 = ptrtoint ptr %26 to i64
  %31 = sub i64 %29, %30
  %32 = load ptr, ptr %0, align 8, !tbaa !15
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %32, ptr align 8 %26, i64 %31, i1 false)
  %33 = load ptr, ptr %0, align 8, !tbaa !15
  %34 = getelementptr inbounds i8, ptr %33, i64 %31
  store ptr %34, ptr %6, align 8, !tbaa !11
  br label %35

35:                                               ; preds = %14, %13, %20, %28, %19, %2
  %.1 = phi i64 [ 0, %2 ], [ %18, %14 ], [ -22, %13 ], [ %12, %20 ], [ %12, %28 ], [ %12, %19 ]
  ret i64 %.1
}

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() 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

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


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