; LLVM IR from Algo-Phantoms/Algo-Tree :: Code/C++/add_two_numbers_linked_list.ll (Z11addTwoListsP4NodeS0_)

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

%class.Node = 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #3

; 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
declare dso_local noundef ptr @_Z7reverseP4Node(ptr noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z11addTwoListsP4NodeS0_(ptr noundef %0, ptr noundef %1) #4 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call noundef ptr @_Z7reverseP4Node(ptr noundef %11)
  store ptr %12, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call noundef ptr @_Z7reverseP4Node(ptr noundef %13)
  store ptr %14, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %74, %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %24, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %24, label %21

21:                                               ; preds = %18
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = icmp ne i32 %22, 0
  br label %24

24:                                               ; preds = %21, %18, %15
  %25 = phi i1 [ true, %18 ], [ true, %15 ], [ %23, %21 ]
  br i1 %25, label %26, label %75

26:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %27 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %27, ptr %7, align 4, !tbaa !9
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %36

30:                                               ; preds = %26
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.Node, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = add nsw i32 %34, %33
  store i32 %35, ptr %7, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %30, %26
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %45

39:                                               ; preds = %36
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %class.Node, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !11
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %7, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %39, %36
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sdiv i32 %46, 10
  store i32 %47, ptr %6, align 4, !tbaa !9
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = srem i32 %48, 10
  store i32 %49, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %50 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 16) #6
  %51 = load i32, ptr %7, align 4, !tbaa !9
  invoke void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(16) %50, i32 noundef %51)
          to label %52 unwind label %63

52:                                               ; preds = %45
  store ptr %50, ptr %8, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %class.Node, ptr %54, i32 0, i32 1
  store ptr %53, ptr %55, align 8, !tbaa !13
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %56, ptr %5, align 8, !tbaa !5
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %67

59:                                               ; preds = %52
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %class.Node, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !13
  store ptr %62, ptr %3, align 8, !tbaa !5
  br label %67

63:                                               ; preds = %45
  %64 = landingpad { ptr, i32 }
          cleanup
  %65 = extractvalue { ptr, i32 } %64, 0
  store ptr %65, ptr %9, align 8
  %66 = extractvalue { ptr, i32 } %64, 1
  store i32 %66, ptr %10, align 4
  call void @_ZdlPvm(ptr noundef %50, i64 noundef 16) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %77

67:                                               ; preds = %59, %52
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %74

70:                                               ; preds = %67
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %class.Node, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !13
  store ptr %73, ptr %4, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %70, %67
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %15, !llvm.loop !14

75:                                               ; preds = %24
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %76

77:                                               ; preds = %63
  %78 = load ptr, ptr %9, align 8
  %79 = load i32, ptr %10, align 4
  %80 = insertvalue { ptr, i32 } poison, ptr %78, 0
  %81 = insertvalue { ptr, i32 } %80, i32 %79, 1
  resume { ptr, i32 } %81
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin 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 = { mustprogress 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 = { nobuiltin 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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, !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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z7reverseP4Node(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z11addTwoListsP4NodeS0_(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %3 = tail call noundef ptr @_Z7reverseP4Node(ptr noundef %0)
  %4 = tail call noundef ptr @_Z7reverseP4Node(ptr noundef %1)
  %5 = icmp ne ptr %3, null
  %6 = icmp ne ptr %4, null
  %or.cond31 = or i1 %5, %6
  br i1 %or.cond31, label %.critedge, label %._crit_edge

.critedge:                                        ; preds = %2, %28
  %7 = phi i1 [ %30, %28 ], [ %6, %2 ]
  %8 = phi i1 [ %29, %28 ], [ %5, %2 ]
  %.035 = phi ptr [ %.1, %28 ], [ %3, %2 ]
  %.02734 = phi i32 [ %17, %28 ], [ 0, %2 ]
  %.02833 = phi ptr [ %19, %28 ], [ null, %2 ]
  %.02932 = phi ptr [ %.130, %28 ], [ %4, %2 ]
  br i1 %8, label %9, label %12

9:                                                ; preds = %.critedge
  %10 = load i32, ptr %.035, align 8, !tbaa !5
  %11 = add nsw i32 %10, %.02734
  br label %12

12:                                               ; preds = %9, %.critedge
  %.025 = phi i32 [ %11, %9 ], [ %.02734, %.critedge ]
  br i1 %7, label %13, label %16

13:                                               ; preds = %12
  %14 = load i32, ptr %.02932, align 8, !tbaa !5
  %15 = add nsw i32 %14, %.025
  br label %16

16:                                               ; preds = %13, %12
  %.126 = phi i32 [ %15, %13 ], [ %.025, %12 ]
  %17 = sdiv i32 %.126, 10
  %18 = srem i32 %.126, 10
  %19 = tail call noalias noundef nonnull dereferenceable(16) ptr @_Znwm(i64 noundef 16) #3
  tail call void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(16) %19, i32 noundef %18)
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  store ptr %.02833, ptr %20, align 8, !tbaa !11
  br i1 %8, label %21, label %24

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %.035, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %21, %16
  %.1 = phi ptr [ %23, %21 ], [ null, %16 ]
  br i1 %7, label %25, label %28

25:                                               ; preds = %24
  %26 = getelementptr inbounds i8, ptr %.02932, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  br label %28

28:                                               ; preds = %25, %24
  %.130 = phi ptr [ %27, %25 ], [ null, %24 ]
  %29 = icmp ne ptr %.1, null
  %30 = icmp ne ptr %.130, null
  %or.cond = select i1 %29, i1 true, i1 %30
  %31 = add i32 %.126, -10
  %32 = icmp ult i32 %31, -19
  %or.cond3 = select i1 %or.cond, i1 true, i1 %32
  br i1 %or.cond3, label %.critedge, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %28, %2
  %.028.lcssa = phi ptr [ null, %2 ], [ %19, %28 ]
  ret ptr %.028.lcssa
}

attributes #0 = { nobuiltin 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 #1 = { mustprogress 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 = { 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 = { builtin 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, !7, i64 0}
!6 = !{!"_ZTS4Node", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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