; LLVM IR from JessonYue/LeetCodeLearning :: Array/zhangjunwei/linked_list (linkedlist)

; 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.Linked_list_ = type { i32, ptr, ptr }
%struct.Node_ = type { i32, ptr }

@.str.1 = external hidden unnamed_addr constant [103 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [40 x i8], align 1
@__PRETTY_FUNCTION__.inser_node_atindex = external hidden unnamed_addr constant [49 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @make_node_next(i32 noundef, ptr noundef) #0

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

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

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

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

19:                                               ; preds = %13
  br label %21

20:                                               ; preds = %13, %3
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 73, ptr noundef @__PRETTY_FUNCTION__.inser_node_atindex) #3
  unreachable

21:                                               ; preds = %19
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Linked_list_, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = icmp eq i32 %22, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %21
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !9
  call void @insert_node_attail(ptr noundef %28, i32 noundef %29)
  br label %68

30:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Linked_list_, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = getelementptr inbounds %struct.Node_, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  store ptr %35, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Linked_list_, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  store ptr %38, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %56, %30
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Linked_list_, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  %44 = icmp ne ptr %40, %43
  br i1 %44, label %45, label %63

45:                                               ; preds = %39
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = icmp eq i32 %46, %47
  br i1 %48, label %49, label %56

49:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = call ptr @make_node_next(i32 noundef %50, ptr noundef %51)
  store ptr %52, ptr %10, align 8, !tbaa !5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Node_, ptr %54, i32 0, i32 1
  store ptr %53, ptr %55, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %63

56:                                               ; preds = %45
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %9, align 4, !tbaa !9
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %59, ptr %8, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Node_, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  store ptr %62, ptr %7, align 8, !tbaa !5
  br label %39, !llvm.loop !17

63:                                               ; preds = %49, %39
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.Linked_list_, ptr %64, i32 0, i32 0
  %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 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %68

68:                                               ; preds = %63, %27
  ret void
}

attributes #0 = { 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 = { noreturn nounwind "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 = { noreturn nounwind }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"Linked_list_", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !6, i64 8}
!15 = !{!"Node_", !10, i64 0, !6, i64 8}
!16 = !{!12, !6, i64 16}
!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"

@.str.1 = external hidden unnamed_addr constant [103 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [40 x i8], align 1
@__PRETTY_FUNCTION__.inser_node_atindex = external hidden unnamed_addr constant [49 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @make_node_next(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

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

5:                                                ; preds = %3
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp slt i32 %6, %2
  br i1 %.not, label %7, label %8

7:                                                ; preds = %5, %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 73, ptr noundef nonnull @__PRETTY_FUNCTION__.inser_node_atindex) #2
  unreachable

8:                                                ; preds = %5
  %9 = icmp eq i32 %6, %2
  br i1 %9, label %10, label %11

10:                                               ; preds = %8
  tail call void @insert_node_attail(ptr noundef nonnull %0, i32 noundef %1)
  br label %22

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %.0.in27 = getelementptr inbounds i8, ptr %13, i64 8
  %.028 = load ptr, ptr %.0.in27, align 8, !tbaa !13
  %.not2429 = icmp eq ptr %.028, %15
  br i1 %.not2429, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %11
  %16 = icmp eq i32 %2, 0
  br i1 %16, label %.lr.ph._crit_edge, label %.lr.ph41

.lr.ph41:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.0203140 = phi i32 [ %17, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.03239 = phi ptr [ %.0, %.lr.ph ], [ %.028, %.lr.ph.preheader ]
  %.0.in = getelementptr inbounds i8, ptr %.03239, i64 8
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !13
  %.not24 = icmp eq ptr %.0, %15
  br i1 %.not24, label %.loopexit, label %.lr.ph, !llvm.loop !15

.lr.ph:                                           ; preds = %.lr.ph41
  %17 = add nuw nsw i32 %.0203140, 1
  %18 = icmp eq i32 %17, %2
  br i1 %18, label %.lr.ph._crit_edge, label %.lr.ph41, !llvm.loop !15

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %.lr.ph.preheader
  %.032.lcssa = phi ptr [ %.028, %.lr.ph.preheader ], [ %.0, %.lr.ph ]
  %.02130.lcssa = phi ptr [ %13, %.lr.ph.preheader ], [ %.03239, %.lr.ph ]
  %.0.in.le = getelementptr inbounds i8, ptr %.02130.lcssa, i64 8
  %19 = tail call ptr @make_node_next(i32 noundef %1, ptr noundef %.032.lcssa)
  store ptr %19, ptr %.0.in.le, align 8, !tbaa !13
  %.pre = load i32, ptr %0, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph41, %11, %.lr.ph._crit_edge
  %20 = phi i32 [ %6, %11 ], [ %.pre, %.lr.ph._crit_edge ], [ %6, %.lr.ph41 ]
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %0, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %.loopexit, %10
  ret void
}

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


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