; LLVM IR from MiRoboticsLab/cyberdog_ros2 :: cyberdog_common/cyberdog_utils/src/can (socket_can_sender)

; 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.std::chrono::duration" = type { i64 }
%struct.timeval = type { i64, i64 }
%struct.fd_set = type { [16 x i64] }
%"class.drivers::socketcan::SocketCanSender" = type { i32, %"class.drivers::socketcan::CanId" }
%"class.drivers::socketcan::CanId" = type { i32, i32 }

@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@_ZTIN7drivers9socketcan16SocketCanTimeoutE = external dso_local constant { ptr, ptr, ptr }, align 8
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1

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

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_allocate_exception(i64)

declare void @__cxa_free_exception(ptr)

declare void @__cxa_throw(ptr, ptr, ptr)

; Function Attrs: mustprogress uwtable
define hidden void @_ZNK7drivers9socketcan15SocketCanSender4waitENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE(ptr noundef nonnull align 4 dereferenceable(12) %0, i64 %1) #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.std::chrono::duration", align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"class.std::chrono::duration", align 8
  %6 = alloca %struct.timeval, align 8
  %7 = alloca %"class.std::chrono::duration", align 8
  %8 = alloca %struct.fd_set, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = getelementptr inbounds %"class.std::chrono::duration", ptr %3, i32 0, i32 0
  store i64 %1, ptr %11, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %13 = call i64 @_ZNSt6chrono8durationIlSt5ratioILl1ELl1000000000EEE4zeroEv() #6
  %14 = getelementptr inbounds %"class.std::chrono::duration", ptr %5, i32 0, i32 0
  store i64 %13, ptr %14, align 8
  %15 = call noundef zeroext i1 @_ZNSt6chronoltIlSt5ratioILl1ELl1000000000EElS2_EEbRKNS_8durationIT_T0_EERKNS3_IT1_T2_EE(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br i1 %15, label %16, label %62

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %3, i64 8, i1 false), !tbaa.struct !9
  %17 = getelementptr inbounds %"class.std::chrono::duration", ptr %7, i32 0, i32 0
  %18 = load i64, ptr %17, align 8
  %19 = call { i64, i64 } @_ZN7drivers9socketcan10to_timevalENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE(i64 %18) #6
  %20 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  %21 = extractvalue { i64, i64 } %19, 0
  store i64 %21, ptr %20, align 8
  %22 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  %23 = extractvalue { i64, i64 } %19, 1
  store i64 %23, ptr %22, align 8
  call void @llvm.lifetime.start.p0(i64 128, ptr %8) #6
  %24 = getelementptr inbounds %"class.drivers::socketcan::SocketCanSender", ptr %12, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !12
  call void @_ZN7drivers9socketcan10single_setEi(ptr dead_on_unwind writable sret(%struct.fd_set) align 8 %8, i32 noundef %25) #6
  %26 = getelementptr inbounds %"class.drivers::socketcan::SocketCanSender", ptr %12, i32 0, i32 0
  %27 = load i32, ptr %26, align 4, !tbaa !12
  %28 = add nsw i32 %27, 1
  %29 = call i32 @select(i32 noundef %28, ptr noundef null, ptr noundef %8, ptr noundef null, ptr noundef %6)
  %30 = icmp eq i32 0, %29
  br i1 %30, label %31, label %38

31:                                               ; preds = %16
  %32 = call ptr @__cxa_allocate_exception(i64 16) #6
  invoke void @_ZN7drivers9socketcan16SocketCanTimeoutC2EPKc(ptr noundef nonnull align 8 dereferenceable(16) %32, ptr noundef @.str.1)
          to label %33 unwind label %34

33:                                               ; preds = %31
  call void @__cxa_throw(ptr %32, ptr @_ZTIN7drivers9socketcan16SocketCanTimeoutE, ptr @_ZNSt13runtime_errorD2Ev) #7
  unreachable

34:                                               ; preds = %31
  %35 = landingpad { ptr, i32 }
          cleanup
  %36 = extractvalue { ptr, i32 } %35, 0
  store ptr %36, ptr %9, align 8
  %37 = extractvalue { ptr, i32 } %35, 1
  store i32 %37, ptr %10, align 4
  call void @__cxa_free_exception(ptr %32) #6
  br label %61

38:                                               ; preds = %16
  %39 = getelementptr inbounds %struct.fd_set, ptr %8, i32 0, i32 0
  %40 = getelementptr inbounds %"class.drivers::socketcan::SocketCanSender", ptr %12, i32 0, i32 0
  %41 = load i32, ptr %40, align 4, !tbaa !12
  %42 = sdiv i32 %41, 64
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [16 x i64], ptr %39, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !10
  %46 = getelementptr inbounds %"class.drivers::socketcan::SocketCanSender", ptr %12, i32 0, i32 0
  %47 = load i32, ptr %46, align 4, !tbaa !12
  %48 = srem i32 %47, 64
  %49 = zext i32 %48 to i64
  %50 = shl i64 1, %49
  %51 = and i64 %45, %50
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %60, label %53

53:                                               ; preds = %38
  %54 = call ptr @__cxa_allocate_exception(i64 16) #6
  invoke void @_ZN7drivers9socketcan16SocketCanTimeoutC2EPKc(ptr noundef nonnull align 8 dereferenceable(16) %54, ptr noundef @.str.2)
          to label %55 unwind label %56

55:                                               ; preds = %53
  call void @__cxa_throw(ptr %54, ptr @_ZTIN7drivers9socketcan16SocketCanTimeoutE, ptr @_ZNSt13runtime_errorD2Ev) #7
  unreachable

56:                                               ; preds = %53
  %57 = landingpad { ptr, i32 }
          cleanup
  %58 = extractvalue { ptr, i32 } %57, 0
  store ptr %58, ptr %9, align 8
  %59 = extractvalue { ptr, i32 } %57, 1
  store i32 %59, ptr %10, align 4
  call void @__cxa_free_exception(ptr %54) #6
  br label %61

60:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 128, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #6
  br label %63

61:                                               ; preds = %56, %34
  call void @llvm.lifetime.end.p0(i64 128, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #6
  br label %64

62:                                               ; preds = %2
  br label %63

63:                                               ; preds = %62, %60
  ret void

64:                                               ; preds = %61
  %65 = load ptr, ptr %9, align 8
  %66 = load i32, ptr %10, align 4
  %67 = insertvalue { ptr, i32 } poison, ptr %65, 0
  %68 = insertvalue { ptr, i32 } %67, i32 %66, 1
  resume { ptr, i32 } %68
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNSt6chronoltIlSt5ratioILl1ELl1000000000EElS2_EEbRKNS_8durationIT_T0_EERKNS3_IT1_T2_EE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i64 @_ZNSt6chrono8durationIlSt5ratioILl1ELl1000000000EEE4zeroEv() #3 align 2

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

; Function Attrs: nounwind
declare { i64, i64 } @_ZN7drivers9socketcan10to_timevalENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE(i64) #4

; Function Attrs: nounwind
declare void @_ZN7drivers9socketcan10single_setEi(ptr dead_on_unwind writable sret(%struct.fd_set) align 8, i32 noundef) #4

declare i32 @select(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #5

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7drivers9socketcan16SocketCanTimeoutC2EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #1 align 2

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #4

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

!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 = !{i64 0, i64 8, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"_ZTSN7drivers9socketcan15SocketCanSenderE", !14, i64 0, !15, i64 4}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTSN7drivers9socketcan5CanIdE", !14, i64 0, !14, i64 4}


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

%"class.std::chrono::duration" = type { i64 }
%struct.timeval = type { i64, i64 }
%struct.fd_set = type { [16 x i64] }

@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@_ZTIN7drivers9socketcan16SocketCanTimeoutE = external dso_local constant { ptr, ptr, ptr }, align 8
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @__cxa_free_exception(ptr) local_unnamed_addr

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

; Function Attrs: mustprogress uwtable
define hidden void @_ZNK7drivers9socketcan15SocketCanSender4waitENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE(ptr nocapture noundef nonnull readonly align 4 dereferenceable(12) %0, i64 %1) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.std::chrono::duration", align 8
  %4 = alloca %"class.std::chrono::duration", align 8
  %5 = alloca %struct.timeval, align 8
  %6 = alloca %struct.fd_set, align 8
  store i64 %1, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %7 = tail call i64 @_ZNSt6chrono8durationIlSt5ratioILl1ELl1000000000EEE4zeroEv() #5
  store i64 %7, ptr %4, align 8
  %8 = call noundef zeroext i1 @_ZNSt6chronoltIlSt5ratioILl1ELl1000000000EElS2_EEbRKNS_8durationIT_T0_EERKNS3_IT1_T2_EE(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  br i1 %8, label %9, label %41

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  %.sroa.0.0.copyload = load i64, ptr %3, align 8, !tbaa !5
  %10 = call { i64, i64 } @_ZN7drivers9socketcan10to_timevalENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE(i64 %.sroa.0.0.copyload) #5
  %11 = extractvalue { i64, i64 } %10, 0
  store i64 %11, ptr %5, align 8
  %12 = getelementptr inbounds i8, ptr %5, i64 8
  %13 = extractvalue { i64, i64 } %10, 1
  store i64 %13, ptr %12, align 8
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %6) #5
  %14 = load i32, ptr %0, align 4, !tbaa !9
  call void @_ZN7drivers9socketcan10single_setEi(ptr dead_on_unwind nonnull writable sret(%struct.fd_set) align 8 %6, i32 noundef %14) #5
  %15 = load i32, ptr %0, align 4, !tbaa !9
  %16 = add nsw i32 %15, 1
  %17 = call i32 @select(i32 noundef %16, ptr noundef null, ptr noundef nonnull %6, ptr noundef null, ptr noundef nonnull %5)
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %9
  %20 = call ptr @__cxa_allocate_exception(i64 16) #5
  invoke void @_ZN7drivers9socketcan16SocketCanTimeoutC2EPKc(ptr noundef nonnull align 8 dereferenceable(16) %20, ptr noundef nonnull @.str.1)
          to label %21 unwind label %22

21:                                               ; preds = %19
  call void @__cxa_throw(ptr nonnull %20, ptr nonnull @_ZTIN7drivers9socketcan16SocketCanTimeoutE, ptr nonnull @_ZNSt13runtime_errorD2Ev) #6
  unreachable

22:                                               ; preds = %19
  %23 = landingpad { ptr, i32 }
          cleanup
  br label %40

24:                                               ; preds = %9
  %25 = load i32, ptr %0, align 4, !tbaa !9
  %26 = sdiv i32 %25, 64
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [16 x i64], ptr %6, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = srem i32 %25, 64
  %31 = zext nneg i32 %30 to i64
  %32 = shl nuw i64 1, %31
  %33 = and i64 %32, %29
  %.not = icmp eq i64 %33, 0
  br i1 %.not, label %34, label %39

34:                                               ; preds = %24
  %35 = call ptr @__cxa_allocate_exception(i64 16) #5
  invoke void @_ZN7drivers9socketcan16SocketCanTimeoutC2EPKc(ptr noundef nonnull align 8 dereferenceable(16) %35, ptr noundef nonnull @.str.2)
          to label %36 unwind label %37

36:                                               ; preds = %34
  call void @__cxa_throw(ptr nonnull %35, ptr nonnull @_ZTIN7drivers9socketcan16SocketCanTimeoutE, ptr nonnull @_ZNSt13runtime_errorD2Ev) #6
  unreachable

37:                                               ; preds = %34
  %38 = landingpad { ptr, i32 }
          cleanup
  br label %40

39:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  br label %41

40:                                               ; preds = %37, %22
  %.sink = phi ptr [ %35, %37 ], [ %20, %22 ]
  %.pn = phi { ptr, i32 } [ %38, %37 ], [ %23, %22 ]
  call void @__cxa_free_exception(ptr %.sink) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  resume { ptr, i32 } %.pn

41:                                               ; preds = %2, %39
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNSt6chronoltIlSt5ratioILl1ELl1000000000EElS2_EEbRKNS_8durationIT_T0_EERKNS3_IT1_T2_EE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i64 @_ZNSt6chrono8durationIlSt5ratioILl1ELl1000000000EEE4zeroEv() local_unnamed_addr #2 align 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: nounwind
declare { i64, i64 } @_ZN7drivers9socketcan10to_timevalENSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE(i64) local_unnamed_addr #3

; Function Attrs: nounwind
declare void @_ZN7drivers9socketcan10single_setEi(ptr dead_on_unwind writable sret(%struct.fd_set) align 8, i32 noundef) local_unnamed_addr #3

declare i32 @select(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7drivers9socketcan16SocketCanTimeoutC2EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #0 align 2

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3

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 = { 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 #3 = { 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 = { "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 = { noreturn }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN7drivers9socketcan15SocketCanSenderE", !11, i64 0, !12, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSN7drivers9socketcan5CanIdE", !11, i64 0, !11, i64 4}


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