; LLVM IR from AnneLivia/Competitive-Programming :: Data Structures/Linked List/Doubly Linked List (Implemented With Struct)/doublylin_8950ec1a (sortedPP4Nodei)

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

%struct.Node = type { i32, ptr, ptr }

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(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 nounwind uwtable
define dso_local noundef zeroext i1 @_Z13insert_sortedPP4Nodei(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %89

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %14 = call noalias ptr @malloc(i64 noundef 24) #4
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %13
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %88

18:                                               ; preds = %13
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Node, ptr %20, i32 0, i32 0
  store i32 %19, ptr %21, align 8, !tbaa !11
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %32

25:                                               ; preds = %18
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Node, ptr %26, i32 0, i32 1
  store ptr null, ptr %27, align 8, !tbaa !13
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Node, ptr %28, i32 0, i32 2
  store ptr null, ptr %29, align 8, !tbaa !14
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %30, ptr %31, align 8, !tbaa !5
  br label %87

32:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  store ptr %34, ptr %9, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %46, %32
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %44

38:                                               ; preds = %35
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Node, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = icmp slt i32 %41, %42
  br label %44

44:                                               ; preds = %38, %35
  %45 = phi i1 [ false, %35 ], [ %43, %38 ]
  br i1 %45, label %46, label %51

46:                                               ; preds = %44
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %47, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  store ptr %50, ptr %9, align 8, !tbaa !5
  br label %35, !llvm.loop !15

51:                                               ; preds = %44
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = icmp eq ptr %52, %54
  br i1 %55, label %56, label %69

56:                                               ; preds = %51
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Node, ptr %59, i32 0, i32 1
  store ptr %58, ptr %60, align 8, !tbaa !13
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Node, ptr %63, i32 0, i32 2
  store ptr %61, ptr %64, align 8, !tbaa !14
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Node, ptr %65, i32 0, i32 2
  store ptr null, ptr %66, align 8, !tbaa !14
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %67, ptr %68, align 8, !tbaa !5
  br label %86

69:                                               ; preds = %51
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Node, ptr %71, i32 0, i32 1
  store ptr %70, ptr %72, align 8, !tbaa !13
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.Node, ptr %74, i32 0, i32 1
  store ptr %73, ptr %75, align 8, !tbaa !13
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Node, ptr %77, i32 0, i32 2
  store ptr %76, ptr %78, align 8, !tbaa !14
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = icmp ne ptr %79, null
  br i1 %80, label %81, label %85

81:                                               ; preds = %69
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.Node, ptr %83, i32 0, i32 2
  store ptr %82, ptr %84, align 8, !tbaa !14
  br label %85

85:                                               ; preds = %81, %69
  br label %86

86:                                               ; preds = %85, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %87

87:                                               ; preds = %86, %25
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %88

88:                                               ; preds = %87, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %89

89:                                               ; preds = %88, %12
  %90 = load i1, ptr %3, align 1
  ret i1 %90
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind 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 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 }
attributes #4 = { nounwind 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS4Node", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef zeroext i1 @_Z13insert_sortedPP4Nodei(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %28, label %4

4:                                                ; preds = %2
  %5 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #3
  %.not39 = icmp eq ptr %5, null
  br i1 %.not39, label %28, label %6

6:                                                ; preds = %4
  store i32 %1, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %0, align 8, !tbaa !11
  %8 = icmp eq ptr %7, null
  br i1 %8, label %11, label %.preheader.preheader

.preheader.preheader:                             ; preds = %6
  %9 = load i32, ptr %7, align 8, !tbaa !5
  %10 = icmp slt i32 %9, %1
  br i1 %10, label %.lr.ph, label %.critedge.thread

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %5, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %12, i8 0, i64 16, i1 false)
  store ptr %5, ptr %0, align 8, !tbaa !11
  br label %28

.preheader:                                       ; preds = %.lr.ph
  %13 = load i32, ptr %16, align 8, !tbaa !5
  %14 = icmp slt i32 %13, %1
  br i1 %14, label %.lr.ph, label %.critedge.thread, !llvm.loop !12

.lr.ph:                                           ; preds = %.preheader.preheader, %.preheader
  %.04351 = phi ptr [ %16, %.preheader ], [ %7, %.preheader.preheader ]
  %15 = getelementptr inbounds i8, ptr %.04351, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %.critedge, label %.preheader, !llvm.loop !12

.critedge.thread:                                 ; preds = %.preheader, %.preheader.preheader
  %.043.lcssa = phi ptr [ %7, %.preheader.preheader ], [ %16, %.preheader ]
  %.03342.lcssa = phi ptr [ undef, %.preheader.preheader ], [ %.04351, %.preheader ]
  %17 = icmp eq ptr %.043.lcssa, %7
  %18 = getelementptr inbounds i8, ptr %5, i64 8
  %19 = getelementptr inbounds i8, ptr %5, i64 16
  br i1 %17, label %20, label %25

20:                                               ; preds = %.critedge.thread
  store ptr %7, ptr %18, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %7, i64 16
  store ptr %5, ptr %21, align 8, !tbaa !15
  store ptr null, ptr %19, align 8, !tbaa !15
  store ptr %5, ptr %0, align 8, !tbaa !11
  br label %28

.critedge:                                        ; preds = %.lr.ph
  %22 = getelementptr inbounds i8, ptr %.04351, i64 8
  %23 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr null, ptr %23, align 8, !tbaa !14
  store ptr %5, ptr %22, align 8, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %.04351, ptr %24, align 8, !tbaa !15
  br label %28

25:                                               ; preds = %.critedge.thread
  store ptr %.043.lcssa, ptr %18, align 8, !tbaa !14
  %26 = getelementptr inbounds i8, ptr %.03342.lcssa, i64 8
  store ptr %5, ptr %26, align 8, !tbaa !14
  store ptr %.03342.lcssa, ptr %19, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %.043.lcssa, i64 16
  store ptr %5, ptr %27, align 8, !tbaa !15
  br label %28

28:                                               ; preds = %.critedge, %4, %20, %25, %11, %2
  %.1 = phi i1 [ false, %2 ], [ true, %11 ], [ true, %.critedge ], [ true, %25 ], [ true, %20 ], [ false, %4 ]
  ret i1 %.1
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nofree 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind 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 = !{!10, !10, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !10, i64 8}
!15 = !{!6, !10, i64 16}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass