; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 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: nounwind uwtable
define dso_local ptr @createList(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = mul i64 16, %9
  %11 = call noalias ptr @malloc(i64 noundef %10) #4
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %29, %2
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = sub nsw i32 %14, 1
  %16 = icmp slt i32 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %32

18:                                               ; preds = %12
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %struct.ListNode, ptr %19, i64 %21
  %23 = getelementptr inbounds %struct.ListNode, ptr %22, i64 1
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %struct.ListNode, ptr %24, i64 %26
  %28 = getelementptr inbounds %struct.ListNode, ptr %27, i32 0, i32 1
  store ptr %23, ptr %28, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %18
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !9
  br label %12, !llvm.loop !13

32:                                               ; preds = %17
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.ListNode, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct.ListNode, ptr %36, i64 -1
  %38 = getelementptr inbounds %struct.ListNode, ptr %37, i32 0, i32 1
  store ptr null, ptr %38, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %55, %32
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %58

44:                                               ; preds = %39
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %45, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.ListNode, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.ListNode, ptr %53, i32 0, i32 0
  store i32 %49, ptr %54, align 8, !tbaa !15
  br label %55

55:                                               ; preds = %44
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %7, align 4, !tbaa !9
  br label %39, !llvm.loop !16

58:                                               ; preds = %43
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %59
}

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


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

%struct.ListNode = type { i32, ptr }

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

; Function Attrs: nofree nounwind memory(write, argmem: read, inaccessiblemem: readwrite) uwtable
define dso_local noundef ptr @createList(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = sext i32 %1 to i64
  %4 = shl nsw i64 %3, 4
  %5 = tail call noalias ptr @malloc(i64 noundef %4) #2
  %6 = icmp sgt i32 %1, 1
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %7 = add nsw i32 %1, -1
  %wide.trip.count = zext nneg i32 %7 to i64
  %8 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %wide.trip.count, 7
  %9 = icmp ult i64 %8, 7
  br i1 %9, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483640
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.7, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %10 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv.epil
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = getelementptr inbounds i8, ptr %10, i64 8
  store ptr %11, ptr %12, align 8, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %2
  %13 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %3
  %14 = getelementptr inbounds i8, ptr %13, i64 -8
  store ptr null, ptr %14, align 8, !tbaa !5
  %15 = icmp sgt i32 %1, 0
  br i1 %15, label %.lr.ph21.preheader, label %._crit_edge22

.lr.ph21.preheader:                               ; preds = %._crit_edge
  %wide.trip.count27 = zext nneg i32 %1 to i64
  %xtraiter29 = and i64 %wide.trip.count27, 3
  %16 = icmp ult i32 %1, 4
  br i1 %16, label %._crit_edge22.loopexit.unr-lcssa, label %.lr.ph21.preheader.new

.lr.ph21.preheader.new:                           ; preds = %.lr.ph21.preheader
  %unroll_iter32 = and i64 %wide.trip.count27, 2147483644
  br label %.lr.ph21

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.7, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %17 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %18, ptr %19, align 8, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %20 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv.next
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %22 = getelementptr inbounds i8, ptr %20, i64 8
  store ptr %21, ptr %22, align 8, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %23 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv.next.1
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %25 = getelementptr inbounds i8, ptr %23, i64 8
  store ptr %24, ptr %25, align 8, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %26 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv.next.2
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %28 = getelementptr inbounds i8, ptr %26, i64 8
  store ptr %27, ptr %28, align 8, !tbaa !5
  %indvars.iv.next.3 = or disjoint i64 %indvars.iv, 4
  %29 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv.next.3
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  %31 = getelementptr inbounds i8, ptr %29, i64 8
  store ptr %30, ptr %31, align 8, !tbaa !5
  %indvars.iv.next.4 = or disjoint i64 %indvars.iv, 5
  %32 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv.next.4
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  %34 = getelementptr inbounds i8, ptr %32, i64 8
  store ptr %33, ptr %34, align 8, !tbaa !5
  %indvars.iv.next.5 = or disjoint i64 %indvars.iv, 6
  %35 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv.next.5
  %36 = getelementptr inbounds i8, ptr %35, i64 16
  %37 = getelementptr inbounds i8, ptr %35, i64 8
  store ptr %36, ptr %37, align 8, !tbaa !5
  %indvars.iv.next.6 = or disjoint i64 %indvars.iv, 7
  %38 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv.next.6
  %39 = getelementptr inbounds i8, ptr %38, i64 16
  %40 = getelementptr inbounds i8, ptr %38, i64 8
  store ptr %39, ptr %40, align 8, !tbaa !5
  %indvars.iv.next.7 = add nuw nsw i64 %indvars.iv, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !13

._crit_edge22.loopexit.unr-lcssa:                 ; preds = %.lr.ph21, %.lr.ph21.preheader
  %indvars.iv24.unr = phi i64 [ 0, %.lr.ph21.preheader ], [ %indvars.iv.next25.3, %.lr.ph21 ]
  %lcmp.mod31.not = icmp eq i64 %xtraiter29, 0
  br i1 %lcmp.mod31.not, label %._crit_edge22, label %.lr.ph21.epil

.lr.ph21.epil:                                    ; preds = %._crit_edge22.loopexit.unr-lcssa, %.lr.ph21.epil
  %indvars.iv24.epil = phi i64 [ %indvars.iv.next25.epil, %.lr.ph21.epil ], [ %indvars.iv24.unr, %._crit_edge22.loopexit.unr-lcssa ]
  %epil.iter30 = phi i64 [ %epil.iter30.next, %.lr.ph21.epil ], [ 0, %._crit_edge22.loopexit.unr-lcssa ]
  %41 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv24.epil
  %42 = load i32, ptr %41, align 4, !tbaa !15
  %43 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv24.epil
  store i32 %42, ptr %43, align 8, !tbaa !16
  %indvars.iv.next25.epil = add nuw nsw i64 %indvars.iv24.epil, 1
  %epil.iter30.next = add i64 %epil.iter30, 1
  %epil.iter30.cmp.not = icmp eq i64 %epil.iter30.next, %xtraiter29
  br i1 %epil.iter30.cmp.not, label %._crit_edge22, label %.lr.ph21.epil, !llvm.loop !17

._crit_edge22:                                    ; preds = %._crit_edge22.loopexit.unr-lcssa, %.lr.ph21.epil, %._crit_edge
  ret ptr %5

.lr.ph21:                                         ; preds = %.lr.ph21, %.lr.ph21.preheader.new
  %indvars.iv24 = phi i64 [ 0, %.lr.ph21.preheader.new ], [ %indvars.iv.next25.3, %.lr.ph21 ]
  %niter33 = phi i64 [ 0, %.lr.ph21.preheader.new ], [ %niter33.next.3, %.lr.ph21 ]
  %44 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv24
  %45 = load i32, ptr %44, align 4, !tbaa !15
  %46 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv24
  store i32 %45, ptr %46, align 8, !tbaa !16
  %indvars.iv.next25 = or disjoint i64 %indvars.iv24, 1
  %47 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next25
  %48 = load i32, ptr %47, align 4, !tbaa !15
  %49 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv.next25
  store i32 %48, ptr %49, align 8, !tbaa !16
  %indvars.iv.next25.1 = or disjoint i64 %indvars.iv24, 2
  %50 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next25.1
  %51 = load i32, ptr %50, align 4, !tbaa !15
  %52 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv.next25.1
  store i32 %51, ptr %52, align 8, !tbaa !16
  %indvars.iv.next25.2 = or disjoint i64 %indvars.iv24, 3
  %53 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next25.2
  %54 = load i32, ptr %53, align 4, !tbaa !15
  %55 = getelementptr inbounds %struct.ListNode, ptr %5, i64 %indvars.iv.next25.2
  store i32 %54, ptr %55, align 8, !tbaa !16
  %indvars.iv.next25.3 = add nuw nsw i64 %indvars.iv24, 4
  %niter33.next.3 = add i64 %niter33, 4
  %niter33.ncmp.3 = icmp eq i64 %niter33.next.3, %unroll_iter32
  br i1 %niter33.ncmp.3, label %._crit_edge22.loopexit.unr-lcssa, label %.lr.ph21, !llvm.loop !18
}

attributes #0 = { 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 #1 = { nofree nounwind memory(write, argmem: read, inaccessiblemem: readwrite) 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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !7, i64 0}
!17 = distinct !{!17, !12}
!18 = distinct !{!18, !14}


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