; LLVM IR from MinhasKamal/AlgorithmImplementations :: dataStructures/listImplementation/implementationUsingNode (TwoWayLinkedList)

; 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::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%struct.node = type { i32, ptr, ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.6 = external hidden unnamed_addr constant [31 x i8], align 1

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z22insertBeforeTheElementiiP4node(i32 noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %10, ptr %7, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %25, %3
  br label %12

12:                                               ; preds = %11
  %13 = load ptr, ptr %7, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.node, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp eq i32 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  br label %29

19:                                               ; preds = %12
  %20 = load ptr, ptr %7, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.node, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %19
  br label %29

25:                                               ; preds = %19
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.node, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  store ptr %28, ptr %7, align 8, !tbaa !9
  br label %11, !llvm.loop !14

29:                                               ; preds = %24, %18
  %30 = load ptr, ptr %7, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.node, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %43

34:                                               ; preds = %29
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = icmp ne i32 %37, %38
  br i1 %39, label %40, label %43

40:                                               ; preds = %34
  %41 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.6)
  %42 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %41, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %93

43:                                               ; preds = %34, %29
  %44 = load ptr, ptr %7, align 8, !tbaa !9
  %45 = load ptr, ptr %6, align 8, !tbaa !9
  %46 = icmp eq ptr %44, %45
  br i1 %46, label %47, label %66

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %48 = call noalias noundef nonnull ptr @_Znam(i64 noundef 24) #5
  store ptr %48, ptr %8, align 8, !tbaa !9
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = load ptr, ptr %8, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.node, ptr %50, i64 0
  %52 = getelementptr inbounds %struct.node, ptr %51, i32 0, i32 0
  store i32 %49, ptr %52, align 8, !tbaa !11
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  %54 = load ptr, ptr %8, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.node, ptr %54, i64 0
  %56 = getelementptr inbounds %struct.node, ptr %55, i32 0, i32 1
  store ptr %53, ptr %56, align 8, !tbaa !13
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.node, ptr %57, i64 0
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 2
  store ptr null, ptr %59, align 8, !tbaa !16
  %60 = load ptr, ptr %8, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.node, ptr %60, i64 0
  %62 = load ptr, ptr %7, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.node, ptr %62, i32 0, i32 2
  store ptr %61, ptr %63, align 8, !tbaa !16
  %64 = load ptr, ptr %8, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.node, ptr %64, i64 0
  store ptr %65, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %92

66:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %67 = call noalias noundef nonnull ptr @_Znam(i64 noundef 24) #5
  store ptr %67, ptr %9, align 8, !tbaa !9
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = load ptr, ptr %9, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.node, ptr %69, i64 0
  %71 = getelementptr inbounds %struct.node, ptr %70, i32 0, i32 0
  store i32 %68, ptr %71, align 8, !tbaa !11
  %72 = load ptr, ptr %7, align 8, !tbaa !9
  %73 = load ptr, ptr %9, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.node, ptr %73, i64 0
  %75 = getelementptr inbounds %struct.node, ptr %74, i32 0, i32 1
  store ptr %72, ptr %75, align 8, !tbaa !13
  %76 = load ptr, ptr %7, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.node, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !16
  %79 = load ptr, ptr %9, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.node, ptr %79, i64 0
  %81 = getelementptr inbounds %struct.node, ptr %80, i32 0, i32 2
  store ptr %78, ptr %81, align 8, !tbaa !16
  %82 = load ptr, ptr %9, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct.node, ptr %82, i64 0
  %84 = load ptr, ptr %7, align 8, !tbaa !9
  %85 = getelementptr inbounds %struct.node, ptr %84, i32 0, i32 2
  %86 = load ptr, ptr %85, align 8, !tbaa !16
  %87 = getelementptr inbounds %struct.node, ptr %86, i32 0, i32 1
  store ptr %83, ptr %87, align 8, !tbaa !13
  %88 = load ptr, ptr %9, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.node, ptr %88, i64 0
  %90 = load ptr, ptr %7, align 8, !tbaa !9
  %91 = getelementptr inbounds %struct.node, ptr %90, i32 0, i32 2
  store ptr %89, ptr %91, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %92

92:                                               ; preds = %66, %47
  br label %93

93:                                               ; preds = %92, %40
  %94 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret ptr %94
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #3

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4node", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!12, !10, i64 16}


; 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::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.6 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z22insertBeforeTheElementiiP4node(i32 noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  br label %4

4:                                                ; preds = %7, %3
  %.028 = phi ptr [ %2, %3 ], [ %9, %7 ]
  %5 = load i32, ptr %.028, align 8, !tbaa !5
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %.028, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = icmp eq ptr %9, null
  br i1 %10, label %.thread, label %4, !llvm.loop !12

.thread:                                          ; preds = %7
  %11 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.6)
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %24

.loopexit:                                        ; preds = %4
  %13 = icmp eq ptr %.028, %2
  %14 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znam(i64 noundef 24) #3
  store i32 %1, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr %.028, ptr %15, align 8, !tbaa !11
  br i1 %13, label %16, label %19

16:                                               ; preds = %.loopexit
  %17 = getelementptr inbounds i8, ptr %14, i64 16
  store ptr null, ptr %17, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %.028, i64 16
  store ptr %14, ptr %18, align 8, !tbaa !14
  br label %24

19:                                               ; preds = %.loopexit
  %20 = getelementptr inbounds i8, ptr %.028, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %14, i64 16
  store ptr %21, ptr %22, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %21, i64 8
  store ptr %14, ptr %23, align 8, !tbaa !11
  store ptr %14, ptr %20, align 8, !tbaa !14
  br label %24

24:                                               ; preds = %16, %19, %.thread
  %.0 = phi ptr [ %2, %.thread ], [ %14, %16 ], [ %2, %19 ]
  ret ptr %.0
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #2

attributes #0 = { nobuiltin allocsize(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 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 = { inlinehint 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 #3 = { builtin allocsize(0) }

!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, !7, i64 0}
!6 = !{!"_ZTS4node", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !10, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass