; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/list.ll (ZN3qOS4list6removeENS_12listPositionEPv)

; 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::list" = type { %"class.qOS::node", ptr, ptr, i64 }
%"class.qOS::node" = type { ptr, ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3qOS4list8isMemberEPKv(ptr noundef nonnull align 8 dereferenceable(56), ptr 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 nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS4list11removeFrontEv(ptr noundef nonnull align 8 dereferenceable(56)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS4list10removeBackEv(ptr noundef nonnull align 8 dereferenceable(56)) #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3qOS4list6removeEPv(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) #0 align 2

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

14:                                               ; preds = %3
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp sge i32 %15, -2
  br i1 %16, label %17, label %68

17:                                               ; preds = %14
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = call noundef zeroext i1 @_ZNK3qOS4list8isMemberEPKv(ptr noundef nonnull align 8 dereferenceable(56) %10, ptr noundef %18) #2
  br i1 %19, label %20, label %26

20:                                               ; preds = %17
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = call noundef zeroext i1 @_ZN3qOS4list6removeEPv(ptr noundef nonnull align 8 dereferenceable(56) %10, ptr noundef %21) #2
  br i1 %22, label %23, label %25

23:                                               ; preds = %20
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %24, ptr %7, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %23, %20
  br label %67

26:                                               ; preds = %17
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = icmp eq i32 -1, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %26
  %30 = call noundef ptr @_ZN3qOS4list11removeFrontEv(ptr noundef nonnull align 8 dereferenceable(56) %10) #2
  store ptr %30, ptr %7, align 8, !tbaa !5
  br label %61

31:                                               ; preds = %26
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = icmp eq i32 -2, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %31
  %35 = call noundef ptr @_ZN3qOS4list10removeBackEv(ptr noundef nonnull align 8 dereferenceable(56) %10) #2
  store ptr %35, ptr %7, align 8, !tbaa !5
  br label %60

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = sub nsw i32 %37, 1
  store i32 %38, ptr %9, align 4, !tbaa !15
  %39 = load i32, ptr %9, align 4, !tbaa !15
  %40 = call noundef ptr @_ZNK3qOS4list14getNodeAtIndexENS_12listPositionE(ptr noundef nonnull align 8 dereferenceable(56) %10, i32 noundef %39) #2
  store ptr %40, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %"class.qOS::node", ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  store ptr %43, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %"class.qOS::node", ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %"class.qOS::node", ptr %47, i32 0, i32 1
  store ptr %46, ptr %48, align 8, !tbaa !17
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.qOS::node", ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !17
  %52 = icmp ne ptr null, %51
  br i1 %52, label %53, label %59

53:                                               ; preds = %36
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %"class.qOS::node", ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  %58 = getelementptr inbounds %"class.qOS::node", ptr %57, i32 0, i32 2
  store ptr %54, ptr %58, align 8, !tbaa !18
  br label %59

59:                                               ; preds = %53, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %60

60:                                               ; preds = %59, %34
  br label %61

61:                                               ; preds = %60, %29
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %"class.qOS::node", ptr %62, i32 0, i32 3
  store ptr null, ptr %63, align 8, !tbaa !19
  %64 = getelementptr inbounds %"class.qOS::list", ptr %10, i32 0, i32 3
  %65 = load i64, ptr %64, align 8, !tbaa !20
  %66 = add i64 %65, -1
  store i64 %66, ptr %64, align 8, !tbaa !20
  br label %67

67:                                               ; preds = %61, %25
  br label %68

68:                                               ; preds = %67, %14, %3
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret ptr %69
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"_ZTSN3qOS12listPositionE", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"_ZTSN3qOS4listE", !13, i64 0, !6, i64 32, !6, i64 40, !14, i64 48}
!13 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!13, !6, i64 8}
!18 = !{!13, !6, i64 16}
!19 = !{!13, !6, i64 24}
!20 = !{!12, !14, i64 48}


; 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3qOS4list8isMemberEPKv(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS4list11removeFrontEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS4list10removeBackEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN3qOS4list6removeENS_12listPositionEPv(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  %7 = icmp sgt i32 %1, -3
  %or.cond = and i1 %7, %6
  br i1 %or.cond, label %8, label %31

8:                                                ; preds = %3
  %9 = tail call noundef zeroext i1 @_ZNK3qOS4list8isMemberEPKv(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %2) #1
  br i1 %9, label %10, label %12

10:                                               ; preds = %8
  %11 = tail call noundef zeroext i1 @_ZN3qOS4list6removeEPv(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %2) #1
  %spec.select = select i1 %11, ptr %2, ptr null
  br label %31

12:                                               ; preds = %8
  switch i32 %1, label %17 [
    i32 -1, label %13
    i32 -2, label %15
  ]

13:                                               ; preds = %12
  %14 = tail call noundef ptr @_ZN3qOS4list11removeFrontEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #1
  br label %26

15:                                               ; preds = %12
  %16 = tail call noundef ptr @_ZN3qOS4list10removeBackEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #1
  br label %26

17:                                               ; preds = %12
  %18 = add nsw i32 %1, -1
  %19 = tail call noundef ptr @_ZNK3qOS4list14getNodeAtIndexENS_12listPositionE(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %18) #1
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  store ptr %23, ptr %20, align 8, !tbaa !12
  %.not = icmp eq ptr %23, null
  br i1 %.not, label %26, label %24

24:                                               ; preds = %17
  %25 = getelementptr inbounds i8, ptr %23, i64 16
  store ptr %19, ptr %25, align 8, !tbaa !13
  br label %26

26:                                               ; preds = %17, %24, %15, %13
  %.0 = phi ptr [ %14, %13 ], [ %16, %15 ], [ %21, %24 ], [ %21, %17 ]
  %27 = getelementptr inbounds i8, ptr %.0, i64 24
  store ptr null, ptr %27, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %0, i64 48
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = add i64 %29, -1
  store i64 %30, ptr %28, align 8, !tbaa !15
  br label %31

31:                                               ; preds = %10, %26, %3
  %.1 = phi ptr [ %.0, %26 ], [ null, %3 ], [ %spec.select, %10 ]
  ret ptr %.1
}

attributes #0 = { 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 #1 = { 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, !8, i64 32}
!6 = !{!"_ZTSN3qOS4listE", !7, i64 0, !8, i64 32, !8, i64 40, !11, i64 48}
!7 = !{!"_ZTSN3qOS4nodeE", !8, i64 8, !8, i64 16, !8, i64 24}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!7, !8, i64 8}
!13 = !{!7, !8, i64 16}
!14 = !{!7, !8, i64 24}
!15 = !{!6, !11, i64 48}


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