; LLVM IR from HarshCasper/NeoAlgo :: C/ds (singly_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 }

@first = external dso_local global ptr, align 8
@ptr = external dso_local global ptr, align 8
@prev = external dso_local global ptr, align 8
@.str.30 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [17 x i8], align 1

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

declare i32 @printf(ptr noundef, ...) #1

declare i32 @__isoc99_scanf(ptr 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 void @delete_pos() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %4 = load ptr, ptr @first, align 8, !tbaa !9
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %9

6:                                                ; preds = %0
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.31)
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str.33)
  br label %63

9:                                                ; preds = %0
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.34)
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.35, ptr noundef %1)
  %12 = load ptr, ptr @first, align 8, !tbaa !9
  store ptr %12, ptr @ptr, align 8, !tbaa !9
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %20

15:                                               ; preds = %9
  %16 = load ptr, ptr @ptr, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.node, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  store ptr %18, ptr @first, align 8, !tbaa !9
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.36)
  br label %62

20:                                               ; preds = %9
  br label %21

21:                                               ; preds = %24, %20
  %22 = load ptr, ptr @ptr, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %30

24:                                               ; preds = %21
  %25 = load ptr, ptr @ptr, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.node, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  store ptr %27, ptr @ptr, align 8, !tbaa !9
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %2, align 4, !tbaa !5
  br label %21, !llvm.loop !13

30:                                               ; preds = %21
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %33, label %57

33:                                               ; preds = %30
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %37, label %57

37:                                               ; preds = %33
  %38 = load ptr, ptr @first, align 8, !tbaa !9
  store ptr %38, ptr @ptr, align 8, !tbaa !9
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %48, %37
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = load i32, ptr %1, align 4, !tbaa !5
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %43, label %51

43:                                               ; preds = %39
  %44 = load ptr, ptr @ptr, align 8, !tbaa !9
  store ptr %44, ptr @prev, align 8, !tbaa !9
  %45 = load ptr, ptr @ptr, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.node, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  store ptr %47, ptr @ptr, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %43
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %3, align 4, !tbaa !5
  br label %39, !llvm.loop !15

51:                                               ; preds = %39
  %52 = load ptr, ptr @ptr, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  %55 = load ptr, ptr @prev, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.node, ptr %55, i32 0, i32 1
  store ptr %54, ptr %56, align 8, !tbaa !11
  br label %59

57:                                               ; preds = %33, %30
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.30)
  br label %59

59:                                               ; preds = %57, %51
  %60 = load ptr, ptr @ptr, align 8, !tbaa !9
  call void @free(ptr noundef %60) #4
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.36)
  br label %62

62:                                               ; preds = %59, %15
  br label %63

63:                                               ; preds = %62, %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret void
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 "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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"node", !6, i64 0, !10, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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"

@first = external dso_local local_unnamed_addr global ptr, align 8
@ptr = external dso_local local_unnamed_addr global ptr, align 8
@prev = external dso_local local_unnamed_addr global ptr, align 8
@.str.30 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [17 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress 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 void @delete_pos() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = load ptr, ptr @first, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %7

4:                                                ; preds = %0
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.31)
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.33)
  br label %55

7:                                                ; preds = %0
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.34)
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.35, ptr noundef nonnull %1)
  %10 = load ptr, ptr @first, align 8, !tbaa !5
  store ptr %10, ptr @ptr, align 8, !tbaa !5
  %11 = load i32, ptr %1, align 4, !tbaa !9
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %.preheader

.preheader:                                       ; preds = %7
  %.not8 = icmp eq ptr %10, null
  br i1 %.not8, label %21, label %.lr.ph

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %10, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr @first, align 8, !tbaa !5
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.36)
  br label %55

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.049 = phi i32 [ %20, %.lr.ph ], [ 0, %.preheader ]
  %17 = phi ptr [ %19, %.lr.ph ], [ %10, %.preheader ]
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = add nuw nsw i32 %.049, 1
  %.not = icmp eq ptr %19, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph
  store ptr null, ptr @ptr, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %._crit_edge, %.preheader
  %.04.lcssa = phi i32 [ %20, %._crit_edge ], [ 0, %.preheader ]
  %22 = icmp slt i32 %11, 1
  %.not7 = icmp sgt i32 %11, %.04.lcssa
  %or.cond = select i1 %22, i1 true, i1 %.not7
  br i1 %or.cond, label %50, label %23

23:                                               ; preds = %21
  store ptr %10, ptr @ptr, align 8, !tbaa !5
  %24 = add nsw i32 %11, -1
  %25 = add nsw i32 %11, -2
  %xtraiter = and i32 %24, 7
  %26 = icmp ult i32 %25, 7
  br i1 %26, label %._crit_edge13.unr-lcssa, label %.new

.new:                                             ; preds = %23
  %unroll_iter = and i32 %24, -8
  br label %.lr.ph12

.lr.ph12:                                         ; preds = %.lr.ph12, %.new
  %27 = phi ptr [ %10, %.new ], [ %43, %.lr.ph12 ]
  %niter = phi i32 [ 0, %.new ], [ %niter.next.7, %.lr.ph12 ]
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = getelementptr inbounds i8, ptr %31, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = getelementptr inbounds i8, ptr %33, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds i8, ptr %37, i64 8
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = getelementptr inbounds i8, ptr %39, i64 8
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds i8, ptr %41, i64 8
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge13.unr-lcssa, label %.lr.ph12, !llvm.loop !15

._crit_edge13.unr-lcssa:                          ; preds = %.lr.ph12, %23
  %.lcssa25.ph = phi ptr [ poison, %23 ], [ %41, %.lr.ph12 ]
  %.lcssa.ph = phi ptr [ poison, %23 ], [ %43, %.lr.ph12 ]
  %.unr = phi ptr [ %10, %23 ], [ %43, %.lr.ph12 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge13, label %.lr.ph12.epil

.lr.ph12.epil:                                    ; preds = %._crit_edge13.unr-lcssa, %.lr.ph12.epil
  %44 = phi ptr [ %46, %.lr.ph12.epil ], [ %.unr, %._crit_edge13.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph12.epil ], [ 0, %._crit_edge13.unr-lcssa ]
  %45 = getelementptr inbounds i8, ptr %44, i64 8
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge13, label %.lr.ph12.epil, !llvm.loop !16

._crit_edge13:                                    ; preds = %.lr.ph12.epil, %._crit_edge13.unr-lcssa
  %.lcssa25 = phi ptr [ %.lcssa25.ph, %._crit_edge13.unr-lcssa ], [ %44, %.lr.ph12.epil ]
  %.lcssa = phi ptr [ %.lcssa.ph, %._crit_edge13.unr-lcssa ], [ %46, %.lr.ph12.epil ]
  store ptr %.lcssa25, ptr @prev, align 8, !tbaa !5
  store ptr %.lcssa, ptr @ptr, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %.lcssa, i64 8
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = getelementptr inbounds i8, ptr %.lcssa25, i64 8
  store ptr %48, ptr %49, align 8, !tbaa !11
  br label %52

50:                                               ; preds = %21
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.30)
  %.pre20 = load ptr, ptr @ptr, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %50, %._crit_edge13
  %53 = phi ptr [ %.pre20, %50 ], [ %.lcssa, %._crit_edge13 ]
  call void @free(ptr noundef %53) #4
  %54 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.36)
  br label %55

55:                                               ; preds = %13, %52, %4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #4 = { 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"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}


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