; LLVM IR from gargarchit/Data_Structure_n_Algorithms :: Linked_List (7_FrontBackSplit)

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

@head = external dso_local global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 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

; 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 @FrontBackSplit() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  %10 = load ptr, ptr @head, align 8, !tbaa !5
  store ptr %10, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %14, %0
  %12 = load ptr, ptr %1, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %20

14:                                               ; preds = %11
  %15 = load i32, ptr %2, align 4, !tbaa !9
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %2, align 4, !tbaa !9
  %17 = load ptr, ptr %1, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.node, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  store ptr %19, ptr %1, align 8, !tbaa !5
  br label %11, !llvm.loop !13

20:                                               ; preds = %11
  %21 = load ptr, ptr @head, align 8, !tbaa !5
  store ptr %21, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = icmp slt i32 %22, 2
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = load ptr, ptr @head, align 8, !tbaa !5
  store ptr %25, ptr %3, align 8, !tbaa !5
  store ptr null, ptr %4, align 8, !tbaa !5
  br label %48

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %27 = load i32, ptr %2, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 1
  %29 = sdiv i32 %28, 2
  store i32 %29, ptr %6, align 4, !tbaa !9
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %38, %26
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %41

34:                                               ; preds = %30
  %35 = load ptr, ptr %1, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  store ptr %37, ptr %1, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %34
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %5, align 4, !tbaa !9
  br label %30, !llvm.loop !15

41:                                               ; preds = %30
  %42 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %42, ptr %3, align 8, !tbaa !5
  %43 = load ptr, ptr %1, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.node, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  store ptr %45, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.node, ptr %46, i32 0, i32 1
  store ptr null, ptr %47, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %48

48:                                               ; preds = %41, %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %49 = load ptr, ptr @head, align 8, !tbaa !5
  store ptr %49, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = icmp eq ptr %50, null
  br i1 %51, label %52, label %54

52:                                               ; preds = %48
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  store i32 1, ptr %8, align 4
  br label %90

54:                                               ; preds = %48
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %56

56:                                               ; preds = %59, %54
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %67

59:                                               ; preds = %56
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.node, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !16
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %62)
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !11
  store ptr %66, ptr %7, align 8, !tbaa !5
  br label %56, !llvm.loop !17

67:                                               ; preds = %56
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %69, ptr %9, align 8, !tbaa !5
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = icmp eq ptr %70, null
  br i1 %71, label %72, label %74

72:                                               ; preds = %67
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  store i32 1, ptr %8, align 4
  br label %89

74:                                               ; preds = %67
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  br label %76

76:                                               ; preds = %79, %74
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %87

79:                                               ; preds = %76
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.node, ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 8, !tbaa !16
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %82)
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.node, ptr %84, i32 0, i32 1
  %86 = load ptr, ptr %85, align 8, !tbaa !11
  store ptr %86, ptr %9, align 8, !tbaa !5
  br label %76, !llvm.loop !18

87:                                               ; preds = %76
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  store i32 1, ptr %8, align 4
  br label %89

89:                                               ; preds = %87, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %90

90:                                               ; preds = %89, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

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 }

!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 = !{!12, !10, i64 0}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !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"

@head = external dso_local local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @FrontBackSplit() local_unnamed_addr #1 {
  %.02128 = load ptr, ptr @head, align 8, !tbaa !5
  %.not29 = icmp eq ptr %.02128, null
  br i1 %.not29, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.02131 = phi ptr [ %.021, %.lr.ph ], [ %.02128, %0 ]
  %.02430 = phi i32 [ %1, %.lr.ph ], [ 0, %0 ]
  %1 = add nuw nsw i32 %.02430, 1
  %2 = getelementptr inbounds i8, ptr %.02131, i64 8
  %.021 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %.021, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  %3 = icmp eq i32 %.02430, 0
  br i1 %3, label %19, label %4

4:                                                ; preds = %._crit_edge
  %.not41 = icmp eq i32 %1, 2
  br i1 %.not41, label %._crit_edge37, label %.lr.ph36.preheader

.lr.ph36.preheader:                               ; preds = %4
  %5 = lshr i32 %.02430, 1
  %6 = add nsw i32 %5, -1
  %xtraiter = and i32 %5, 7
  %7 = icmp ult i32 %6, 7
  br i1 %7, label %._crit_edge37.loopexit.unr-lcssa, label %.lr.ph36.preheader.new

.lr.ph36.preheader.new:                           ; preds = %.lr.ph36.preheader
  %unroll_iter = and i32 %5, 1073741816
  br label %.lr.ph36

.lr.ph36:                                         ; preds = %.lr.ph36, %.lr.ph36.preheader.new
  %.134 = phi ptr [ %.02128, %.lr.ph36.preheader.new ], [ %.1.7, %.lr.ph36 ]
  %niter = phi i32 [ 0, %.lr.ph36.preheader.new ], [ %niter.next.7, %.lr.ph36 ]
  %8 = getelementptr inbounds i8, ptr %.134, i64 8
  %.1 = load ptr, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %.1, i64 8
  %.1.1 = load ptr, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %.1.1, i64 8
  %.1.2 = load ptr, ptr %10, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %.1.2, i64 8
  %.1.3 = load ptr, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.1.3, i64 8
  %.1.4 = load ptr, ptr %12, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.1.4, i64 8
  %.1.5 = load ptr, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %.1.5, i64 8
  %.1.6 = load ptr, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.1.6, i64 8
  %.1.7 = load ptr, ptr %15, align 8, !tbaa !5
  %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_edge37.loopexit.unr-lcssa, label %.lr.ph36, !llvm.loop !11

._crit_edge37.loopexit.unr-lcssa:                 ; preds = %.lr.ph36, %.lr.ph36.preheader
  %.1.lcssa47.ph = phi ptr [ poison, %.lr.ph36.preheader ], [ %.1.7, %.lr.ph36 ]
  %.134.unr = phi ptr [ %.02128, %.lr.ph36.preheader ], [ %.1.7, %.lr.ph36 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge37, label %.lr.ph36.epil

.lr.ph36.epil:                                    ; preds = %._crit_edge37.loopexit.unr-lcssa, %.lr.ph36.epil
  %.134.epil = phi ptr [ %.1.epil, %.lr.ph36.epil ], [ %.134.unr, %._crit_edge37.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph36.epil ], [ 0, %._crit_edge37.loopexit.unr-lcssa ]
  %16 = getelementptr inbounds i8, ptr %.134.epil, i64 8
  %.1.epil = load ptr, ptr %16, align 8, !tbaa !5
  %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_edge37, label %.lr.ph36.epil, !llvm.loop !12

._crit_edge37:                                    ; preds = %._crit_edge37.loopexit.unr-lcssa, %.lr.ph36.epil, %4
  %.1.lcssa = phi ptr [ %.02128, %4 ], [ %.1.lcssa47.ph, %._crit_edge37.loopexit.unr-lcssa ], [ %.1.epil, %.lr.ph36.epil ]
  %17 = getelementptr inbounds i8, ptr %.1.lcssa, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  store ptr null, ptr %17, align 8, !tbaa !14
  br label %19

19:                                               ; preds = %._crit_edge, %._crit_edge37
  %.023 = phi ptr [ %18, %._crit_edge37 ], [ null, %._crit_edge ]
  br i1 %.not29, label %.thread, label %20

20:                                               ; preds = %19
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %22

22:                                               ; preds = %20, %22
  %.02039 = phi ptr [ %.02128, %20 ], [ %26, %22 ]
  %23 = load i32, ptr %.02039, align 8, !tbaa !17
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %23)
  %25 = getelementptr inbounds i8, ptr %.02039, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %.not26 = icmp eq ptr %26, null
  br i1 %.not26, label %27, label %22, !llvm.loop !18

27:                                               ; preds = %22
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %29 = icmp eq ptr %.023, null
  br i1 %29, label %.thread, label %30

30:                                               ; preds = %27
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  br label %32

32:                                               ; preds = %30, %32
  %.040 = phi ptr [ %.023, %30 ], [ %36, %32 ]
  %33 = load i32, ptr %.040, align 8, !tbaa !17
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %33)
  %35 = getelementptr inbounds i8, ptr %.040, i64 8
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %.not27 = icmp eq ptr %36, null
  br i1 %.not27, label %.thread, label %32, !llvm.loop !19

.thread:                                          ; preds = %32, %27, %19, %0
  %.str.9.sink = phi ptr [ @.str.6, %0 ], [ @.str.6, %19 ], [ @.str.9, %27 ], [ @.str.11, %32 ]
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.9.sink)
  ret void
}

attributes #0 = { 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 #1 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = !{!15, !6, i64 8}
!15 = !{!"node", !16, i64 0, !6, i64 8}
!16 = !{!"int", !7, i64 0}
!17 = !{!15, !16, i64 0}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10}


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