; LLVM IR from Ayon-SSP/The-SDE-Prep :: 1]_Data Structures/2]_Linked List (8_insertingnode)

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

@first = external dso_local global ptr, align 8

; 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: nounwind uwtable
define dso_local void @insert(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = load ptr, ptr @first, align 8, !tbaa !9
  store ptr %8, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %9 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %9, ptr %6, align 8, !tbaa !9
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %49

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %30, %12
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sub nsw i32 %15, 1
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %18, label %23

18:                                               ; preds = %13
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.Node, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = icmp ne ptr %21, null
  br label %23

23:                                               ; preds = %18, %13
  %24 = phi i1 [ false, %13 ], [ %22, %18 ]
  br i1 %24, label %26, label %25

25:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %33

26:                                               ; preds = %23
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.Node, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  store ptr %29, ptr %5, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %26
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %7, align 4, !tbaa !5
  br label %13, !llvm.loop !13

33:                                               ; preds = %25
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %48

36:                                               ; preds = %33
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.Node, ptr %38, i32 0, i32 0
  store i32 %37, ptr %39, align 8, !tbaa !15
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.Node, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.Node, ptr %43, i32 0, i32 1
  store ptr %42, ptr %44, align 8, !tbaa !11
  %45 = load ptr, ptr %6, align 8, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.Node, ptr %46, i32 0, i32 1
  store ptr %45, ptr %47, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %36, %33
  br label %57

49:                                               ; preds = %2
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.Node, ptr %51, i32 0, i32 0
  store i32 %50, ptr %52, align 8, !tbaa !15
  %53 = load ptr, ptr @first, align 8, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 1
  store ptr %53, ptr %55, align 8, !tbaa !11
  %56 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %56, ptr @first, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %49, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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


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

@first = external dso_local local_unnamed_addr global ptr, align 8

; 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: nofree nounwind uwtable
define dso_local void @insert(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr @first, align 8, !tbaa !5
  %4 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #2
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %13, label %.preheader

.preheader:                                       ; preds = %2
  %5 = icmp sgt i32 %0, 1
  br i1 %5, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %.preheader
  %6 = add nsw i32 %0, -2
  br label %.lr.ph

7:                                                ; preds = %.lr.ph
  %8 = add nuw nsw i32 %.025, 1
  %exitcond.not = icmp eq i32 %.025, %6
  br i1 %exitcond.not, label %.critedge..critedge.thread_crit_edge, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph.preheader, %7
  %.025 = phi i32 [ %8, %7 ], [ 0, %.lr.ph.preheader ]
  %.01624 = phi ptr [ %10, %7 ], [ %3, %.lr.ph.preheader ]
  %9 = getelementptr inbounds i8, ptr %.01624, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %.not19 = icmp eq ptr %10, null
  br i1 %.not19, label %.critedge.thread, label %7

.critedge:                                        ; preds = %.preheader
  %.not20 = icmp eq ptr %3, null
  br i1 %.not20, label %15, label %.critedge..critedge.thread_crit_edge

.critedge..critedge.thread_crit_edge:             ; preds = %7, %.critedge
  %.016.lcssa31 = phi ptr [ %3, %.critedge ], [ %10, %7 ]
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.016.lcssa31, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !11
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %.lr.ph, %.critedge..critedge.thread_crit_edge
  %11 = phi ptr [ %.pre, %.critedge..critedge.thread_crit_edge ], [ null, %.lr.ph ]
  %.01623 = phi ptr [ %.016.lcssa31, %.critedge..critedge.thread_crit_edge ], [ %.01624, %.lr.ph ]
  store i32 %1, ptr %4, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %.01623, i64 8
  br label %.sink.split

13:                                               ; preds = %2
  store i32 %1, ptr %4, align 8, !tbaa !14
  br label %.sink.split

.sink.split:                                      ; preds = %13, %.critedge.thread
  %.sink34 = phi ptr [ %11, %.critedge.thread ], [ %3, %13 ]
  %.sink = phi ptr [ %12, %.critedge.thread ], [ @first, %13 ]
  %14 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %.sink34, ptr %14, align 8, !tbaa !11
  store ptr %4, ptr %.sink, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %.sink.split, %.critedge
  ret void
}

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 = { 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 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 8}
!12 = !{!"Node", !13, i64 0, !6, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 0}


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