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

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

; 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 void @_ZN3qOS4list13insertAtFrontEPNS_4nodeE(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS4list12insertAtBackEPNS_4nodeE(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) #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
define dso_local noundef zeroext i1 @_ZN3qOS4list6insertEPvNS_12listPositionE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !11
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr null, %11
  br i1 %12, label %13, label %68

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

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

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %20, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN3qOS4node4initEv(ptr noundef nonnull align 8 dereferenceable(32) %21) #2
  store i8 1, ptr %7, align 1, !tbaa !11
  %22 = getelementptr inbounds %"class.qOS::list", ptr %10, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = icmp eq ptr null, %23
  br i1 %24, label %25, label %30

25:                                               ; preds = %19
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.qOS::list", ptr %10, i32 0, i32 1
  store ptr %26, ptr %27, align 8, !tbaa !13
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.qOS::list", ptr %10, i32 0, i32 2
  store ptr %28, ptr %29, align 8, !tbaa !17
  br label %61

30:                                               ; preds = %19
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp eq i32 -1, %31
  br i1 %32, label %33, label %35

33:                                               ; preds = %30
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN3qOS4list13insertAtFrontEPNS_4nodeE(ptr noundef nonnull align 8 dereferenceable(56) %10, ptr noundef %34) #2
  br label %60

35:                                               ; preds = %30
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = icmp eq i32 -2, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %35
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN3qOS4list12insertAtBackEPNS_4nodeE(ptr noundef nonnull align 8 dereferenceable(56) %10, ptr noundef %39) #2
  br label %59

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = call noundef ptr @_ZNK3qOS4list14getNodeAtIndexENS_12listPositionE(ptr noundef nonnull align 8 dereferenceable(56) %10, i32 noundef %41) #2
  store ptr %42, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.qOS::node", ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !18
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %"class.qOS::node", ptr %46, i32 0, i32 1
  store ptr %45, ptr %47, align 8, !tbaa !18
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.qOS::node", ptr %49, i32 0, i32 2
  store ptr %48, ptr %50, align 8, !tbaa !19
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %"class.qOS::node", ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !18
  %55 = getelementptr inbounds %"class.qOS::node", ptr %54, i32 0, i32 2
  store ptr %51, ptr %55, align 8, !tbaa !19
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %"class.qOS::node", ptr %57, i32 0, i32 1
  store ptr %56, ptr %58, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %59

59:                                               ; preds = %40, %38
  br label %60

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

61:                                               ; preds = %60, %25
  %62 = getelementptr inbounds %"class.qOS::list", ptr %10, i32 0, i32 3
  %63 = load i64, ptr %62, align 8, !tbaa !20
  %64 = add i64 %63, 1
  store i64 %64, ptr %62, align 8, !tbaa !20
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %"class.qOS::node", ptr %65, i32 0, i32 3
  store ptr %10, ptr %66, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %67

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

68:                                               ; preds = %67, %13, %3
  %69 = load i8, ptr %7, align 1, !tbaa !11, !range !22, !noundef !23
  %70 = trunc i8 %69 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  ret i1 %70
}

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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !6, i64 32}
!14 = !{!"_ZTSN3qOS4listE", !15, i64 0, !6, i64 32, !6, i64 40, !16, i64 48}
!15 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!"long", !7, i64 0}
!17 = !{!14, !6, i64 40}
!18 = !{!15, !6, i64 8}
!19 = !{!15, !6, i64 16}
!20 = !{!14, !16, i64 48}
!21 = !{!15, !6, i64 24}
!22 = !{i8 0, i8 2}
!23 = !{}


; 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 void @_ZN3qOS4node4initEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; 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 void @_ZN3qOS4list13insertAtFrontEPNS_4nodeE(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS4list12insertAtBackEPNS_4nodeE(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 @_ZNK3qOS4list14getNodeAtIndexENS_12listPositionE(ptr noundef nonnull align 8 dereferenceable(56), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS4list6insertEPvNS_12listPositionE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = icmp ne ptr %1, null
  %5 = icmp sgt i32 %2, -3
  %or.cond = and i1 %4, %5
  br i1 %or.cond, label %6, label %29

6:                                                ; preds = %3
  %7 = tail call noundef zeroext i1 @_ZNK3qOS4list8isMemberEPKv(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull %1) #1
  br i1 %7, label %29, label %8

8:                                                ; preds = %6
  tail call void @_ZN3qOS4node4initEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #1
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %14

12:                                               ; preds = %8
  store ptr %1, ptr %9, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %1, ptr %13, align 8, !tbaa !12
  br label %24

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

15:                                               ; preds = %14
  tail call void @_ZN3qOS4list13insertAtFrontEPNS_4nodeE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull %1) #1
  br label %24

16:                                               ; preds = %14
  tail call void @_ZN3qOS4list12insertAtBackEPNS_4nodeE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull %1) #1
  br label %24

17:                                               ; preds = %14
  %18 = tail call noundef ptr @_ZNK3qOS4list14getNodeAtIndexENS_12listPositionE(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %2) #1
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %20, ptr %21, align 8, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr %18, ptr %22, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %20, i64 16
  store ptr %1, ptr %23, align 8, !tbaa !14
  store ptr %1, ptr %19, align 8, !tbaa !13
  br label %24

24:                                               ; preds = %15, %17, %16, %12
  %25 = getelementptr inbounds i8, ptr %0, i64 48
  %26 = load i64, ptr %25, align 8, !tbaa !15
  %27 = add i64 %26, 1
  store i64 %27, ptr %25, align 8, !tbaa !15
  %28 = getelementptr inbounds i8, ptr %1, i64 24
  store ptr %0, ptr %28, align 8, !tbaa !16
  br label %29

29:                                               ; preds = %6, %24, %3
  %.0 = phi i1 [ false, %6 ], [ true, %24 ], [ false, %3 ]
  ret i1 %.0
}

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 = !{!6, !8, i64 40}
!13 = !{!7, !8, i64 8}
!14 = !{!7, !8, i64 16}
!15 = !{!6, !11, i64 48}
!16 = !{!7, !8, i64 24}


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