; LLVM IR from hanzohasashi33/Competetive_programming :: Snippets/DSA_PROBLEMS (add_2_numbers_linked_list)

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

; Function Attrs: nounwind uwtable
declare dso_local void @push(ptr noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @swap(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @getsize(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @addsamesize(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @addcarrytoremaining(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @addlist(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %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
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %18

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %16, ptr %17, align 8, !tbaa !5
  store i32 1, ptr %8, align 4
  br label %73

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

21:                                               ; preds = %18
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %22, ptr %23, align 8, !tbaa !5
  store i32 1, ptr %8, align 4
  br label %73

24:                                               ; preds = %18
  br label %25

25:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call i32 @getsize(ptr noundef %26)
  store i32 %27, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i32 @getsize(ptr noundef %28)
  store i32 %29, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = icmp eq i32 %30, %31
  br i1 %32, label %33, label %38

33:                                               ; preds = %25
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call ptr @addsamesize(ptr noundef %34, ptr noundef %35, ptr noundef %11)
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %36, ptr %37, align 8, !tbaa !5
  br label %66

38:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = sub nsw i32 %39, %40
  %42 = call i32 @llvm.abs.i32(i32 %41, i1 true)
  store i32 %42, ptr %12, align 4, !tbaa !9
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %38
  call void @swap(ptr noundef %4, ptr noundef %5)
  br label %47

47:                                               ; preds = %46, %38
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %48, ptr %7, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %54, %47
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr %12, align 4, !tbaa !9
  %52 = icmp ne i32 %50, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %49
  br label %54

54:                                               ; preds = %53
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.node, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  store ptr %57, ptr %7, align 8, !tbaa !5
  br label %49, !llvm.loop !13

58:                                               ; preds = %49
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = call ptr @addsamesize(ptr noundef %59, ptr noundef %60, ptr noundef %11)
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %61, ptr %62, align 8, !tbaa !5
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  call void @addcarrytoremaining(ptr noundef %63, ptr noundef %64, ptr noundef %11, ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %66

66:                                               ; preds = %58, %33
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = icmp sgt i32 %67, 0
  br i1 %68, label %69, label %72

69:                                               ; preds = %66
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load i32, ptr %11, align 4, !tbaa !9
  call void @push(ptr noundef %70, i32 noundef %71)
  br label %72

72:                                               ; preds = %69, %66
  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
  store i32 0, ptr %8, align 4
  br label %73

73:                                               ; preds = %72, %21, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %74 = load i32, ptr %8, align 4
  switch i32 %74, label %76 [
    i32 0, label %75
    i32 1, label %75
  ]

75:                                               ; preds = %73, %73
  ret void

76:                                               ; preds = %73
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"node", !10, i64 0, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"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: nounwind uwtable
declare dso_local void @push(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @swap(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @getsize(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @addsamesize(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @addcarrytoremaining(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @addlist(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %0, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %3
  store ptr %1, ptr %2, align 8, !tbaa !5
  br label %44

9:                                                ; preds = %3
  %10 = icmp eq ptr %1, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %9
  store ptr %0, ptr %2, align 8, !tbaa !5
  br label %44

12:                                               ; preds = %9
  %13 = tail call i32 @getsize(ptr noundef nonnull %0)
  %14 = tail call i32 @getsize(ptr noundef nonnull %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  %15 = icmp eq i32 %13, %14
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  %17 = call ptr @addsamesize(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull %6)
  store ptr %17, ptr %2, align 8, !tbaa !5
  br label %39

18:                                               ; preds = %12
  %19 = sub i32 %13, %14
  %20 = tail call i32 @llvm.abs.i32(i32 %19, i1 true)
  %21 = icmp slt i32 %13, %14
  br i1 %21, label %22, label %.lr.ph.preheader

22:                                               ; preds = %18
  call void @swap(ptr noundef nonnull %4, ptr noundef nonnull %5)
  %.01520.pre = load ptr, ptr %4, align 8, !tbaa !5
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %18, %22
  %.01523.ph = phi ptr [ %0, %18 ], [ %.01520.pre, %22 ]
  %smax = call i32 @llvm.abs.i32(i32 %19, i1 false)
  %23 = add i32 %smax, -1
  %xtraiter = and i32 %smax, 7
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.01523.prol = phi ptr [ %.015.prol, %.lr.ph.prol ], [ %.01523.ph, %.lr.ph.preheader ]
  %.022.prol = phi i32 [ %24, %.lr.ph.prol ], [ %20, %.lr.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %24 = add nsw i32 %.022.prol, -1
  %25 = getelementptr inbounds i8, ptr %.01523.prol, i64 8
  %.015.prol = load ptr, ptr %25, align 8, !tbaa !5
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !11

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.015.lcssa.unr = phi ptr [ poison, %.lr.ph.preheader ], [ %.015.prol, %.lr.ph.prol ]
  %.01523.unr = phi ptr [ %.01523.ph, %.lr.ph.preheader ], [ %.015.prol, %.lr.ph.prol ]
  %.022.unr = phi i32 [ %20, %.lr.ph.preheader ], [ %24, %.lr.ph.prol ]
  %26 = icmp ult i32 %23, 7
  br i1 %26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.01523 = phi ptr [ %.015.7, %.lr.ph ], [ %.01523.unr, %.lr.ph.prol.loopexit ]
  %.022 = phi i32 [ %34, %.lr.ph ], [ %.022.unr, %.lr.ph.prol.loopexit ]
  %27 = getelementptr inbounds i8, ptr %.01523, i64 8
  %.015 = load ptr, ptr %27, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.015, i64 8
  %.015.1 = load ptr, ptr %28, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.015.1, i64 8
  %.015.2 = load ptr, ptr %29, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %.015.2, i64 8
  %.015.3 = load ptr, ptr %30, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %.015.3, i64 8
  %.015.4 = load ptr, ptr %31, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %.015.4, i64 8
  %.015.5 = load ptr, ptr %32, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %.015.5, i64 8
  %.015.6 = load ptr, ptr %33, align 8, !tbaa !5
  %34 = add nsw i32 %.022, -8
  %35 = getelementptr inbounds i8, ptr %.015.6, i64 8
  %.015.7 = load ptr, ptr %35, align 8, !tbaa !5
  %.not.7 = icmp eq i32 %34, 0
  br i1 %.not.7, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph.prol.loopexit
  %.015.lcssa = phi ptr [ %.015.lcssa.unr, %.lr.ph.prol.loopexit ], [ %.015.7, %.lr.ph ]
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call ptr @addsamesize(ptr noundef %.015.lcssa, ptr noundef %36, ptr noundef nonnull %6)
  store ptr %37, ptr %2, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @addcarrytoremaining(ptr noundef %38, ptr noundef %.015.lcssa, ptr noundef nonnull %6, ptr noundef nonnull %2)
  br label %39

39:                                               ; preds = %._crit_edge, %16
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = icmp sgt i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  call void @push(ptr noundef nonnull %2, i32 noundef %40)
  br label %43

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

44:                                               ; preds = %43, %11, %8
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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