; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/input.ll (ZN3qOS5input7watcher6removeERNS0_7channelE)

; 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.qOS::listIterator" = type { ptr, ptr, ptr, ptr }
%"class.qOS::input::watcher" = type { %"class.qOS::node", ptr, %"class.qOS::list", %"class.qOS::list", %"class.qOS::timer", i64, ptr, ptr }
%"class.qOS::node" = type { ptr, ptr, ptr, ptr }
%"class.qOS::list" = type { %"class.qOS::node", ptr, ptr, i64 }
%"class.qOS::timer" = type { ptr, i64, i64 }
%"class.qOS::input::channel" = type { %"class.qOS::node", i32, i8, ptr, ptr, i64, i64, i64 }
%"class.qOS::input::analogChannel" = type { %"class.qOS::input::channel", i32, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i64 }

; 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: nounwind
declare void @_ZN3qOS4list5beginEv(ptr dead_on_unwind writable sret(%"class.qOS::listIterator") align 8, ptr noundef nonnull align 8 dereferenceable(56)) #1

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32)) #1

; Function Attrs: nounwind
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS12listIteratorppEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS12listIteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS12listIterator3getIPNS_5input13analogChannelEEET_v(ptr noundef nonnull align 8 dereferenceable(32)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS5input7watcher6removeERNS0_7channelE(ptr noundef nonnull align 8 dereferenceable(200) %0, ptr noundef nonnull align 8 dereferenceable(80) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca %"class.qOS::listIterator", align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call noundef ptr @_ZN3qOS4node12getContainerEv(ptr noundef nonnull align 8 dereferenceable(32) %11) #4
  store ptr %12, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call noundef zeroext i1 @_ZN3qOS4list6removeEPv(ptr noundef nonnull align 8 dereferenceable(56) %13, ptr noundef %14) #4
  %16 = zext i1 %15 to i8
  store i8 %16, ptr %6, align 1, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds ptr, ptr %18, i64 13
  %20 = load ptr, ptr %19, align 8
  %21 = call noundef zeroext i1 %20(ptr noundef nonnull align 8 dereferenceable(80) %17) #4
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds ptr, ptr %23, i64 6
  %25 = load ptr, ptr %24, align 8
  %26 = call noundef i32 %25(ptr noundef nonnull align 8 dereferenceable(80) %22) #4
  %27 = icmp eq i32 1, %26
  br i1 %27, label %28, label %69

28:                                               ; preds = %2
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds ptr, ptr %30, i64 7
  %32 = load ptr, ptr %31, align 8
  %33 = call noundef zeroext i1 %32(ptr noundef nonnull align 8 dereferenceable(80) %29) #4
  br i1 %33, label %69, label %34

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #4
  %35 = getelementptr inbounds %"class.qOS::input::watcher", ptr %10, i32 0, i32 3
  call void @_ZN3qOS4list5beginEv(ptr dead_on_unwind writable sret(%"class.qOS::listIterator") align 8 %8, ptr noundef nonnull align 8 dereferenceable(56) %35) #4
  br label %36

36:                                               ; preds = %66, %34
  %37 = call noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32) %8) #4
  br i1 %37, label %39, label %38

38:                                               ; preds = %36
  call void @_ZN3qOS12listIteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  br label %68

39:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %40 = call noundef ptr @_ZN3qOS12listIterator3getIPNS_5input13analogChannelEEET_v(ptr noundef nonnull align 8 dereferenceable(32) %8) #4
  store ptr %40, ptr %9, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %"class.qOS::input::channel", ptr %41, i32 0, i32 2
  %43 = load i8, ptr %42, align 4, !tbaa !13
  %44 = zext i8 %43 to i32
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %"class.qOS::input::channel", ptr %45, i32 0, i32 2
  %47 = load i8, ptr %46, align 4, !tbaa !13
  %48 = zext i8 %47 to i32
  %49 = icmp eq i32 %44, %48
  br i1 %49, label %50, label %65

50:                                               ; preds = %39
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = icmp eq ptr null, %51
  br i1 %52, label %53, label %60

53:                                               ; preds = %50
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %54, i32 0, i32 1
  store ptr %55, ptr %7, align 8, !tbaa !5
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %58, i32 0, i32 2
  store ptr %57, ptr %59, align 8, !tbaa !18
  br label %64

60:                                               ; preds = %50
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %62, i32 0, i32 2
  store ptr %61, ptr %63, align 8, !tbaa !18
  br label %64

64:                                               ; preds = %60, %53
  br label %65

65:                                               ; preds = %64, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %66

66:                                               ; preds = %65
  %67 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS12listIteratorppEi(ptr noundef nonnull align 8 dereferenceable(32) %8, i32 noundef 0) #4
  br label %36, !llvm.loop !21

68:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %69

69:                                               ; preds = %68, %28, %2
  %70 = load i8, ptr %6, align 1, !tbaa !9, !range !23, !noundef !24
  %71 = trunc i8 %70 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i1 %71
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS4node12getContainerEv(ptr noundef nonnull align 8 dereferenceable(32)) #3 align 2

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS4list6removeEPv(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) #1

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

!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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !7, i64 36}
!14 = !{!"_ZTSN3qOS5input7channelE", !15, i64 0, !16, i64 32, !7, i64 36, !6, i64 40, !6, i64 48, !17, i64 56, !17, i64 64, !17, i64 72}
!15 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!"_ZTSN3qOS5input5eventE", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !6, i64 88}
!19 = !{!"_ZTSN3qOS5input13analogChannelE", !14, i64 0, !20, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !20, i64 112, !20, i64 116, !20, i64 120, !20, i64 124, !20, i64 128, !20, i64 132, !20, i64 136, !17, i64 144}
!20 = !{!"int", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{i8 0, i8 2}
!24 = !{}


; 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.qOS::listIterator" = type { ptr, ptr, ptr, ptr }

; 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: nounwind
declare void @_ZN3qOS4list5beginEv(ptr dead_on_unwind writable sret(%"class.qOS::listIterator") align 8, ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #1

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1

; Function Attrs: nounwind
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS12listIteratorppEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS12listIteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS12listIterator3getIPNS_5input13analogChannelEEET_v(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS5input7watcher6removeERNS0_7channelE(ptr noundef nonnull align 8 dereferenceable(200) %0, ptr noundef nonnull align 8 dereferenceable(80) %1) local_unnamed_addr #2 align 2 {
  %3 = alloca %"class.qOS::listIterator", align 8
  %4 = tail call noundef ptr @_ZN3qOS4node12getContainerEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #4
  %5 = tail call noundef zeroext i1 @_ZN3qOS4list6removeEPv(ptr noundef nonnull align 8 dereferenceable(56) %4, ptr noundef nonnull %1) #4
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 104
  %8 = load ptr, ptr %7, align 8
  %9 = tail call noundef zeroext i1 %8(ptr noundef nonnull align 8 dereferenceable(80) %1) #4
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 48
  %12 = load ptr, ptr %11, align 8
  %13 = tail call noundef i32 %12(ptr noundef nonnull align 8 dereferenceable(80) %1) #4
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %36

15:                                               ; preds = %2
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 56
  %18 = load ptr, ptr %17, align 8
  %19 = tail call noundef zeroext i1 %18(ptr noundef nonnull align 8 dereferenceable(80) %1) #4
  br i1 %19, label %36, label %20

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  %21 = getelementptr inbounds i8, ptr %0, i64 96
  call void @_ZN3qOS4list5beginEv(ptr dead_on_unwind nonnull writable sret(%"class.qOS::listIterator") align 8 %3, ptr noundef nonnull align 8 dereferenceable(56) %21) #4
  %22 = call noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %20
  %23 = getelementptr inbounds i8, ptr %1, i64 36
  br label %24

._crit_edge:                                      ; preds = %33, %20
  call void @_ZN3qOS12listIteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  br label %36

24:                                               ; preds = %.lr.ph, %33
  %.015 = phi ptr [ null, %.lr.ph ], [ %.1, %33 ]
  %25 = call noundef ptr @_ZN3qOS12listIterator3getIPNS_5input13analogChannelEEET_v(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  %26 = getelementptr inbounds i8, ptr %25, i64 36
  %27 = load i8, ptr %26, align 4, !tbaa !8
  %28 = load i8, ptr %23, align 4, !tbaa !8
  %29 = icmp eq i8 %27, %28
  br i1 %29, label %.sink.split, label %33

.sink.split:                                      ; preds = %24
  %30 = icmp eq ptr %.015, null
  %31 = getelementptr inbounds i8, ptr %25, i64 80
  %.sink = select i1 %30, ptr %31, ptr %.015
  %32 = getelementptr inbounds i8, ptr %25, i64 88
  store ptr %.sink, ptr %32, align 8, !tbaa !15
  br label %33

33:                                               ; preds = %.sink.split, %24
  %.1 = phi ptr [ %.015, %24 ], [ %.sink, %.sink.split ]
  %34 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS12listIteratorppEi(ptr noundef nonnull align 8 dereferenceable(32) %3, i32 noundef 0) #4
  %35 = call noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  br i1 %35, label %24, label %._crit_edge, !llvm.loop !18

36:                                               ; preds = %._crit_edge, %15, %2
  ret i1 %5
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS4node12getContainerEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3 align 2

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS4list6removeEPv(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) local_unnamed_addr #1

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

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !12, i64 36}
!9 = !{!"_ZTSN3qOS5input7channelE", !10, i64 0, !13, i64 32, !12, i64 36, !11, i64 40, !11, i64 48, !14, i64 56, !14, i64 64, !14, i64 72}
!10 = !{!"_ZTSN3qOS4nodeE", !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !7, i64 0}
!13 = !{!"_ZTSN3qOS5input5eventE", !12, i64 0}
!14 = !{!"long", !12, i64 0}
!15 = !{!16, !11, i64 88}
!16 = !{!"_ZTSN3qOS5input13analogChannelE", !9, i64 0, !17, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !17, i64 112, !17, i64 116, !17, i64 120, !17, i64 124, !17, i64 128, !17, i64 132, !17, i64 136, !14, i64 144}
!17 = !{!"int", !12, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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