; LLVM IR from ahampriyanshu/algo-ds-101 :: Data-Structures/LinkedList/sparce matrix/sparce addition.ll (Z8display2P4node)

; 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, i32, i32, ptr }

@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 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

declare i32 @printf(ptr 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 void @_Z8display2P4node(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %64, %1
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.node, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp slt i32 %9, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %8
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %67

15:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %59, %15
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.node, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = icmp slt i32 %17, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %62

23:                                               ; preds = %16
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.node, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  store ptr %26, ptr %3, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %49, %23
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %53

30:                                               ; preds = %27
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.node, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = icmp eq i32 %33, %34
  br i1 %35, label %36, label %47

36:                                               ; preds = %30
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.node, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %47

42:                                               ; preds = %36
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.node, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 8, !tbaa !15
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %45)
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %53

47:                                               ; preds = %36, %30
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.node, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  store ptr %52, ptr %3, align 8, !tbaa !5
  br label %27, !llvm.loop !16

53:                                               ; preds = %42, %27
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %53
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef 0)
  br label %58

58:                                               ; preds = %56, %53
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %7, align 4, !tbaa !9
  br label %16, !llvm.loop !18

62:                                               ; preds = %22
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %64

64:                                               ; preds = %62
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !19

67:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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


; 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.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z8display2P4node(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.preheader19.lr.ph, label %._crit_edge32

.preheader19.lr.ph:                               ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %.016.in22 = getelementptr inbounds i8, ptr %0, i64 16
  br label %.preheader19

.preheader19:                                     ; preds = %.preheader19.lr.ph, %._crit_edge29
  %.01431 = phi i32 [ 0, %.preheader19.lr.ph ], [ %8, %._crit_edge29 ]
  %.01530 = phi i32 [ 0, %.preheader19.lr.ph ], [ %.1.lcssa, %._crit_edge29 ]
  %5 = load i32, ptr %4, align 4, !tbaa !11
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.preheader, label %._crit_edge29

._crit_edge32:                                    ; preds = %._crit_edge29, %1
  ret void

.preheader:                                       ; preds = %.preheader19, %22
  %.027 = phi i32 [ %23, %22 ], [ 0, %.preheader19 ]
  %.126 = phi i32 [ %.318, %22 ], [ %.01530, %.preheader19 ]
  %.01623 = load ptr, ptr %.016.in22, align 8, !tbaa !12
  %.not24 = icmp eq ptr %.01623, null
  br i1 %.not24, label %._crit_edge, label %.lr.ph

._crit_edge29:                                    ; preds = %22, %.preheader19
  %.1.lcssa = phi i32 [ %.01530, %.preheader19 ], [ %.318, %22 ]
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %8 = add nuw nsw i32 %.01431, 1
  %9 = load i32, ptr %0, align 8, !tbaa !5
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %.preheader19, label %._crit_edge32, !llvm.loop !13

.lr.ph:                                           ; preds = %.preheader, %19
  %.01625 = phi ptr [ %.016, %19 ], [ %.01623, %.preheader ]
  %11 = load i32, ptr %.01625, align 8, !tbaa !5
  %12 = icmp eq i32 %11, %.01431
  br i1 %12, label %13, label %19

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %.01625, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp eq i32 %15, %.027
  br i1 %16, label %.thread, label %19

.thread:                                          ; preds = %13
  %17 = getelementptr inbounds i8, ptr %.01625, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !15
  br label %.sink.split

19:                                               ; preds = %13, %.lr.ph
  %.016.in = getelementptr inbounds i8, ptr %.01625, i64 16
  %.016 = load ptr, ptr %.016.in, align 8, !tbaa !12
  %.not = icmp eq ptr %.016, null
  br i1 %.not, label %.sink.split, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.preheader
  %20 = icmp eq i32 %.126, 0
  br i1 %20, label %.sink.split, label %22

.sink.split:                                      ; preds = %19, %._crit_edge, %.thread
  %.sink = phi i32 [ %18, %.thread ], [ 0, %._crit_edge ], [ 0, %19 ]
  %.318.ph = phi i32 [ 1, %.thread ], [ 0, %._crit_edge ], [ 0, %19 ]
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %.sink)
  br label %22

22:                                               ; preds = %.sink.split, %._crit_edge
  %.318 = phi i32 [ %.126, %._crit_edge ], [ %.318.ph, %.sink.split ]
  %23 = add nuw nsw i32 %.027, 1
  %24 = load i32, ptr %4, align 4, !tbaa !11
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %.preheader, label %._crit_edge29, !llvm.loop !17
}

attributes #0 = { nofree 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 #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" }

!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, !7, i64 4, !7, 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, !7, i64 4}
!12 = !{!6, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !7, i64 8}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


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