; LLVM IR from JessonYue/LeetCodeLearning :: Array/caiweixiong/cpp/Homework_004.ll (ZN12Homework_00413addTwoNumbersEP8ListNodeS1_)

; 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.ListNode = type { i32, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN12Homework_00413addTwoNumbersEP8ListNodeS1_(ptr noundef nonnull align 1 dereferenceable(1) %0, ptr noundef %1, ptr noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %21, label %17

17:                                               ; preds = %3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store ptr null, ptr %4, align 8
  br label %85

21:                                               ; preds = %17, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %22, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %23, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %82, %21
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %30, label %27

27:                                               ; preds = %24
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br label %30

30:                                               ; preds = %27, %24
  %31 = phi i1 [ true, %24 ], [ %29, %27 ]
  br i1 %31, label %32, label %83

32:                                               ; preds = %30
  %33 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %33, ptr %13, align 4, !tbaa !9
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %45

36:                                               ; preds = %32
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ListNode, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = load i32, ptr %13, align 4, !tbaa !9
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr %13, align 4, !tbaa !9
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ListNode, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  store ptr %44, ptr %9, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %36, %32
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %57

48:                                               ; preds = %45
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ListNode, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !11
  %52 = load i32, ptr %13, align 4, !tbaa !9
  %53 = add nsw i32 %52, %51
  store i32 %53, ptr %13, align 4, !tbaa !9
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ListNode, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !13
  store ptr %56, ptr %10, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %48, %45
  %58 = load i32, ptr %13, align 4, !tbaa !9
  %59 = srem i32 %58, 10
  store i32 %59, ptr %11, align 4, !tbaa !9
  %60 = load i32, ptr %13, align 4, !tbaa !9
  %61 = sdiv i32 %60, 10
  store i32 %61, ptr %12, align 4, !tbaa !9
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %66, label %64

64:                                               ; preds = %57
  %65 = load i32, ptr %11, align 4, !tbaa !9
  call void @_Z14createHeadNodeRP8ListNodei(ptr noundef nonnull align 8 dereferenceable(8) %8, i32 noundef %65)
  br label %69

66:                                               ; preds = %57
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = call noundef zeroext i1 @_Z10insertNodeRP8ListNodei(ptr noundef nonnull align 8 dereferenceable(8) %8, i32 noundef %67)
  br label %69

69:                                               ; preds = %66, %64
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %82, label %72

72:                                               ; preds = %69
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = icmp ne ptr %73, null
  br i1 %74, label %82, label %75

75:                                               ; preds = %72
  %76 = load i32, ptr %12, align 4, !tbaa !9
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %81

78:                                               ; preds = %75
  %79 = load i32, ptr %12, align 4, !tbaa !9
  %80 = call noundef zeroext i1 @_Z10insertNodeRP8ListNodei(ptr noundef nonnull align 8 dereferenceable(8) %8, i32 noundef %79)
  br label %81

81:                                               ; preds = %78, %75
  br label %82

82:                                               ; preds = %81, %72, %69
  br label %24, !llvm.loop !14

83:                                               ; preds = %30
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %84, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %85

85:                                               ; preds = %83, %20
  %86 = load ptr, ptr %4, align 8
  ret ptr %86
}

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

declare void @_Z14createHeadNodeRP8ListNodei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #2

declare noundef zeroext i1 @_Z10insertNodeRP8ListNodei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"_ZTS8ListNode", !10, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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 uwtable
define dso_local noundef ptr @_ZN12Homework_00413addTwoNumbersEP8ListNodeS1_(ptr nocapture noundef nonnull readnone align 1 dereferenceable(1) %0, ptr noundef readonly %1, ptr noundef readonly %2) local_unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = icmp ne ptr %1, null
  %6 = icmp ne ptr %2, null
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %.lr.ph.preheader, label %38

.lr.ph.preheader:                                 ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store ptr null, ptr %4, align 8, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %34
  %7 = phi i1 [ %36, %34 ], [ %6, %.lr.ph.preheader ]
  %8 = phi i1 [ %35, %34 ], [ %5, %.lr.ph.preheader ]
  %.02941 = phi i32 [ %22, %34 ], [ 0, %.lr.ph.preheader ]
  %.03040 = phi ptr [ %.131, %34 ], [ %2, %.lr.ph.preheader ]
  %.03239 = phi ptr [ %.133, %34 ], [ %1, %.lr.ph.preheader ]
  br i1 %8, label %9, label %14

9:                                                ; preds = %.lr.ph
  %10 = load i32, ptr %.03239, align 8, !tbaa !9
  %11 = add nsw i32 %10, %.02941
  %12 = getelementptr inbounds i8, ptr %.03239, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  br label %14

14:                                               ; preds = %9, %.lr.ph
  %.133 = phi ptr [ %13, %9 ], [ null, %.lr.ph ]
  %.0 = phi i32 [ %11, %9 ], [ %.02941, %.lr.ph ]
  br i1 %7, label %15, label %20

15:                                               ; preds = %14
  %16 = load i32, ptr %.03040, align 8, !tbaa !9
  %17 = add nsw i32 %16, %.0
  %18 = getelementptr inbounds i8, ptr %.03040, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  br label %20

20:                                               ; preds = %15, %14
  %.131 = phi ptr [ %19, %15 ], [ null, %14 ]
  %.1 = phi i32 [ %17, %15 ], [ %.0, %14 ]
  %21 = srem i32 %.1, 10
  %22 = sdiv i32 %.1, 10
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %.not = icmp eq ptr %23, null
  br i1 %.not, label %24, label %25

24:                                               ; preds = %20
  call void @_Z14createHeadNodeRP8ListNodei(ptr noundef nonnull align 8 dereferenceable(8) %4, i32 noundef %21)
  br label %27

25:                                               ; preds = %20
  %26 = call noundef zeroext i1 @_Z10insertNodeRP8ListNodei(ptr noundef nonnull align 8 dereferenceable(8) %4, i32 noundef %21)
  br label %27

27:                                               ; preds = %25, %24
  %28 = icmp eq ptr %.133, null
  %29 = icmp eq ptr %.131, null
  %or.cond3.not38 = select i1 %28, i1 %29, i1 false
  %30 = add i32 %.1, -10
  %31 = icmp ult i32 %30, -19
  %or.cond5 = select i1 %or.cond3.not38, i1 %31, i1 false
  br i1 %or.cond5, label %32, label %34

32:                                               ; preds = %27
  %33 = call noundef zeroext i1 @_Z10insertNodeRP8ListNodei(ptr noundef nonnull align 8 dereferenceable(8) %4, i32 noundef %22)
  br label %34

34:                                               ; preds = %32, %27
  %35 = icmp ne ptr %.133, null
  %36 = icmp ne ptr %.131, null
  %37 = select i1 %35, i1 true, i1 %36
  br i1 %37, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %34
  %.pre = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %38

38:                                               ; preds = %3, %._crit_edge
  %.034 = phi ptr [ %.pre, %._crit_edge ], [ null, %3 ]
  ret ptr %.034
}

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

declare void @_Z14createHeadNodeRP8ListNodei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #2

declare noundef zeroext i1 @_Z10insertNodeRP8ListNodei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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, !11, i64 0}
!10 = !{!"_ZTS8ListNode", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass