; LLVM IR from bartobri/data-structures-c :: symbol-table/array-ordered (st)

; 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.anon = type { i32, i32 }

@st = external hidden global ptr, align 8
@N = external hidden global i32, align 4

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

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

4:                                                ; preds = %42, %1
  %5 = load i32, ptr %3, align 4, !tbaa !9
  %6 = load i32, ptr @N, align 4, !tbaa !9
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %8, label %45

8:                                                ; preds = %4
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.anon, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = load ptr, ptr @st, align 8, !tbaa !5
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds ptr, ptr %12, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.anon, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = icmp eq i32 %11, %18
  br i1 %19, label %20, label %41

20:                                               ; preds = %8
  br label %21

21:                                               ; preds = %25, %20
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = load i32, ptr @N, align 4, !tbaa !9
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %38

25:                                               ; preds = %21
  %26 = load ptr, ptr @st, align 8, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %26, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = load ptr, ptr @st, align 8, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds ptr, ptr %32, i64 %34
  store ptr %31, ptr %35, align 8, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %3, align 4, !tbaa !9
  br label %21, !llvm.loop !13

38:                                               ; preds = %21
  %39 = load i32, ptr @N, align 4, !tbaa !9
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr @N, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %38, %8
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %3, align 4, !tbaa !9
  br label %4, !llvm.loop !15

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4}
!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"

@st = external hidden local_unnamed_addr global ptr, align 8
@N = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @STdelete(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @N, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph11, label %._crit_edge12

.lr.ph11:                                         ; preds = %1, %37
  %4 = phi i32 [ %38, %37 ], [ %2, %1 ]
  %.09 = phi i32 [ %39, %37 ], [ 0, %1 ]
  %5 = load i32, ptr %0, align 4, !tbaa !9
  %6 = load ptr, ptr @st, align 8, !tbaa !11
  %7 = sext i32 %.09 to i64
  %8 = getelementptr inbounds ptr, ptr %6, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp eq i32 %5, %10
  br i1 %11, label %.preheader, label %37

.preheader:                                       ; preds = %.lr.ph11
  %12 = icmp slt i32 %.09, %4
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = sext i32 %4 to i64
  %13 = sub nsw i64 %wide.trip.count, %7
  %xtraiter = and i64 %13, 3
  %lcmp.mod.not = icmp eq i64 %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
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %7, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %14 = load ptr, ptr @st, align 8, !tbaa !11
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, 1
  %15 = getelementptr inbounds ptr, ptr %14, i64 %indvars.iv.next.prol
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds ptr, ptr %14, i64 %indvars.iv.prol
  store ptr %16, ptr %17, align 8, !tbaa !11
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !13

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ %7, %.lr.ph.preheader ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %18 = sub nsw i64 %7, %wide.trip.count
  %19 = icmp ugt i64 %18, -4
  br i1 %19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %20 = load ptr, ptr @st, align 8, !tbaa !11
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %21 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv.next
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv
  store ptr %22, ptr %23, align 8, !tbaa !11
  %24 = load ptr, ptr @st, align 8, !tbaa !11
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %25 = getelementptr inbounds ptr, ptr %24, i64 %indvars.iv.next.1
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = getelementptr inbounds ptr, ptr %24, i64 %indvars.iv.next
  store ptr %26, ptr %27, align 8, !tbaa !11
  %28 = load ptr, ptr @st, align 8, !tbaa !11
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, 3
  %29 = getelementptr inbounds ptr, ptr %28, i64 %indvars.iv.next.2
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds ptr, ptr %28, i64 %indvars.iv.next.1
  store ptr %30, ptr %31, align 8, !tbaa !11
  %32 = load ptr, ptr @st, align 8, !tbaa !11
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %33 = getelementptr inbounds ptr, ptr %32, i64 %indvars.iv.next.3
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds ptr, ptr %32, i64 %indvars.iv.next.2
  store ptr %34, ptr %35, align 8, !tbaa !11
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %.preheader
  %.1.lcssa = phi i32 [ %.09, %.preheader ], [ %4, %.lr.ph ], [ %4, %.lr.ph.prol.loopexit ]
  %36 = add nsw i32 %4, -1
  store i32 %36, ptr @N, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %.lr.ph11, %._crit_edge
  %38 = phi i32 [ %36, %._crit_edge ], [ %4, %.lr.ph11 ]
  %.2 = phi i32 [ %.1.lcssa, %._crit_edge ], [ %.09, %.lr.ph11 ]
  %39 = add nsw i32 %.2, 1
  %40 = icmp slt i32 %39, %38
  br i1 %40, label %.lr.ph11, label %._crit_edge12, !llvm.loop !17

._crit_edge12:                                    ; preds = %37, %1
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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