; LLVM IR from lolosssss/leetcode :: c (2_add_two_numbers)

; 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: nounwind uwtable
define dso_local ptr @addTwoNumbers(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %12 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ListNode, ptr %13, i32 0, i32 1
  store ptr null, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %15, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %16, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ListNode, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ListNode, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !13
  %23 = add nsw i32 %19, %22
  store i32 %23, ptr %9, align 4, !tbaa !9
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = icmp sgt i32 %24, 9
  br i1 %25, label %26, label %29

26:                                               ; preds = %2
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 10
  br label %31

29:                                               ; preds = %2
  %30 = load i32, ptr %9, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %29, %26
  %32 = phi i32 [ %28, %26 ], [ %30, %29 ]
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ListNode, ptr %33, i32 0, i32 0
  store i32 %32, ptr %34, align 8, !tbaa !13
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = sdiv i32 %35, 10
  store i32 %36, ptr %8, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %95, %31
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ListNode, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = icmp ne ptr %40, null
  br i1 %41, label %47, label %42

42:                                               ; preds = %37
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ListNode, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = icmp ne ptr %45, null
  br label %47

47:                                               ; preds = %42, %37
  %48 = phi i1 [ true, %37 ], [ %46, %42 ]
  br i1 %48, label %49, label %101

49:                                               ; preds = %47
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ListNode, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !11
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %61

54:                                               ; preds = %49
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ListNode, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  store ptr %57, ptr %3, align 8, !tbaa !5
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ListNode, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 8, !tbaa !13
  store i32 %60, ptr %10, align 4, !tbaa !9
  br label %62

61:                                               ; preds = %49
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %61, %54
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ListNode, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !11
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %74

67:                                               ; preds = %62
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.ListNode, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !11
  store ptr %70, ptr %4, align 8, !tbaa !5
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.ListNode, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 8, !tbaa !13
  store i32 %73, ptr %11, align 4, !tbaa !9
  br label %75

74:                                               ; preds = %62
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %74, %67
  %76 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %76, ptr %6, align 8, !tbaa !5
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.ListNode, ptr %77, i32 0, i32 1
  store ptr null, ptr %78, align 8, !tbaa !11
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.ListNode, ptr %80, i32 0, i32 1
  store ptr %79, ptr %81, align 8, !tbaa !11
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %82, ptr %7, align 8, !tbaa !5
  %83 = load i32, ptr %10, align 4, !tbaa !9
  %84 = load i32, ptr %11, align 4, !tbaa !9
  %85 = add nsw i32 %83, %84
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = add nsw i32 %85, %86
  store i32 %87, ptr %9, align 4, !tbaa !9
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = icmp sgt i32 %88, 9
  br i1 %89, label %90, label %93

90:                                               ; preds = %75
  %91 = load i32, ptr %9, align 4, !tbaa !9
  %92 = sub nsw i32 %91, 10
  br label %95

93:                                               ; preds = %75
  %94 = load i32, ptr %9, align 4, !tbaa !9
  br label %95

95:                                               ; preds = %93, %90
  %96 = phi i32 [ %92, %90 ], [ %94, %93 ]
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.ListNode, ptr %97, i32 0, i32 0
  store i32 %96, ptr %98, align 8, !tbaa !13
  %99 = load i32, ptr %9, align 4, !tbaa !9
  %100 = sdiv i32 %99, 10
  store i32 %100, ptr %8, align 4, !tbaa !9
  br label %37, !llvm.loop !14

101:                                              ; preds = %47
  %102 = load i32, ptr %8, align 4, !tbaa !9
  %103 = icmp sgt i32 %102, 0
  br i1 %103, label %104, label %115

104:                                              ; preds = %101
  %105 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %105, ptr %6, align 8, !tbaa !5
  %106 = load ptr, ptr %6, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.ListNode, ptr %106, i32 0, i32 1
  store ptr null, ptr %107, align 8, !tbaa !11
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.ListNode, ptr %109, i32 0, i32 1
  store ptr %108, ptr %110, align 8, !tbaa !11
  %111 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %111, ptr %7, align 8, !tbaa !5
  %112 = load i32, ptr %8, align 4, !tbaa !9
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.ListNode, ptr %113, i32 0, i32 0
  store i32 %112, ptr %114, align 8, !tbaa !13
  br label %115

115:                                              ; preds = %104, %101
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %116
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 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 = { 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 = { 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 #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, !6, i64 8}
!12 = !{!"ListNode", !10, i64 0, !6, i64 8}
!13 = !{!12, !10, i64 0}
!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: nofree nounwind uwtable
define dso_local noalias noundef ptr @addTwoNumbers(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #2
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr null, ptr %4, align 8, !tbaa !5
  %5 = load i32, ptr %0, align 8, !tbaa !11
  %6 = load i32, ptr %1, align 8, !tbaa !11
  %7 = add nsw i32 %6, %5
  br label %8

8:                                                ; preds = %20, %2
  %.sink59 = phi i32 [ %25, %20 ], [ %7, %2 ]
  %.sink55 = phi ptr [ %21, %20 ], [ %3, %2 ]
  %.041 = phi ptr [ %.14252, %20 ], [ %0, %2 ]
  %.040 = phi ptr [ %.1, %20 ], [ %1, %2 ]
  %9 = icmp sgt i32 %.sink59, 9
  %10 = add nsw i32 %.sink59, -10
  %11 = select i1 %9, i32 %10, i32 %.sink59
  store i32 %11, ptr %.sink55, align 8, !tbaa !11
  %.038 = sdiv i32 %.sink59, 10
  %12 = getelementptr inbounds i8, ptr %.041, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %14, label %.critedge.thread

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %.040, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %.not45 = icmp eq ptr %16, null
  br i1 %.not45, label %26, label %.critedge.thread.thread

.critedge.thread:                                 ; preds = %8
  %17 = load i32, ptr %13, align 8, !tbaa !11
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.040, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !5
  %.not47 = icmp eq ptr %.pre, null
  br i1 %.not47, label %20, label %.critedge.thread.thread

.critedge.thread.thread:                          ; preds = %14, %.critedge.thread
  %.03753 = phi i32 [ %17, %.critedge.thread ], [ 0, %14 ]
  %.14251 = phi ptr [ %13, %.critedge.thread ], [ %.041, %14 ]
  %18 = phi ptr [ %.pre, %.critedge.thread ], [ %16, %14 ]
  %19 = load i32, ptr %18, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %.critedge.thread, %.critedge.thread.thread
  %.03754 = phi i32 [ %.03753, %.critedge.thread.thread ], [ %17, %.critedge.thread ]
  %.14252 = phi ptr [ %.14251, %.critedge.thread.thread ], [ %13, %.critedge.thread ]
  %.1 = phi ptr [ %18, %.critedge.thread.thread ], [ %.040, %.critedge.thread ]
  %.0 = phi i32 [ %19, %.critedge.thread.thread ], [ 0, %.critedge.thread ]
  %21 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #2
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  store ptr null, ptr %22, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %.sink55, i64 8
  store ptr %21, ptr %23, align 8, !tbaa !5
  %24 = add i32 %.03754, %.038
  %25 = add i32 %24, %.0
  br label %8, !llvm.loop !12

26:                                               ; preds = %14
  %27 = icmp sgt i32 %.sink59, 9
  br i1 %27, label %28, label %32

28:                                               ; preds = %26
  %29 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #2
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  store ptr null, ptr %30, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %.sink55, i64 8
  store ptr %29, ptr %31, align 8, !tbaa !5
  store i32 %.038, ptr %29, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %28, %26
  ret ptr %3
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass