; LLVM IR from ImChong/Practice_LeetCode_C :: F01_Common_Functions/src (common_linked_list_dummy)

; 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.DummyLinkedList = type { ptr, i32 }
%struct.ListNode = type { i32, 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: nounwind uwtable
declare dso_local void @DLinkedList_AddAtHead(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @DLinkedList_AddAtTail(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @DLinkedList_AddAtIndex(ptr noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %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 i32 %2, ptr %6, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 0
  br i1 %11, label %18, label %12

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

18:                                               ; preds = %12, %3
  br label %68

19:                                               ; preds = %12
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %19
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !9
  call void @DLinkedList_AddAtHead(ptr noundef %23, i32 noundef %24)
  br label %68

25:                                               ; preds = %19
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.DummyLinkedList, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = icmp eq i32 %26, %29
  br i1 %30, label %31, label %34

31:                                               ; preds = %25
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !9
  call void @DLinkedList_AddAtTail(ptr noundef %32, i32 noundef %33)
  br label %68

34:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %35 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %35, ptr %7, align 8, !tbaa !5
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ListNode, ptr %37, i32 0, i32 0
  store i32 %36, ptr %38, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.DummyLinkedList, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  store ptr %41, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %52, %34
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = sub nsw i32 %44, 1
  %46 = icmp slt i32 %43, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %55

48:                                               ; preds = %42
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ListNode, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  store ptr %51, ptr %8, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %48
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %9, align 4, !tbaa !9
  br label %42, !llvm.loop !17

55:                                               ; preds = %47
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ListNode, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ListNode, ptr %59, i32 0, i32 1
  store ptr %58, ptr %60, align 8, !tbaa !16
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ListNode, ptr %62, i32 0, i32 1
  store ptr %61, ptr %63, align 8, !tbaa !16
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.DummyLinkedList, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 8, !tbaa !11
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %65, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %68

68:                                               ; preds = %55, %31, %22, %18
  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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"", !6, i64 0, !10, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"ListNode", !10, i64 0, !6, i64 8}
!15 = !{!12, !6, i64 0}
!16 = !{!14, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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: nounwind uwtable
declare dso_local void @DLinkedList_AddAtHead(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @DLinkedList_AddAtTail(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @DLinkedList_AddAtIndex(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = icmp slt i32 %1, 0
  br i1 %4, label %33, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp slt i32 %7, %1
  br i1 %8, label %33, label %9

9:                                                ; preds = %5
  %10 = icmp eq i32 %1, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %9
  tail call void @DLinkedList_AddAtHead(ptr noundef nonnull %0, i32 noundef %2)
  br label %33

12:                                               ; preds = %9
  %13 = icmp eq i32 %7, %1
  br i1 %13, label %14, label %15

14:                                               ; preds = %12
  tail call void @DLinkedList_AddAtTail(ptr noundef nonnull %0, i32 noundef %2)
  br label %33

15:                                               ; preds = %12
  %16 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #2
  store i32 %2, ptr %16, align 8, !tbaa !11
  %.02124 = load ptr, ptr %0, align 8, !tbaa !13
  %.not = icmp eq i32 %1, 1
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %15
  %17 = add nsw i32 %1, -2
  %18 = add nsw i32 %1, -1
  %xtraiter = and i32 %18, 7
  %19 = icmp ult i32 %17, 7
  br i1 %19, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %18, -8
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.021.lcssa30.ph = phi ptr [ poison, %.lr.ph.preheader ], [ %.021.7, %.lr.ph ]
  %.02126.unr = phi ptr [ %.02124, %.lr.ph.preheader ], [ %.021.7, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.02126.epil = phi ptr [ %.021.epil, %.lr.ph.epil ], [ %.02126.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %20 = getelementptr inbounds i8, ptr %.02126.epil, i64 8
  %.021.epil = load ptr, ptr %20, align 8, !tbaa !13
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !14

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %15
  %.021.lcssa = phi ptr [ %.02124, %15 ], [ %.021.lcssa30.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.021.epil, %.lr.ph.epil ]
  %21 = getelementptr inbounds i8, ptr %.021.lcssa, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %16, i64 8
  store ptr %22, ptr %23, align 8, !tbaa !16
  store ptr %16, ptr %21, align 8, !tbaa !16
  %24 = add nsw i32 %7, 1
  store i32 %24, ptr %6, align 8, !tbaa !5
  br label %33

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.02126 = phi ptr [ %.02124, %.lr.ph.preheader.new ], [ %.021.7, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %25 = getelementptr inbounds i8, ptr %.02126, i64 8
  %.021 = load ptr, ptr %25, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %.021, i64 8
  %.021.1 = load ptr, ptr %26, align 8, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %.021.1, i64 8
  %.021.2 = load ptr, ptr %27, align 8, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %.021.2, i64 8
  %.021.3 = load ptr, ptr %28, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %.021.3, i64 8
  %.021.4 = load ptr, ptr %29, align 8, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %.021.4, i64 8
  %.021.5 = load ptr, ptr %30, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %.021.5, i64 8
  %.021.6 = load ptr, ptr %31, align 8, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %.021.6, i64 8
  %.021.7 = load ptr, ptr %32, align 8, !tbaa !13
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !17

33:                                               ; preds = %3, %5, %._crit_edge, %14, %11
  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 = { 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"ListNode", !10, i64 0, !7, i64 8}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = !{!12, !7, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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